def test_repeated_behavior_registration_lookup(self): fti = DexterityFTI(u"testtype") self.mock_utility(fti, IDexterityFTI, name=u"testtype") # Mock a test behavior class ITestBehavior(Interface): pass fti.behaviors = [ITestBehavior.__identifier__] from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior", description=u"Provides test behavior", interface=Interface, marker=ITestBehavior, factory=None ) from plone.behavior.interfaces import IBehavior self.mock_utility( registration, IBehavior, ITestBehavior.__identifier__ ) r1 = SCHEMA_CACHE.behavior_registrations(u'testtype') r2 = SCHEMA_CACHE.behavior_registrations(u'testtype') self.assertTrue(r1[0] is r2[0] is registration)
def test_repeated_behavior_registration_lookup(self): fti = DexterityFTI(u"testtype") self.mock_utility(fti, IDexterityFTI, name=u"testtype") # Mock a test behavior class ITestBehavior(Interface): pass fti.behaviors = [ITestBehavior.__identifier__] from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior", description=u"Provides test behavior", interface=Interface, marker=ITestBehavior, factory=None ) from plone.behavior.interfaces import IBehavior self.mock_utility( registration, IBehavior, ITestBehavior.__identifier__ ) r1 = SCHEMA_CACHE.behavior_registrations(u'testtype') r2 = SCHEMA_CACHE.behavior_registrations(u'testtype') self.assertTrue(r1[0] is r2[0] is registration)
def test_repeated_behavior_registration_lookup(self): # FTI mock fti_mock = self.mocker.proxy(DexterityFTI(u"testtype")) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") # Mock a test behavior class ITestBehavior(Interface): pass self.expect(fti_mock.behaviors).result([ITestBehavior.__identifier__]) from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior", description=u"Provides test behavior", interface=Interface, marker=ITestBehavior, factory=None) from plone.behavior.interfaces import IBehavior self.mock_utility(registration, IBehavior, ITestBehavior.__identifier__) self.replay() r1 = SCHEMA_CACHE.behavior_registrations(u'testtype') r2 = SCHEMA_CACHE.behavior_registrations(u'testtype') self.assertTrue(r1[0] is r2[0] is registration)
def test_repeated_behavior_registration_lookup(self): # FTI mock fti_mock = self.mocker.proxy(DexterityFTI(u"testtype")) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") # Mock a test behavior class ITestBehavior(Interface): pass self.expect(fti_mock.behaviors).result([ITestBehavior.__identifier__]) from plone.behavior.registration import BehaviorRegistration registration = BehaviorRegistration( title=u"Test Behavior", description=u"Provides test behavior", interface=Interface, marker=ITestBehavior, factory=None ) from plone.behavior.interfaces import IBehavior self.mock_utility( registration, IBehavior, ITestBehavior.__identifier__ ) self.replay() r1 = SCHEMA_CACHE.behavior_registrations(u'testtype') r2 = SCHEMA_CACHE.behavior_registrations(u'testtype') self.assertTrue(r1[0] is r2[0] is registration)
def test_unexistent_behaviors_lookup(self): fti = DexterityFTI(u"testtype") self.mock_utility(fti, IDexterityFTI, name=u"testtype") # Set an unregistered behavior fti.behaviors = ["foo.bar"] with patch("warnings.warn") as mock_warnings: SCHEMA_CACHE.behavior_registrations(u'testtype') # Verify the warning has been issued mock_warnings.assert_called_once_with( ('No behavior registration found for behavior named ' '"foo.bar" for factory "testtype" - trying deprecated ' 'fallback lookup (will be removed in 3.0)..."'), DeprecationWarning, )
def enumerateBehaviors(self): isview = self.context.layout == 'cciaa_modulistica_view' iface = 'cciaa.modulistica.behaviors.folder_modulistica.'\ 'IFolderWithColumnsExtension' for behavior in SCHEMA_CACHE.behavior_registrations( self.context.portal_type ): if not isview and behavior.interface.__identifier__ == iface: continue yield behavior
def enumerateBehaviors(self): res = [] _sb = None _cpb = None behvs = SCHEMA_CACHE.behavior_registrations(self.context.portal_type) for b in behvs: if b.interface is ICityProfileStaging: _cpb = b elif b.interface is IStagingSupport: _sb = b else: res.append(b) res = [_cpb, _sb] + res for behavior in res: yield behavior
def enumerateBehaviors(self): res = [] _sb = None _cpb = None behvs = SCHEMA_CACHE.behavior_registrations(self.context.portal_type) for b in behvs: if b.interface is ICityProfileStaging: _cpb = b elif b.interface is IStagingSupport: _sb = b else: res.append(b) res = [_cpb, _sb] + res for behavior in res: yield behavior
def enumerateBehaviors(self): #print "enumerate" request = self.context.REQUEST editedLocalBehaviours = [] try: editedLocalBehaviours = request.get("form.widgets.ILocalBehaviorSupport.local_behaviors", []) except: pass editedLocalBehaviours = list(set(editedLocalBehaviours)) #print "edited", editedLocalBehaviours # Here we save the behaviors saved previously in the context in the request, # because we will need to check this list later # and it might be changed during a "save" if not request.get("savedLocalBehaviors", []): savedBehaviors = getattr(self.context, 'local_behaviors', [])[:] request.set("savedLocalBehaviors", list(set(savedBehaviors))) #print "saved", savedBehaviors if IDPDocument.providedBy(self.context): dp_app_state = getMultiAdapter((self.context, request), name=u'dp_app_state') self.available_apps = dp_app_state.appsEffectiveForObject(request) # self.available_apps = list(set(self.available_apps).intersection(getattr(self.context, 'local_behaviors', []))) else: self.available_apps = list(set(getattr(self.context, 'local_behaviors', [])[:])) editedLocalBehaviours.extend(self.available_apps) editedLocalBehaviours.extend(request.get("savedLocalBehaviors", [])) editedLocalBehaviours = list(set(editedLocalBehaviours)) #print "resulting", editedLocalBehaviours #print "enumerate ", self.available_apps for behavior in SCHEMA_CACHE.behavior_registrations( self.context.portal_type ): if isSupported(editedLocalBehaviours, behavior.interface): yield behavior
def enumerateBehaviors(self): for behavior in SCHEMA_CACHE.behavior_registrations( self.context.portal_type): yield behavior
def enumerateBehaviors(self): for behavior in SCHEMA_CACHE.behavior_registrations( self.context.portal_type ): yield behavior