Ejemplo n.º 1
0
    def test_components_not_registered_on_add_if_exist(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)

        # Register FTI utility and factory utility

        self.mock_utility(fti, IDexterityFTI, name=portal_type)
        self.mock_utility(DexterityFactory(portal_type), IFactory, name=portal_type)

        # We expect that all components are registered, so do not expect any registrations

        self.expect(site_manager_mock.registerUtility(fti, IDexterityFTI, portal_type)).passthrough().count(0)
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.portal_type == portal_type),
                IFactory,
                portal_type,
            )
        ).passthrough().count(0)

        self.replay()

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))
Ejemplo n.º 2
0
    def test_components_unregistered_on_delete(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)

        # We expect to always be able to unregister without error, even if the
        # components do not exists (as here)

        self.expect(site_manager_mock.unregisterUtility(provided=IDexterityFTI, name=portal_type)).passthrough()
        self.expect(site_manager_mock.unregisterUtility(provided=IFactory, name=portal_type)).passthrough()

        self.replay()

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(getSiteManager=lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()

        self.assertEquals(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEquals(None, queryUtility(IFactory, name=portal_type))
Ejemplo n.º 3
0
    def test_components_unregistered_on_delete(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)

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(
            getSiteManager=lambda: site_manager_mock
        )
        setSite(site_dummy)
        setHooks()

        self.assertEqual(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEqual(None, queryUtility(IFactory, name=portal_type))
Ejemplo n.º 4
0
    def test_components_registered_on_add(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)
        
        # We expect that no components are registered , so look for all registrations
        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.replay()
        
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))
        
        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))
Ejemplo n.º 5
0
    def test_components_not_registered_on_add_if_exist(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)

        # Register FTI utility and factory utility

        self.mock_utility(fti, IDexterityFTI, name=portal_type)
        self.mock_utility(
            DexterityFactory(portal_type),
            IFactory,
            name=portal_type
        )

        # We expect that all components are registered, so do not expect any
        # registrations

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        self.assertFalse(site_manager_mock.registerUtility.called)
Ejemplo n.º 6
0
    def test_components_unregistered_on_delete(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)

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(
            getSiteManager=lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()

        self.assertEqual(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEqual(None, queryUtility(IFactory, name=portal_type))
Ejemplo n.º 7
0
    def test_components_not_registered_on_add_if_exist(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)

        # Register FTI utility and factory utility

        self.mock_utility(fti, IDexterityFTI, name=portal_type)
        self.mock_utility(DexterityFactory(portal_type),
                          IFactory,
                          name=portal_type)

        # We expect that all components are registered, so do not expect any
        # registrations

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        self.assertFalse(site_manager_mock.registerUtility.called)
Ejemplo n.º 8
0
    def test_components_registered_on_add(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)

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        args1, kwargs1 = site_manager_mock.registerUtility.call_args_list[0]
        self.assertEqual(args1, (fti, IDexterityFTI, portal_type))
        self.assertEqual(kwargs1, {'info': 'plone.dexterity.dynamic'})

        args2, kwargs2 = site_manager_mock.registerUtility.call_args_list[1]
        self.assertIsInstance(args2[0], DexterityFactory)
        self.assertEqual(args2[0].portal_type, portal_type)
        self.assertEqual(args2[1:], (IFactory, portal_type))
        self.assertEqual(kwargs2, {'info': 'plone.dexterity.dynamic'})

        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))
Ejemplo n.º 9
0
    def test_components_registered_on_add(self):
        portal_type = '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, Interface)

        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)

        # We expect that no components are registered , so look for all
        # registrations
        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.replay()

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        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))
Ejemplo n.º 10
0
    def test_components_unregistered_on_delete(self):
        portal_type = '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, Interface)

        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)

        # We expect to always be able to unregister without error, even if the
        # components do not exists (as here)

        self.expect(
            site_manager_mock.unregisterUtility(
                provided=IDexterityFTI, name=portal_type)).passthrough()
        self.expect(
            site_manager_mock.unregisterUtility(
                provided=IFactory, name=portal_type)).passthrough()

        self.replay()

        # First add the components
        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        # Then remove them again
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_dummy = self.create_dummy(
            getSiteManager=lambda: site_manager_mock)
        setSite(site_dummy)
        setHooks()

        self.assertEqual(None, queryUtility(IDexterityFTI, name=portal_type))
        self.assertEqual(None, queryUtility(IFactory, name=portal_type))
Ejemplo n.º 11
0
    def test_components_not_registered_on_add_if_exist(self):
        portal_type = '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, Interface)

        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)

        # Register FTI utility and factory utility

        self.mock_utility(fti, IDexterityFTI, name=portal_type)
        self.mock_utility(DexterityFactory(portal_type),
                          IFactory,
                          name=portal_type)

        # We expect that all components are registered, so do not expect any
        # registrations

        self.expect(
            site_manager_mock.registerUtility(
                fti, IDexterityFTI, portal_type)).passthrough().count(0)
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.
                             portal_type == portal_type), IFactory,
                portal_type)).passthrough().count(0)

        self.replay()

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))
Ejemplo n.º 12
0
    def test_components_registered_on_add(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)

        ftiAdded(fti, ObjectAddedEvent(fti, container_dummy, fti.getId()))

        args1, kwargs1 = site_manager_mock.registerUtility.call_args_list[0]
        self.assertEqual(args1, (fti, IDexterityFTI, portal_type))
        self.assertEqual(kwargs1, {'info': 'plone.dexterity.dynamic'})

        args2, kwargs2 = site_manager_mock.registerUtility.call_args_list[1]
        self.assertIsInstance(args2[0], DexterityFactory)
        self.assertEqual(args2[0].portal_type, portal_type)
        self.assertEqual(args2[1:], (IFactory, portal_type))
        self.assertEqual(kwargs2, {'info': 'plone.dexterity.dynamic'})

        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))