Ejemplo n.º 1
0
    def test23_RegistryBasesNotVersionedOrRestored(self):
        portal_repo = self.portal.portal_repository
        fol = self.portal.fol

        fol.setTitle("v1")
        # Make it a component registry with bases
        base = aq_base(self.portal.getSiteManager())
        components = PersistentComponents()
        components.__bases__ = (base,)
        fol.setSiteManager(components)
        portal_repo.applyVersionControl(fol)

        broken_iface = broken.find_global(
            'never_gonna_be_real', 'IMissing',
            Broken=ZODB.interfaces.IBroken, type=InterfaceClass)
        sys.modules[broken_iface.__module__] = module = imp.new_module(
            broken_iface.__module__)
        module.IMissing = broken_iface

        # add a broken registrsation but do a savepoint before
        # breaking the interfaces to simulate a broken registrion from
        # a previous commit
        base.registerUtility(component=None, provided=broken_iface)
        transaction.savepoint(optimistic=True)
        del sys.modules[broken_iface.__module__]

        fol.setTitle("v2")

        # If an attempt was made to pickle the parent registry's
        # broken registration we would see an error here
        portal_repo.save(fol)

        self.assertEqual(self.portal.fol.Title(), "v2")
        self.assertTrue(
            self.portal.fol.getSiteManager().__bases__[0] is base)
Ejemplo n.º 2
0
    def makeSite(self):
        if IObjectManagerSite.providedBy(self.context):
            raise ValueError('This is already a site')

        enableSite(self.context, iface=IObjectManagerSite)

        #TODO in the future we'll have to walk up to other site
        # managers and put them in the bases
        components = PersistentComponents()
        components.__bases__ = (base,)
        self.context.setSiteManager(components)
Ejemplo n.º 3
0
    def makeSite(self):
        if IObjectManagerSite.providedBy(self.context):
            raise ValueError('This is already a site')

        enableSite(self.context, iface=IObjectManagerSite)

        #TODO in the future we'll have to walk up to other site
        # managers and put them in the bases
        components = PersistentComponents()
        components.__bases__ = (base,)
        self.context.setSiteManager(components)
Ejemplo n.º 4
0
def enable_local_site(obj):
    enableSite(obj, iface=IObjectManagerSite)
    for parent in aq_chain(obj)[1:]:
        if ISite.providedBy(parent):
            p_sm = parent.getSiteManager()
            bases = (p_sm, ) + p_sm.__bases__
            break
    else:
        bases = (base, )
    components = PersistentComponents()
    components.__bases__ = bases
    obj.setSiteManager(components)
Ejemplo n.º 5
0
def enable_local_site(obj):
    enableSite(obj, iface=IObjectManagerSite)
    for parent in aq_chain(obj)[1:]:
        if ISite.providedBy(parent):
            p_sm = parent.getSiteManager()
            bases = (p_sm,) + p_sm.__bases__
            break
    else:
         bases = (base,)   
    components = PersistentComponents()
    components.__bases__ = bases
    obj.setSiteManager(components)
Ejemplo n.º 6
0
    def test_deleted_factory_not_unregistered_if_not_unique(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type, factory='common-factory')
        portal_type2 = u"testtype2"
        fti2 = DexterityFTI(portal_type2, factory='common-factory')
        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)

        # Pretend two FTIs are registered, both using common-factory
        # NB: Assuming that "testtype" was already removed when this gets
        #     called
        site_manager_mock.registeredUtilities = Mock(return_value=[
            self.create_dummy(provided=IFactory,
                              name='common-factory',
                              info='plone.dexterity.dynamic'),
            self.create_dummy(component=fti2,
                              provided=IDexterityFTI,
                              name='testtype2',
                              info='plone.dexterity.dynamic'),
        ])

        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        # We shouldn't remove this since fti2 still uses it
        # The type itself should be removed though
        site_manager_mock.unregisterUtility.assert_called_once_with(
            provided=IDexterityFTI, name=u'testtype')
Ejemplo n.º 7
0
    def test_old_factory_not_unregistered_if_not_created_by_dexterity(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)

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

        # Pretend like we have a utility registered

        reg1 = self.create_dummy()
        reg1.provided = IFactory
        reg1.name = 'old-factory'
        reg1.info = None

        site_manager_mock.registeredUtilities = Mock(return_value=[reg1])

        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))

        # This should not be removed, since we didn't create it
        self.assertFalse(site_manager_mock.unregisterUtility.called)
        # A new one may still be created, however
        self.assertEqual(site_manager_mock.registerUtility.call_args[0][2],
                         'new-factory')
Ejemplo n.º 8
0
    def test_new_factory_not_registered_after_name_changed_if_exists(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)

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

        # Create a global default for the new name
        self.mock_utility(DexterityFactory(portal_type),
                          IFactory,
                          name='new-factory')

        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))

        # Factory should not be registered again
        self.assertFalse(site_manager_mock.registerUtility.called)
Ejemplo n.º 9
0
    def test_old_factory_unregistered_after_name_changed_if_dynamic(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)

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

        # Pretend like we have a utility registered

        reg1 = self.create_dummy()
        reg1.provided = IFactory
        reg1.name = 'old-factory'
        reg1.info = 'plone.dexterity.dynamic'

        site_manager_mock.registeredUtilities = Mock(return_value=[reg1])

        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))

        # Expect this to get removed
        site_manager_mock.unregisterUtility.assert_called_once_with(
            provided=IFactory, name='old-factory')
        # And a new one to be created with the new factory name
        self.assertEqual(site_manager_mock.registerUtility.call_args[0][2],
                         'new-factory')
Ejemplo n.º 10
0
    def test_global_components_not_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)

        # 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 to always be able to unregister without error, even if the
        # component exists. The factory is only unregistered if it was
        # registered with info='plone.dexterity.dynamic'.

        ftiRemoved(fti, ObjectRemovedEvent(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.º 11
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.º 12
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.º 13
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.º 14
0
    def test_components_unregistered_on_delete_does_not_error_with_no_components(
            self):  # noqa
        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 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.replay()

        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))
Ejemplo n.º 15
0
    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))
Ejemplo n.º 16
0
    def test_renamed_factory_not_unregistered_if_not_unique(self):
        portal_type = 'testtype'
        fti = DexterityFTI(portal_type, factory='common-factory')
        portal_type2 = 'testtype2'
        fti2 = DexterityFTI(portal_type2, factory='common-factory')

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

        # Pretend two FTIs are registered, both using common-factory
        self.expect(site_manager_mock.registeredUtilities()).result([
            self.create_dummy(provided=IFactory,
                              name='common-factory',
                              info='plone.dexterity.dynamic'),
            self.create_dummy(component=fti,
                              provided=IDexterityFTI,
                              name='testtype',
                              info='plone.dexterity.dynamic'),
            self.create_dummy(component=fti2,
                              provided=IDexterityFTI,
                              name='testtype2',
                              info='plone.dexterity.dynamic'),
        ])

        # We shouldn't remove this since fti2 still uses it
        self.expect(
            site_manager_mock.unregisterUtility(
                provided=IFactory, name='common-factory')).count(0)

        # And a new one to be created with the new factory name
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.
                             portal_type == portal_type),
                IFactory,
                'new-factory',
                info='plone.dexterity.dynamic')).passthrough()

        self.replay()
        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory',
                                                    'common-factory')))
Ejemplo n.º 17
0
    def test_renamed_factory_not_unregistered_if_not_unique(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type, factory='common-factory')
        portal_type2 = u"testtype2"
        fti2 = DexterityFTI(portal_type2, factory='common-factory')

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

        # Pretend two FTIs are registered, both using common-factory
        site_manager_mock.registeredUtilities = Mock(return_value=[
            self.create_dummy(
                provided=IFactory,
                name='common-factory',
                info='plone.dexterity.dynamic'
            ),
            self.create_dummy(
                component=fti,
                provided=IDexterityFTI,
                name='testtype',
                info='plone.dexterity.dynamic'
            ),
            self.create_dummy(
                component=fti2,
                provided=IDexterityFTI,
                name='testtype2',
                info='plone.dexterity.dynamic'
            ),
        ])

        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription(
                    'factory',
                    'common-factory'
                )
            )
        )

        # We shouldn't remove this since fti2 still uses it
        self.assertFalse(site_manager_mock.unregisterUtility.called)

        # A new one may still be created, however
        self.assertEqual(
            site_manager_mock.registerUtility.call_args[0][2], 'new-factory')
Ejemplo n.º 18
0
    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))
Ejemplo n.º 19
0
    def test_old_factory_not_unregistered_if_not_created_by_dexterity(self):
        portal_type = 'testtype'
        fti = DexterityFTI(portal_type)

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

        # Pretend like we have a utility registered

        reg1 = self.create_dummy()
        reg1.provided = IFactory
        reg1.name = 'old-factory'
        reg1.info = None

        self.expect(site_manager_mock.registeredUtilities()).result([reg1])

        # This should not be removed, since we didn't create it
        self.expect(
            site_manager_mock.unregisterUtility(provided=IFactory,
                                                name='old-factory')).count(0)

        # A new one may still be created, however
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.
                             portal_type == portal_type),
                IFactory,
                'new-factory',
                info='plone.dexterity.dynamic')).passthrough()

        self.replay()
        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))
Ejemplo n.º 20
0
    def test_old_factory_unregistered_after_name_changed_if_dynamic(self):
        portal_type = u"testtype"
        fti = DexterityFTI(portal_type)

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

        # Pretend like we have a utility registered

        reg1 = self.create_dummy()
        reg1.provided = IFactory
        reg1.name = 'old-factory'
        reg1.info = 'plone.dexterity.dynamic'

        self.expect(site_manager_mock.registeredUtilities()).result([reg1])

        # Expect this to get removed
        self.expect(
            site_manager_mock.unregisterUtility(provided=IFactory,
                                                name='old-factory'))

        # And a new one to be created with the new factory name
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.
                             portal_type == portal_type),
                IFactory,
                'new-factory',
                info='plone.dexterity.dynamic')).passthrough()

        self.replay()
        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))
Ejemplo n.º 21
0
    def test_deleted_factory_not_unregistered_if_not_unique(self):
        portal_type = 'testtype'
        fti = DexterityFTI(portal_type, factory='common-factory')
        portal_type2 = 'testtype2'
        fti2 = DexterityFTI(portal_type2, factory='common-factory')
        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)

        # Pretend two FTIs are registered, both using common-factory
        # NB: Assuming that 'testtype' was already removed when this gets
        #     called
        self.expect(site_manager_mock.registeredUtilities()).result([
            self.create_dummy(provided=IFactory,
                              name='common-factory',
                              info='plone.dexterity.dynamic'),
            self.create_dummy(component=fti2,
                              provided=IDexterityFTI,
                              name='testtype2',
                              info='plone.dexterity.dynamic'),
        ])

        # We shouldn't remove this since fti2 still uses it
        self.expect(
            site_manager_mock.unregisterUtility(
                provided=IFactory, name='common-factory')).count(0)

        # The type itself should be removed though
        self.expect(
            site_manager_mock.unregisterUtility(provided=IDexterityFTI,
                                                name='testtype')).count(1)

        self.replay()
        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))
Ejemplo n.º 22
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.º 23
0
    def test_global_components_not_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)

        # 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 to always be able to unregister without error, even if the
        # component exists. The factory is only unregistered if it was
        # registered with info='plone.dexterity.dynamic'.

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

        self.replay()

        ftiRemoved(fti, ObjectRemovedEvent(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.º 24
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.º 25
0
    def test_components_unregistered_on_delete_does_not_error_with_no_components(self):  # noqa
        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)

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

        ftiRemoved(fti, ObjectRemovedEvent(fti, container_dummy, fti.getId()))

        site_manager_mock.unregisterUtility.assert_called_once_with(
            provided=IDexterityFTI, name=portal_type)
Ejemplo n.º 26
0
    def test_new_factory_not_registered_after_name_changed_if_exists(self):
        portal_type = 'testtype'
        fti = DexterityFTI(portal_type)

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

        # Create a global default for the new name
        self.mock_utility(DexterityFactory(portal_type),
                          IFactory,
                          name='new-factory')

        # Factory should not be registered again
        self.expect(
            site_manager_mock.registerUtility(
                mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x.
                             portal_type == portal_type),
                IFactory,
                'new-factory',
                info='plone.dexterity.dynamic')).passthrough().count(0)

        self.replay()
        fti.factory = 'new-factory'
        ftiModified(
            fti,
            ObjectModifiedEvent(
                fti,
                DexterityFTIModificationDescription('factory', 'old-factory')))
Ejemplo n.º 27
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.º 28
0
 def _make_registry(self):
     return PersistentComponents()
Ejemplo n.º 29
0
def createComponentRegistry(context):
    enableSite(context, iface=IObjectManagerSite)

    components = PersistentComponents()
    components.__bases__ = (base,)
    context.setSiteManager(components)
def make_broken_registry():
    persistent = PersistentComponents('persistent')
    persistent.registerAdapter(factory, (Interface,), IBroken)
    persistent.unregisterAdapter(factory, (Interface,), IBroken)
    persistent.registerUtility(factory, IBroken)
    persistent.unregisterUtility(factory, IBroken)
    persistent.registerHandler(factory, (IBroken,))
    persistent.unregisterHandler(factory, (IBroken,))
    return persistent
Ejemplo n.º 31
0
def createComponentRegistry(context):
    enableSite(context, iface=IObjectManagerSite)

    components = PersistentComponents()
    components.__bases__ = (base, )
    context.setSiteManager(components)