Example #1
0
    def test_data_postprocessing(self):
        # Addressing bug #62
        self.portal.invokeFactory(
            'plone.app.event.dx.event',
            'event1',
            start=datetime(2012, 10, 19, 0, 30),
            end=datetime(2012, 10, 19, 1, 30),
            timezone="Europe/Vienna",
            whole_day=False
        )
        e1 = self.portal['event1']
        e1.reindexObject()

        # Prepare reference objects
        tzname_1 = "Europe/Vienna"
        tz_1 = pytz.timezone(tzname_1)
        dt_1 = tz_1.localize(datetime(2012, 10, 19, 0, 30))
        dt_1_1 = tz_1.localize(datetime(2012, 10, 19, 0, 0))
        dt_1_2 = tz_1.localize(datetime(2012, 10, 19, 23, 59, 59))

        tzname_2 = "Hongkong"
        tz_2 = pytz.timezone(tzname_2)
        dt_2 = tz_2.localize(datetime(2012, 10, 19, 0, 30))
        dt_2_1 = tz_2.localize(datetime(2012, 10, 19, 0, 0))
        dt_2_2 = tz_2.localize(datetime(2012, 10, 19, 23, 59, 59))

        # See, if start isn't moved by timezone offset. Addressing issue #62
        self.assertTrue(IEventBasic(e1).start == dt_1)
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1)

        # After timezone changes, only the timezone should be applied, but the
        # date and time values not converted.
        IEventAccessor(e1).timezone = tzname_2
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_2)

        # Test open_end events
        # For open_end events, setting the end date has no effect
        IEventAccessor(e1).edit(
            timezone=tzname_1,
            open_end=True,
            end=datetime(2012, 11, 11, 10, 10, 0),
        )
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1)
        self.assertTrue(IEventBasic(e1).end == dt_1_2)

        # Likewise with whole_day events. If values were converted, the days
        # would drift apart.
        IEventAccessor(e1).whole_day = True
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_1_1)
        self.assertTrue(IEventBasic(e1).end == dt_1_2)

        IEventAccessor(e1).timezone = tzname_2
        notify(ObjectModifiedEvent(e1))
        self.assertTrue(IEventBasic(e1).start == dt_2_1)
        self.assertTrue(IEventBasic(e1).end == dt_2_2)
Example #2
0
    def test_event_accessor(self):
        utc = pytz.utc
        self.portal.invokeFactory(
            'plone.app.event.dx.event',
            'event1',
            start=datetime(2011, 11, 11, 11, 0, tzinfo=utc),
            end=datetime(2011, 11, 11, 12, 0, tzinfo=utc),
            timezone='UTC',
            whole_day=False
        )
        e1 = self.portal['event1']

        # setting attributes via the accessor
        acc = IEventAccessor(e1)
        acc.end = datetime(2011, 11, 13, 10, 0)
        acc.timezone = TZNAME

        tz = pytz.timezone(TZNAME)

        # accessor should return end datetime in the event's timezone
        self.assertTrue(acc.end == datetime(2011, 11, 13, 11, 0, tzinfo=tz))

        # the behavior's end datetime is stored in utc on the content object
        self.assertTrue(e1.end == datetime(2011, 11, 13, 10, 0, tzinfo=utc))

        # accessing the end property via the behavior adapter, returns the
        # value converted to the event's timezone
        self.assertTrue(
            IEventBasic(e1).end == datetime(2011, 11, 13, 11, 0, tzinfo=tz)
        )

        # timezone should be the same on the event object and accessor
        self.assertTrue(e1.timezone == acc.timezone)
Example #3
0
 def test_phone_or_cellphone(self):
     add_behavior('Event', IRelatedContacts.__identifier__)
     timezone = 'Europe/Brussels'
     now = datetime.datetime.now()
     self.event = api.content.create(container=self.portal,
                                     type='Event',
                                     id='event')
     self.event.timezone = timezone
     eventbasic = IEventBasic(self.event)
     eventbasic.start = datetime.datetime(now.year, now.month, now.day, 18)
     eventbasic.end = datetime.datetime(now.year, now.month, now.day, 21)
     self.event.reindexObject()
     view = getMultiAdapter((self.event, self.request),
                            name='event_summary')
     person, organization1, organization2 = add_test_contents(self.portal)
     organization1.phone = ['081/586.100']
     phone_or_cellphone = view.get_phone_or_cellphone(organization1)
     self.assertEqual(phone_or_cellphone[0].get('formated'),
                      '+32 (0) 81 58 61 00')
     organization1.phone = []
     phone_or_cellphone = view.get_phone_or_cellphone(organization1)
     self.assertEqual(len(phone_or_cellphone), 0)
     organization1.cell_phone = ['081/586.101']
     phone_or_cellphone = view.get_phone_or_cellphone(organization1)
     self.assertEqual(phone_or_cellphone[0].get('formated'),
                      '+32 (0) 81 58 61 01')
Example #4
0
    def test_related_contacts_behavior_view_for_contact(self):
        add_behavior('Event', IRelatedContacts.__identifier__)
        timezone = 'Europe/Brussels'
        now = datetime.datetime.now()
        self.event = api.content.create(container=self.portal,
                                        type='Event',
                                        id='event')
        self.event.timezone = timezone
        eventbasic = IEventBasic(self.event)
        eventbasic.start = datetime.datetime(now.year, now.month, now.day, 18)
        eventbasic.end = datetime.datetime(now.year, now.month, now.day, 21)
        self.event.reindexObject()
        view = getMultiAdapter((self.event, self.request),
                               name='event_summary')
        person, organization1, organization2 = add_test_contents(self.portal)

        # set related contact
        intids = getUtility(IIntIds)
        to_id = intids.getId(organization1)
        rv = RelationValue(to_id)
        self.event.contact = rv
        self.assertEqual(view.get_website(organization1), None)
        organization1.website = 'www.foo.bar'
        self.assertEqual(
            view.get_website(organization1),
            '<a class="event_website" href="http://www.foo.bar" target="_blank">www.foo.bar</a>'  # noqa
        )
Example #5
0
    def test_related_contacts_behavior_view_for_partners(self):
        add_behavior('Event', IRelatedContacts.__identifier__)
        timezone = 'Europe/Brussels'
        now = datetime.datetime.now()
        self.event = api.content.create(container=self.portal,
                                        type='Event',
                                        id='event')
        self.event.timezone = timezone
        eventbasic = IEventBasic(self.event)
        eventbasic.start = datetime.datetime(now.year, now.month, now.day, 18)
        eventbasic.end = datetime.datetime(now.year, now.month, now.day, 21)
        self.event.reindexObject()
        view = getMultiAdapter((self.event, self.request),
                               name='event_summary')
        self.assertNotIn('partners', view())

        person, organization1, organization2 = add_test_contents(self.portal)

        # set related contact
        intids = getUtility(IIntIds)
        to_id1 = intids.getId(person)
        to_id2 = intids.getId(organization2)
        rv1 = RelationValue(to_id1)
        rv2 = RelationValue(to_id2)
        self.event.partners = [rv1, rv2]
        self.assertIn('partners', view())
 def set_event_fields(self, obj, data):
     self.set_fields(obj, data)
     #
     event = IEventBasic(obj)
     start = DateTime(data["startDate"]["value"])
     event.start = self.format_datetime(start)
     end = DateTime(data["endDate"]["value"])
     event.end = self.format_datetime(end)
     event.timezone = 'CET'
Example #7
0
    def inject_sane_dates(self):
        """ Takes the IEventSubmissionDate data and makes nice IEventBasic
        data out of it.

        """
        basic = IEventBasic(self.context)
        recurring = IEventRecurrence(self.context)

        (basic.start, basic.end, basic.whole_day,
         recurring.recurrence) = get_event_dates_from_submission(
             self.data, basic.timezone)

        self.submission_recurrence = recurring.recurrence
Example #8
0
 def test_event_view_without_behavior(self):
     timezone = 'Europe/Brussels'
     now = datetime.datetime.now()
     self.event = api.content.create(container=self.portal,
                                     type='Event',
                                     id='event')
     self.event.timezone = timezone
     self.event.location = u'Mon adresse'
     eventbasic = IEventBasic(self.event)
     eventbasic.start = datetime.datetime(now.year, now.month, now.day, 18)
     eventbasic.end = datetime.datetime(now.year, now.month, now.day, 21)
     self.event.reindexObject()
     view = getMultiAdapter((self.event, self.request),
                            name='event_summary')
     self.assertNotIn('partners', view())
Example #9
0
 def talk_date(self):
     wrapped = IEventBasic(self.context)
     return ''