def setUp(self):
        # add IShortName behavior to Page
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])

        fti = DexterityFTI('LockableType',
                           factory='LockableType')
        fti.behaviors = ('plone.app.lockingbehavior.behaviors.ILocking', )
        fti.global_allow = True
        self.portal.portal_types._setObject('LockableType', fti)
        transaction.commit()

        # prepare two browsers
        self.foo_browser = z2.Browser(self.layer['app'])
        self.foo_browser.addHeader(
            'Authorization', 'Basic %s:%s'
            % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
        )
        self.foo_browser.open('http://nohost/plone')

        self.bar_browser = z2.Browser(self.layer['app'])
        self.bar_browser.addHeader(
            'Authorization', 'Basic %s:%s'
            % (TEST_USER_NAME, TEST_USER_PASSWORD,)
        )
        self.bar_browser.open('http://nohost/plone')
Beispiel #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
        )
Beispiel #3
0
    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)
Beispiel #4
0
    def setUpPloneSite(self, portal):
        self.applyProfile(portal, 'plone.app.dexterity:default')
        self.applyProfile(portal, 'plone.app.drafts:default')

        if 'Folder' not in portal.portal_types.objectIds():
            fti = DexterityFTI('Folder')
            fti.behaviors = (
                'plone.app.dexterity.behaviors.metadata.IDublinCore', )
            fti.klass = 'plone.dexterity.content.Container'
            fti.filter_content_types = False
            fti.global_allow = True
            portal.portal_types._setObject('Folder', fti)

        fti = DexterityFTI('MyDocument')
        fti.behaviors = (
            'plone.app.dexterity.behaviors.metadata.IDublinCore',
            'plone.app.drafts.interfaces.IDraftable',
        )
        fti.global_allow = True
        portal.portal_types._setObject('MyDocument', fti)
Beispiel #5
0
    def setUpPloneSite(self, portal):
        self.applyProfile(portal, 'plone.app.dexterity:default')
        self.applyProfile(portal, 'plone.app.drafts:default')

        if 'Folder' not in portal.portal_types.objectIds():
            fti = DexterityFTI('Folder')
            fti.behaviors = (
                'plone.app.dexterity.behaviors.metadata.IDublinCore',
            )
            fti.klass = 'plone.dexterity.content.Container'
            fti.filter_content_types = False
            fti.global_allow = True
            portal.portal_types._setObject('Folder', fti)

        fti = DexterityFTI('MyDocument')
        fti.behaviors = (
            'plone.app.dexterity.behaviors.metadata.IDublinCore',
            'plone.app.drafts.interfaces.IDraftable'
        )
        fti.global_allow = True
        portal.portal_types._setObject('MyDocument', fti)
Beispiel #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)
Beispiel #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
Beispiel #8
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)
Beispiel #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
     
     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
    def create_type_with_date_field(self, name):
        from plone.dexterity.fti import DexterityFTI
        fti = DexterityFTI(str(name), title=name)
        fti.behaviors = ('plone.app.dexterity.behaviors.metadata.IBasic',)
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="duedate" type="zope.schema.Date">
  <description />
  <required>False</required>
  <title>Due Date</title>
</field>
</schema>
</model>"""
        fti.global_allow = True
        self.portal_types._setObject(str(name), fti)
Beispiel #11
0
    def create_type_with_date_field(self, name):
        from plone.dexterity.fti import DexterityFTI
        fti = DexterityFTI(str(name), title=name)
        fti.behaviors = ('plone.app.dexterity.behaviors.metadata.IBasic', )
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="duedate" type="zope.schema.Date">
  <description />
  <required>False</required>
  <title>Due Date</title>
</field>
</schema>
</model>"""
        fti.global_allow = True
        self.portal_types._setObject(str(name), fti)
Beispiel #12
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')
Beispiel #13
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')
Beispiel #14
0
    def create_content_type(self, portal_type):
        """Create dummy content type with a single custom field"""
        fti = DexterityFTI(str(portal_type), title=portal_type)
        fti.behaviors = (
            'plone.app.dexterity.behaviors.metadata.IBasic',
            'plone.app.multilingual.dx.interfaces.IDexterityTranslatable')
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="custom" type="zope.schema.TextLine">
  <description />
  <required>False</required>
  <title>Custom field</title>
</field>
</schema>
</model>"""
        fti.global_allow = True
        self.portal_types._setObject(str(portal_type), fti)
Beispiel #15
0
    def create_content_type(self, portal_type):
        """Create dummy content type with a single custom field"""
        fti = DexterityFTI(str(portal_type), title=portal_type)
        fti.behaviors = (
            "plone.app.dexterity.behaviors.metadata.IBasic",
            "plone.app.multilingual.dx.interfaces.IDexterityTranslatable",
        )
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="custom" type="zope.schema.TextLine">
  <description />
  <required>False</required>
  <title>Custom field</title>
</field>
</schema>
</model>"""
        fti.global_allow = True
        self.portal_types._setObject(str(portal_type), fti)
Beispiel #16
0
    def create_content_type(self, portal_type):
        """Create dummy content type with a single custom field"""
        disableCSRFProtection()
        fti = DexterityFTI(str(portal_type), title=portal_type)
        fti.behaviors = (
            'plone.basic',
            'plone.translatable',
        )
        fti.model_source = u"""\
<model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="custom" type="zope.schema.TextLine">
  <description />
  <required>False</required>
  <title>Custom field</title>
</field>
</schema>
</model>"""
        fti.global_allow = True
        self.portal_types._setObject(str(portal_type), fti)
Beispiel #17
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
Beispiel #18
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