Esempio n. 1
0
 def testFromPage(self):
     page = RecurringEventPage(
         owner=self.user,
         slug="code-for-boston",
         title="Code for Boston",
         repeat=Recurrence(dtstart=dt.date(2017, 1, 1),
                           freq=WEEKLY,
                           byweekday=[TU],
                           until=dt.date(2017, 12, 26)),
         time_from=dt.time(19),
         time_to=dt.time(21, 30),
         tz=pytz.timezone("US/Eastern"),
         location="4th Floor, 1 Broadway, Cambridge, MA")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     vev = VEventFactory().makeFromPage(page)
     self.assertIs(type(vev), RecurringVEvent)
     vev.set('UID', "this-is-not-a-unique-identifier")
     codeForBoston = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Code for Boston",
         b"DTSTART;TZID=US/Eastern:20170103T190000",
         b"DTEND;TZID=US/Eastern:20170103T213000",
         b"DTSTAMP:20170815T000000Z",
         b"UID:this-is-not-a-unique-identifier", b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;UNTIL=20171227T045959Z;BYDAY=TU;WKST=SU",
         b"CREATED:20170815T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170815T000000Z",
         b"LOCATION:4th Floor\\, 1 Broadway\\, Cambridge\\, MA",
         b"URL:http://joy.test/events/code-for-boston/", b"END:VEVENT", b""
     ])
     self.assertEqual(vev.to_ical(), codeForBoston)
Esempio n. 2
0
 def testExtraInfo(self):
     page = RecurringEventPage(
         owner=self.user,
         slug="code-for-boston",
         title="Code for Boston",
         repeat=Recurrence(dtstart=dt.date(2017, 1, 1),
                           freq=WEEKLY,
                           byweekday=[TU],
                           until=dt.date(2017, 12, 26)),
         time_from=dt.time(19),
         time_to=dt.time(21, 30),
         tz=pytz.timezone("US/Eastern"),
         location="4th Floor, 1 Broadway, Cambridge, MA")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     info = ExtraInfoPage(owner=self.user,
                          slug="2017-06-06-extra-info",
                          title="Extra Information for Tuesday 6th of June",
                          overrides=page,
                          except_date=dt.date(2017, 6, 6),
                          extra_title="Handling Time Zones with Python")
     page.add_child(instance=info)
     info.save_revision().publish()
     vev = VEventFactory().makeFromPage(page)
     self.assertIs(type(vev), RecurringVEvent)
     vev.set('UID', "this-is-not-a-unique-identifier")
     codeForBoston = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Code for Boston",
         b"DTSTART;TZID=US/Eastern:20170103T190000",
         b"DTEND;TZID=US/Eastern:20170103T213000",
         b"DTSTAMP:20170515T000000Z",
         b"UID:this-is-not-a-unique-identifier", b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;UNTIL=20171227T045959Z;BYDAY=TU;WKST=SU",
         b"CREATED:20170515T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170515T000000Z",
         b"LOCATION:4th Floor\\, 1 Broadway\\, Cambridge\\, MA",
         b"URL:http://joy.test/events/code-for-boston/", b"END:VEVENT", b""
     ])
     self.assertEqual(vev.to_ical(), codeForBoston)
     self.assertEqual(len(vev.vchildren), 1)
     vchild = vev.vchildren[0]
     vchild.set('UID', "this-is-not-a-unique-identifier")
     self.assertIs(type(vchild), ExtraInfoVEvent)
     talk = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Handling Time Zones with Python",
         b"DTSTART;TZID=US/Eastern:20170606T190000",
         b"DTEND;TZID=US/Eastern:20170606T213000",
         b"DTSTAMP:20170515T000000Z",
         b"UID:this-is-not-a-unique-identifier",
         b"RECURRENCE-ID;TZID=US/Eastern:20170606T190000", b"SEQUENCE:1",
         b"CREATED:20170515T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170515T000000Z",
         b"LOCATION:4th Floor\\, 1 Broadway\\, Cambridge\\, MA",
         b"URL:http://joy.test/events/code-for-boston/2017-06-06-extra-info/",
         b"END:VEVENT", b""
     ])
     self.assertEqual(vchild.to_ical(), talk)
Esempio n. 3
0
 def testExdate(self):
     page = RecurringEventPage(owner=self.user,
                               slug="sleep",
                               title="Sleep In",
                               repeat=Recurrence(dtstart=dt.date(
                                   2018, 5, 1),
                                                 freq=MONTHLY,
                                                 byweekday=[SA(+2)]),
                               time_from=dt.time(7),
                               time_to=dt.time(10, 30),
                               tz=pytz.timezone("Pacific/Auckland"),
                               details="<p>zzzZZZZZZZZZ</p>",
                               location="Bed")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     except1 = CancellationPage(
         owner=self.user,
         slug="2018-06-09-cancellation",
         title="Cancellation for Saturday 9th of June",
         overrides=page,
         except_date=dt.date(2018, 6, 9))
     page.add_child(instance=except1)
     except1.save_revision().publish()
     except2 = CancellationPage(
         owner=self.user,
         slug="2018-07-14-cancellation",
         title="Cancellation for Saturday 14th of July",
         overrides=page,
         except_date=dt.date(2018, 7, 14))
     page.add_child(instance=except2)
     except2.save_revision().publish()
     vev = VEventFactory().makeFromPage(except1)
     self.assertIs(type(vev), RecurringVEvent)
     vev.set('UID', "this-is-not-a-unique-identifier")
     tz = pytz.timezone("Pacific/Auckland")
     exDates = [exDate.dt for exDate in vev['EXDATE'].dts]
     self.assertEqual(exDates, [
         tz.localize(dt.datetime(2018, 6, 9, 7)),
         tz.localize(dt.datetime(2018, 7, 14, 7))
     ])
     sleepIn = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Sleep In",
         b"DTSTART;TZID=Pacific/Auckland:20180512T070000",
         b"DTEND;TZID=Pacific/Auckland:20180512T103000",
         b"DTSTAMP:20180510T000000Z",
         b"UID:this-is-not-a-unique-identifier", b"SEQUENCE:1",
         b"RRULE:FREQ=MONTHLY;BYDAY=+2SA;WKST=SU",
         b"EXDATE;TZID=Pacific/Auckland:20180609T070000,20180714T070000",
         b"CREATED:20180510T000000Z", b"DESCRIPTION:zzzZZZZZZZZZ",
         b"LAST-MODIFIED:20180510T000000Z", b"LOCATION:Bed",
         b"URL:http://joy.test/events/sleep/",
         b"X-ALT-DESC;FMTTYPE=text/html:<p>zzzZZZZZZZZZ</p>", b"END:VEVENT",
         b""
     ])
     self.assertEqual(vev.to_ical(), sleepIn)