test_configure.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:plone.server 作者: plone 项目源码 文件源码
def test_register_behavior(self):
        cur_count = len(
            configure.get_configurations('plone.server.tests', 'behavior'))

        from plone.server.interfaces import IFormFieldProvider
        from zope.interface import provider
        from zope import schema

        @provider(IFormFieldProvider)
        class IMyBehavior(Interface):
            foobar = schema.Text()

        configure.behavior(
            title="MyBehavior",
            provides=IMyBehavior,
            factory="plone.behavior.AnnotationStorage",
            for_="plone.server.interfaces.IResource"
        )()

        self.assertEqual(
            len(configure.get_configurations('plone.server.tests', 'behavior')),
            cur_count + 1)

        class IMyType(Interface):
            pass

        class MyType(Item):
            pass

        configure.register_configuration(MyType, dict(
            context=ISite,
            schema=IMyType,
            portal_type="MyType2",
            behaviors=[IMyBehavior]
        ), 'contenttype')

        # now test it...
        configure.load_configuration(
            self.layer.app.app.config, 'plone.server.tests', 'contenttype')
        self.layer.app.app.config.execute_actions()

        resp = self.layer.requester('GET', '/plone/plone/@types')
        response = json.loads(resp.text)
        type_ = [s for s in response if s['title'] == 'MyType2'][0]
        self.assertTrue('foobar' in type_['definitions']['IMyBehavior']['properties'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号