Ejemplo n.º 1
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())
Ejemplo n.º 2
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
        )
Ejemplo n.º 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')
Ejemplo n.º 4
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')
Ejemplo n.º 5
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
        )
Ejemplo n.º 6
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'
Ejemplo n.º 8
0
    def test_validate_invariants_edge(self):
        data = MockEvent()
        data.start = datetime.datetime(2009, 1, 2)
        data.end = datetime.datetime(2009, 1, 2)

        try:
            IEventBasic.validateInvariants(data)
        except:
            self.fail()
 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'
Ejemplo n.º 10
0
    def test_validate_invariants_ok(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 1)
        mock.end = datetime(2009, 1, 2)

        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 11
0
    def test_validate_invariants_ok(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 1)
        mock.end = datetime(2009, 1, 2)

        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 12
0
    def test_validate_invariants_fail(self):
        data = MockEvent()
        data.start = datetime.datetime(2009, 1, 2)
        data.end = datetime.datetime(2009, 1, 1)

        try:
            IEventBasic.validateInvariants(data)
            self.fail()
        except StartBeforeEnd:
            pass
Ejemplo n.º 13
0
    def test_validate_invariants_fail(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 2)
        mock.end = datetime(2009, 1, 1)

        try:
            IEventBasic.validateInvariants(mock)
            self.fail()
        except StartBeforeEnd:
            pass
Ejemplo n.º 14
0
    def test_validate_invariants_edge(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 2)
        mock.end = datetime(2009, 1, 2)
        mock.open_end = False

        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 15
0
    def test_validate_invariants_fail(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 2)
        mock.end = datetime(2009, 1, 1)

        try:
            IEventBasic.validateInvariants(mock)
            self.fail()
        except StartBeforeEnd:
            pass
Ejemplo n.º 16
0
    def test_validate_invariants_edge(self):
        mock = MockEvent()
        mock.start = datetime(2009, 1, 2)
        mock.end = datetime(2009, 1, 2)
        mock.open_end = False

        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 17
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)
Ejemplo n.º 18
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())
Ejemplo n.º 19
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())
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
    def test_validate_dont_validate_incomplete(self):
        """Don't validate validate_start_end invariant, if start or end are
        None.
        """
        mock = MockEvent()
        mock.open_end = False

        mock.start = datetime(2016, 5, 18)
        mock.end = None
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()

        mock.start = None
        mock.end = datetime(2016, 5, 18)
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()

        mock.start = None
        mock.end = None
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 22
0
    def test_validate_dont_validate_incomplete(self):
        """Don't validate validate_start_end invariant, if start or end are
        None.
        """
        mock = MockEvent()
        mock.open_end = False

        mock.start = datetime(2016, 5, 18)
        mock.end = None
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()

        mock.start = None
        mock.end = datetime(2016, 5, 18)
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()

        mock.start = None
        mock.end = None
        try:
            IEventBasic.validateInvariants(mock)
        except:
            self.fail()
Ejemplo n.º 23
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
Ejemplo n.º 24
0
from zope import schema
from plone.autoform.interfaces import WIDGETS_KEY
from plone.app.event.dx.behaviors import IEventBasic
from plone.supermodel import model
from plone.namedfile.field import NamedBlobImage
from collective.rcse.i18n import _
from collective.z3cform.html5widgets.widget_datetime import DateTimeWidget


#override event basic widgets
IEventBasic.setTaggedValue(
    WIDGETS_KEY, {'start': DateTimeWidget,
                  'end': DateTimeWidget}
)


class EventSchema(model.Schema):
    """event extra fields"""
    image = NamedBlobImage(title=_(u"Image"),
                           description=_(u"image_description"),
                           required=False)
    urlMedia = schema.URI(title=_(u"Media URL"),
                          description=_(u"urlMedia_description"),
                          required=False)
    urlGMaps = schema.URI(title=_(u"Google Maps URL"),
                          description=_(u"urlGMaps_description"),
                          required=False)
Ejemplo n.º 25
0
 def talk_date(self):
     wrapped = IEventBasic(self.context)
     return ''