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'])
评论列表
文章目录