def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = self.mocker.proxy(PersistentComponents(bases=(getGlobalSiteManager(),))) getSiteManager_mock = self.mocker.replace('zope.app.component.hooks.getSiteManager') self.expect(getSiteManager_mock(dummy_site)).result(site_manager_mock).count(1,None) # First look for unregistration of all local components self.expect(site_manager_mock.unregisterUtility(provided=IDexterityFTI, name=portal_type)).passthrough() # Then look for re-registration of global components self.expect(site_manager_mock.registerUtility(fti, IDexterityFTI, portal_type, info='plone.dexterity.dynamic')).passthrough() self.expect(site_manager_mock.registerUtility( mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.portal_type == portal_type), IFactory, portal_type, info='plone.dexterity.dynamic')).passthrough() self.assertEquals('string:${folder_url}/++add++testtype', fti.add_view_expr) self.replay() ftiRenamed(fti, ObjectMovedEvent(fti, container_dummy, fti.getId(), container_dummy, u"newtype")) site_dummy = self.create_dummy(getSiteManager = lambda: site_manager_mock) setSite(site_dummy) setHooks() self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type)) self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = self.mocker.proxy( PersistentComponents(bases=(getGlobalSiteManager(), ))) getSiteManager_mock = self.mocker.replace( 'zope.component.hooks.getSiteManager') self.expect( getSiteManager_mock(dummy_site)).result(site_manager_mock).count( 1, None) # First look for unregistration of all local components self.expect( site_manager_mock.unregisterUtility( provided=IDexterityFTI, name=portal_type)).passthrough() # Then look for re-registration of global components self.expect( site_manager_mock.registerUtility( fti, IDexterityFTI, portal_type, info='plone.dexterity.dynamic')).passthrough() self.expect( site_manager_mock.registerUtility( mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x. portal_type == portal_type), IFactory, portal_type, info='plone.dexterity.dynamic')).passthrough() self.assertEqual('string:${folder_url}/++add++testtype', fti.add_view_expr) self.replay() ftiRenamed( fti, ObjectMovedEvent(fti, container_dummy, fti.getId(), container_dummy, u"newtype")) site_dummy = self.create_dummy( getSiteManager=lambda: site_manager_mock) setSite(site_dummy) setHooks() self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type)) self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = Mock( wraps=PersistentComponents(bases=(getGlobalSiteManager(),))) from zope.component.hooks import getSiteManager self.patch_global(getSiteManager, return_value=site_manager_mock) self.assertEqual( 'string:${folder_url}/++add++testtype', fti.add_view_expr ) ftiRenamed( fti, ObjectMovedEvent( fti, container_dummy, fti.getId(), container_dummy, u"newtype" ) ) # First look for unregistration of all local components site_manager_mock.unregisterUtility.assert_called_once_with( provided=IDexterityFTI, name=portal_type ) # Then look for re-registration of global components self.assertEquals(site_manager_mock.registerUtility.call_count, 2) site_dummy = self.create_dummy( getSiteManager=lambda: site_manager_mock ) setSite(site_dummy) setHooks() self.assertNotEquals( None, queryUtility(IDexterityFTI, name=portal_type) ) self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = Mock( wraps=PersistentComponents(bases=(getGlobalSiteManager(),))) from zope.component.hooks import getSiteManager self.patch_global(getSiteManager, return_value=site_manager_mock) self.assertEqual( 'string:${folder_url}/++add++testtype', fti.add_view_expr ) ftiRenamed( fti, ObjectMovedEvent( fti, container_dummy, fti.getId(), container_dummy, u"newtype" ) ) # First look for unregistration of all local components site_manager_mock.unregisterUtility.assert_called_once_with( provided=IDexterityFTI, name=portal_type ) # Then look for re-registration of global components self.assertEqual(site_manager_mock.registerUtility.call_count, 2) site_dummy = self.create_dummy( getSiteManager=lambda: site_manager_mock ) setSite(site_dummy) setHooks() self.assertNotEqual( None, queryUtility(IDexterityFTI, name=portal_type) ) self.assertNotEqual(None, queryUtility(IFactory, name=portal_type))