def test_schema_lookup_default_view(self): # Context and request class IMarker(IDexterityContent): pass context_mock = self.create_dummy(portal_type=u'testtype') alsoProvides(context_mock, IMarker) request_mock = TestRequest() # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) fti_mock.behaviors = (IBehaviorOne.__identifier__, IBehaviorTwo.__identifier__, IBehaviorThree.__identifier__) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") from plone.behavior.interfaces import IBehavior from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior 1", description=u"Provides test behavior", interface=IBehaviorOne, marker=None, factory=None) self.mock_utility(registration, IBehavior, IBehaviorOne.__identifier__) registration = BehaviorRegistration( title=u"Test Behavior 2", description=u"Provides test behavior", interface=IBehaviorTwo, marker=None, factory=None) self.mock_utility(registration, IBehavior, IBehaviorTwo.__identifier__) registration = BehaviorRegistration( title=u"Test Behavior 3", description=u"Provides test behavior", interface=IBehaviorThree, marker=None, factory=None) self.mock_utility(registration, IBehavior, IBehaviorThree.__identifier__) # Form view = DefaultView(context_mock, request_mock) view.portal_type = u"testtype" self.assertEqual(ISchema, view.schema) # we expect here only formfieldprovider! self.assertEqual((IBehaviorOne, IBehaviorTwo), tuple(view.additionalSchemata)) # When we register our own IBehaviorAssignable we can # influence what goes into the additionalSchemata. self.mock_adapter(NoBehaviorAssignable, IBehaviorAssignable, [IMarker]) additionalSchemata = tuple(view.additionalSchemata) self.assertEqual(tuple(), tuple(additionalSchemata))
def test_schema_lookup(self): # Context and request context_mock = self.create_dummy(portal_type=u'testtype') request_mock = self.create_dummy() # FTI fti_mock = self.mocker.proxy(DexterityFTI(u"testtype")) self.expect(fti_mock.lookupSchema()).result(ISchema) self.expect(fti_mock.behaviors).result( (IBehaviorOne.__identifier__, IBehaviorTwo.__identifier__, IBehaviorThree.__identifier__)) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") # Form self.replay() view = DefaultView(context_mock, request_mock) self.assertEqual(ISchema, view.schema) self.assertEqual([IBehaviorOne, IBehaviorTwo], list(view.additionalSchemata, )) # When we register our own IBehaviorAssignable we can # influence what goes into the additionalSchemata: provideAdapter(NoBehaviorAssignable) self.assertEqual([], list(view.additionalSchemata, ))
def test_schema_lookup_default_view(self): # Context and request class IMarker(IDexterityContent): pass context_mock = self.create_dummy(portal_type=u'testtype') alsoProvides(context_mock, IMarker) request_mock = TestRequest() # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) fti_mock.behaviors = ( IBehaviorOne.__identifier__, IBehaviorTwo.__identifier__, IBehaviorThree.__identifier__ ) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") from plone.behavior.interfaces import IBehavior from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior 1", description=u"Provides test behavior", interface=IBehaviorOne, marker=None, factory=None ) self.mock_utility( registration, IBehavior, IBehaviorOne.__identifier__ ) registration = BehaviorRegistration( title=u"Test Behavior 2", description=u"Provides test behavior", interface=IBehaviorTwo, marker=None, factory=None ) self.mock_utility( registration, IBehavior, IBehaviorTwo.__identifier__ ) registration = BehaviorRegistration( title=u"Test Behavior 3", description=u"Provides test behavior", interface=IBehaviorThree, marker=None, factory=None ) self.mock_utility( registration, IBehavior, IBehaviorThree.__identifier__ ) # Form view = DefaultView(context_mock, request_mock) view.portal_type = u"testtype" self.assertEqual(ISchema, view.schema) # we expect here only formfieldprovider! self.assertEqual( (IBehaviorOne, IBehaviorTwo), tuple(view.additionalSchemata) ) # When we register our own IBehaviorAssignable we can # influence what goes into the additionalSchemata. self.mock_adapter( NoBehaviorAssignable, IBehaviorAssignable, [IMarker] ) additionalSchemata = tuple(view.additionalSchemata) self.assertEqual(tuple(), tuple(additionalSchemata))
def index(self): # ManageViewlets.__call__ may call this at its end, and then we'd like # to render by using our dexterity.DisplayForm based View-class. # noinspection PyCallByClass return DefaultView.__call__(self)