Beispiel #1
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 = 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")))
Beispiel #2
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 = 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)
     
     # 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')))
    def test_form_create(self):

        # Context and request
        context = Container(u"container")
        request = TestRequest()

        # FTI - returns dummy factory name

        fti_mock = DexterityFTI(u"testtype")
        fti_mock.factory = u'testfactory'
        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        # The form we're testing
        form = DefaultAddForm(context, request)
        form.portal_type = u"testtype"

        class ISchema(Interface):
            foo = schema.TextLine()

        form.fields = Fields(ISchema)

        # createObject and applyChanges

        obj_dummy = Item(id="dummy")
        alsoProvides(obj_dummy, ISchema)
        data_dummy = {u"foo": u"bar"}

        from zope.component import createObject
        self.patch_global(createObject, return_value=obj_dummy)

        provideAdapter(AttributeField)

        self.assertEqual(obj_dummy, form.create(data_dummy))
        self.assertEqual("testtype", obj_dummy.portal_type)
Beispiel #4
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)
Beispiel #5
0
    def test_form_create(self):

        # Context and request
        context = Container(u"container")
        request = TestRequest()

        # FTI - returns dummy factory name

        fti_mock = DexterityFTI(u"testtype")
        fti_mock.factory = u'testfactory'
        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        # The form we're testing
        form = DefaultAddForm(context, request)
        form.portal_type = u"testtype"

        class ISchema(Interface):
            foo = schema.TextLine()
        form.fields = Fields(ISchema)

        # createObject and applyChanges

        obj_dummy = Item(id="dummy")
        alsoProvides(obj_dummy, ISchema)
        data_dummy = {u"foo": u"bar"}

        from zope.component import createObject
        self.patch_global(createObject, return_value=obj_dummy)

        provideAdapter(AttributeField)

        self.assertEqual(obj_dummy, form.create(data_dummy))
        self.assertEqual("testtype", obj_dummy.portal_type)
Beispiel #6
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')
Beispiel #7
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)
Beispiel #8
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')
Beispiel #9
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 = 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)
     
     # 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')))
Beispiel #10
0
    def test_form_create(self):

        # Context and request
        context = Container(u"container")
        request = TestRequest()

        # FTI - returns dummy factory name

        fti_mock = DexterityFTI(u"testtype")
        fti_mock.factory = u'testfactory'
        self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")

        # The form we're testing
        form = DefaultAddForm(context, request)
        form.portal_type = u"testtype"

        # createObject and applyChanges

        obj_dummy = Item(id="dummy")
        data_dummy = {u"foo": u"bar"}

        from zope.component import createObject
        self.patch_global(createObject, return_value=obj_dummy)

        from z3c.form.form import applyChanges
        self.patch_global(applyChanges)

        self.assertEqual(obj_dummy, form.create(data_dummy))
        self.assertEqual("testtype", obj_dummy.portal_type)
Beispiel #11
0
    def test_old_factory_unregistered_after_name_changed_if_dynamic(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 = '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')
            )
        )
Beispiel #12
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')))
Beispiel #13
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')
Beispiel #14
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')
Beispiel #15
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')))
Beispiel #16
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')))
Beispiel #17
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')))
Beispiel #18
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')
Beispiel #19
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')
Beispiel #20
0
def create1_0EventType(portal):
    """Recreate the old event type used in the 1.0 branch"""
    fti = DexterityFTI('Event')
    fti.title = 'Event'
    fti.description = 'Events can be shown in calendars.'
    fti.factory = 'Event'
    fti.add_view_expr = 'string:${folder_url}/++add++Event'
    fti.link_target = ''
    fti.link_target = ''
    fti.immediate_view = 'view'
    fti.global_allow = True
    fti.filter_content_types = True
    fti.allowed_content_types = []
    fti.allow_discussion = False
    fti.default_view = 'event_view'
    fti.view_methods = ('event_view', )
    fti.default_view_fallback = False
    fti.add_permission = 'plone.app.contenttypes.addEvent'
    fti.klass = 'plone.app.contenttypes.tests.oldtypes.Event'
    fti.behaviors = (
        'plone.app.contenttypes.interfaces.IEvent',
        'plone.app.dexterity.behaviors.metadata.IDublinCore',
        'plone.app.content.interfaces.INameFromTitle',
        'plone.app.dexterity.behaviors.discussion.IAllowDiscussion',
        'plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation',
        'plone.app.relationfield.behavior.IRelatedItems',
        'plone.app.versioningbehavior.behaviors.IVersionable',
    )
    fti.schema = None
    fti.model_source = """
<model xmlns="http://namespaces.plone.org/supermodel/schema"
       xmlns:indexer="http://namespaces.plone.org/supermodel/indexer"
       xmlns:i18n="http://xml.zope.org/namespaces/i18n"
       i18n:domain="plone">
    <schema>
      <field name="location" type="zope.schema.TextLine"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_event_location">Event Location</title>
      </field>
      <field name="start_date" type="zope.schema.Datetime">
        <description />
        <title i18n:translate="label_event_start">Event Starts</title>
      </field>
      <field name="end_date" type="zope.schema.Datetime">
        <description />
        <title i18n:translate="label_event_end">Event Ends</title>
      </field>
      <field name="text" type="plone.app.textfield.RichText"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="">Text</title>
      </field>
      <field name="attendees" type="zope.schema.Text"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_event_attendees">Attendees</title>
      </field>
      <field name="event_url" type="zope.schema.TextLine">
        <description i18n:translate="help_url">
          Web address with more info about the event. Add http:// for external
          links.
        </description>
        <required>False</required>
        <title i18n:translate="event_more_information">Event URL</title>
      </field>
      <field name="contact_name" type="zope.schema.TextLine"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_name">Contact Name</title>
      </field>
      <field name="contact_email" type="zope.schema.TextLine">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_email">Contact E-mail</title>
      </field>
      <field name="contact_phone" type="zope.schema.TextLine">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_phone">Contact Phone</title>
      </field>
    </schema>
</model>"""
    fti.model_file = None  # Was plone.app.contenttypes.schema:event.xml

    if 'Event' in portal.portal_types:
        del portal.portal_types['Event']
    portal.portal_types._setObject('Event', fti)
    return fti
Beispiel #21
0
def create1_0EventType(portal):
    """Recreate the old event type used in the 1.0 branch"""
    fti = DexterityFTI("Event")
    fti.title = "Event"
    fti.description = "Events can be shown in calendars."
    fti.factory = "Event"
    fti.add_view_expr = "string:${folder_url}/++add++Event"
    fti.link_target = ""
    fti.link_target = ""
    fti.immediate_view = "view"
    fti.global_allow = True
    fti.filter_content_types = True
    fti.allowed_content_types = []
    fti.allow_discussion = False
    fti.default_view = "event_view"
    fti.view_methods = ("event_view",)
    fti.default_view_fallback = False
    fti.add_permission = "plone.app.contenttypes.addEvent"
    fti.klass = "plone.app.contenttypes.content.Event"
    fti.behaviors = (
        "plone.app.contenttypes.interfaces.IEvent",
        "plone.app.dexterity.behaviors.metadata.IDublinCore",
        "plone.app.content.interfaces.INameFromTitle",
        "plone.app.dexterity.behaviors.discussion.IAllowDiscussion",
        "plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation",
        "plone.app.relationfield.behavior.IRelatedItems",
        "plone.app.versioningbehavior.behaviors.IVersionable",
    )
    fti.schema = None
    fti.model_source = """
<model xmlns="http://namespaces.plone.org/supermodel/schema"
       xmlns:indexer="http://namespaces.plone.org/supermodel/indexer"
       xmlns:i18n="http://xml.zope.org/namespaces/i18n"
       i18n:domain="plone">
    <schema>
      <field name="location" type="zope.schema.TextLine"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_event_location">Event Location</title>
      </field>
      <field name="start_date" type="zope.schema.Datetime">
        <description />
        <title i18n:translate="label_event_start">Event Starts</title>
      </field>
      <field name="end_date" type="zope.schema.Datetime">
        <description />
        <title i18n:translate="label_event_end">Event Ends</title>
      </field>
      <field name="text" type="plone.app.textfield.RichText"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="">Text</title>
      </field>
      <field name="attendees" type="zope.schema.Text"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_event_attendees">Attendees</title>
      </field>
      <field name="event_url" type="zope.schema.TextLine">
        <description i18n:translate="help_url">
          Web address with more info about the event. Add http:// for external
          links.
        </description>
        <required>False</required>
        <title i18n:translate="event_more_information">Event URL</title>
      </field>
      <field name="contact_name" type="zope.schema.TextLine"
             indexer:searchable="true">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_name">Contact Name</title>
      </field>
      <field name="contact_email" type="zope.schema.TextLine">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_email">Contact E-mail</title>
      </field>
      <field name="contact_phone" type="zope.schema.TextLine">
        <description />
        <required>False</required>
        <title i18n:translate="label_contact_phone">Contact Phone</title>
      </field>
    </schema>
</model>"""
    fti.model_file = None  # Was plone.app.contenttypes.schema:event.xml

    if "Event" in portal.portal_types:
        del portal.portal_types["Event"]
    portal.portal_types._setObject("Event", fti)
    return fti