def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI('testtype')
        fti.title = 'Old title'
        fti.allow_discussion = False
        fti.global_allow = True

        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x) and len(
                        x.descriptions) == 1 and x.descriptions[0].attribute ==
                    'title' and x.descriptions[0].oldValue == 'Old title')))

        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x) and len(
                        x.descriptions) == 1 and x.descriptions[0].attribute ==
                    'global_allow' and x.descriptions[0].oldValue is True)))
        self.replay()

        fti.manage_changeProperties(title='New title',
                                    allow_discussion=False,
                                    global_allow=False)
Exemple #2
0
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x)
                    and len(x.descriptions) == 1
                    and x.descriptions[0].attribute == 'title'
                    and x.descriptions[0].oldValue == "Old title"
                )
            )
        )

        self.expect(
            notify_mock(
                mocker.MATCH(
                    lambda x: IObjectModifiedEvent.providedBy(x)
                    and len(x.descriptions) == 1
                    and x.descriptions[0].attribute == 'global_allow'
                    and x.descriptions[0].oldValue is True
                )
            )
        )
        self.replay()

        fti.manage_changeProperties(
            title="New title",
            allow_discussion=False,
            global_allow=False
        )
Exemple #3
0
    def setUpPloneSite(self, portal):
        self.applyProfile(portal, "plone.app.dexterity:default")

        from plone.dexterity.fti import DexterityFTI
        fti = DexterityFTI("MicroSite")
        fti.title = u"MicroSite"
        fti.klass = "plone.dexterity.content.Container"
        fti.behaviors = (
            "plone.app.dexterity.behaviors.metadata.IBasic",
            "plone.app.content.interfaces.INameFromTitle",
            "collective.behavior.localregistry.behavior.ILocalRegistry",
            "collective.behavior.localskin.behavior.ILocalSkin",
        )
        portal.portal_types._setObject("MicroSite", fti)
Exemple #4
0
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti.manage_changeProperties(title="New title",
                                    allow_discussion=False,
                                    global_allow=False)

        self.assertEqual(len(notify_mock.call_args_list), 2)
Exemple #5
0
 def test_fires_modified_event_on_update_property_if_changed(self):
     fti = DexterityFTI(u"testtype")
     
     fti.title = u"Old title"
     fti.global_allow = False
     
     notify_mock = self.mocker.replace('zope.event.notify')
     self.expect(notify_mock(mocker.MATCH(lambda x: IObjectModifiedEvent.providedBy(x) \
                                                     and len(x.descriptions) == 1 \
                                                     and x.descriptions[0].attribute == 'title' \
                                                     and x.descriptions[0].oldValue == "Old title")))
     
     self.replay()
     
     fti._updateProperty('title', "New title") # fires event caught above
     fti._updateProperty('allow_discussion', False) # does not fire
Exemple #6
0
    def test_fires_modified_event_on_change_props_per_changed_property(self):
        fti = DexterityFTI(u"testtype")
        fti.title = "Old title"
        fti.allow_discussion = False
        fti.global_allow = True

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti.manage_changeProperties(
            title="New title",
            allow_discussion=False,
            global_allow=False
        )

        self.assertEqual(len(notify_mock.call_args_list), 2)
Exemple #7
0
    def test_fires_modified_event_on_update_property_if_changed(self):
        fti = DexterityFTI(u"testtype")

        fti.title = u"Old title"
        fti.global_allow = False

        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(notify_mock(mocker.MATCH(lambda x: IObjectModifiedEvent.providedBy(x) \
                                                        and len(x.descriptions) == 1 \
                                                        and x.descriptions[0].attribute == 'title' \
                                                        and x.descriptions[0].oldValue == "Old title")))

        self.replay()

        fti._updateProperty('title', "New title")  # fires event caught above
        fti._updateProperty('allow_discussion', False)  # does not fire
Exemple #8
0
    def test_fires_modified_event_on_update_property_if_changed(self):
        fti = DexterityFTI(u"testtype")

        fti.title = u"Old title"
        fti.global_allow = False

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti._updateProperty('title', "New title")  # fires event caught above
        fti._updateProperty('allow_discussion', False)  # does not fire

        event = notify_mock.call_args[0][0]
        self.assertTrue(IObjectModifiedEvent.providedBy(event))
        self.assertEqual(len(event.descriptions), 1)
        self.assertEqual(event.descriptions[0].attribute, 'title')
        self.assertEqual(event.descriptions[0].oldValue, 'Old title')
Exemple #9
0
    def test_fires_modified_event_on_update_property_if_changed(self):
        fti = DexterityFTI(u"testtype")

        fti.title = u"Old title"
        fti.global_allow = False

        from zope.event import notify
        notify_mock = self.patch_global(notify)

        fti._updateProperty('title', "New title")  # fires event caught above
        fti._updateProperty('allow_discussion', False)  # does not fire

        event = notify_mock.call_args[0][0]
        self.assertTrue(IObjectModifiedEvent.providedBy(event))
        self.assertEqual(len(event.descriptions), 1)
        self.assertEqual(event.descriptions[0].attribute, 'title')
        self.assertEqual(event.descriptions[0].oldValue, 'Old title')
    def setUpPloneSite(self, portal):
        portal.portal_workflow.setDefaultChain('simple_publication_workflow')
        self.applyProfile(portal, 'example.uidattrbehavior:default')

        # Define minimal buyable content type
        fti = DexterityFTI('example')
        fti.title = u'example'
        fti.icon_expr = 'string:${portal_url}/document_icon.png'
        fti.icon_expr_object = Expression(fti.icon_expr)
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
  <schema />
</model>"""
        fti.behaviors = (
            'plone.app.content.interfaces.INameFromTitle',
            'plone.app.dexterity.behaviors.metadata.IBasic',
            'plone.app.dexterity.behaviors.metadata.ICategorization',
            'example.uidattrbehavior.behaviors.IUIDAttrBehavior',
        )
        portal.portal_types._setObject('example', fti)

        setRoles(portal, TEST_USER_ID, ['Manager'])
        createContentInContainer(portal, 'example', title=u'Hello World')
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
Exemple #12
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