Пример #1
0
 def testFromUnsupported(self):
     page = Page(owner=self.user,
                 slug="thoughts",
                 title="My thoughts for today")
     self.home.add_child(instance=page)
     page.save_revision().publish()
     with self.assertRaises(CalendarTypeError):
         VCalendar.fromPage(page, self._getRequest("/thoughts/"))
Пример #2
0
 def testFromSimpleCalendarPage(self):
     page = SimpleEventPage(owner=self.user,
                            slug="bbq",
                            title="BBQ",
                            date=dt.date(2008, 7, 15),
                            time_from=dt.time(17, 30),
                            time_to=dt.time(19),
                            tz=pytz.timezone("Pacific/Auckland"))
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     vcal = VCalendar.fromPage(self.calendar, self._getRequest("/events/"))
     export = vcal.to_ical()
     props = [
         b"SUMMARY:BBQ",
         b"DTSTART;TZID=Pacific/Auckland:20080715T173000",
         b"DTEND;TZID=Pacific/Auckland:20080715T190000",
         b"DTSTAMP:20180512T040000Z",
         b"UID:",
         b"SEQUENCE:1",
         b"CREATED:20180512T040000Z",
         b"DESCRIPTION:",
         b"LAST-MODIFIED:20180512T040000Z",
         b"LOCATION:",
         b"URL:http://joy.test/events/bbq/",
     ]
     for prop in props:
         with self.subTest(prop=prop.split(b'\r\n', 1)[0]):
             self.assertIn(prop, export)
Пример #3
0
 def testFromCalendarPage(self):
     page = RecurringEventPage(owner=self.user,
                               slug="chess",
                               title="Chess",
                               repeat=Recurrence(dtstart=dt.date(
                                   2000, 1, 1),
                                                 freq=WEEKLY,
                                                 byweekday=[MO, WE, FR]),
                               time_from=dt.time(12),
                               time_to=dt.time(13))
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     cancellation = CancellationPage(
         owner=self.user,
         slug="2019-02-04-cancellation",
         title="Cancellation for Monday 4th of February",
         overrides=page,
         except_date=dt.date(2019, 2, 4),
         cancellation_title="No Chess Club Today")
     page.add_child(instance=cancellation)
     cancellation.save_revision().publish()
     postponement = PostponementPage(
         owner=self.user,
         slug="2019-10-02-postponement",
         title="Postponement for Wednesday 2nd of October",
         overrides=page,
         except_date=dt.date(2019, 10, 2),
         cancellation_title="",
         postponement_title="Early Morning Matches",
         date=dt.date(2019, 10, 3),
         time_from=dt.time(7, 30),
         time_to=dt.time(8, 30))
     page.add_child(instance=postponement)
     postponement.save_revision().publish()
     vcal = VCalendar.fromPage(self.calendar, self._getRequest("/events/"))
     export = vcal.to_ical()
     props = [
         b"SUMMARY:Chess",
         b"DTSTART;TZID=Asia/Tokyo:20000103T120000",
         b"DTEND;TZID=Asia/Tokyo:20000103T130000",
         b"DTSTAMP:20190121T060000Z",
         b"UID:",
         b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;WKST=SU",
         b"EXDATE;TZID=Asia/Tokyo:20190204T120000",
         b"CREATED:20190121T060000Z",
         b"DESCRIPTION:",
         b"LAST-MODIFIED:20190121T060000Z",
         b"LOCATION:",
         b"URL:http://joy.test/events/chess/",
         b"SUMMARY:Early Morning Matches",
         b"DTSTART;TZID=Asia/Tokyo:20191003T073000",
         b"DTEND;TZID=Asia/Tokyo:20191003T083000",
         b"RECURRENCE-ID;TZID=Asia/Tokyo:20191002T120000",
     ]
     for prop in props:
         with self.subTest(prop=prop):
             self.assertIn(prop, export)
Пример #4
0
 def testFromEventPageShutdown(self):
     chess = GroupPage(slug="chess-club", title="Chess Club")
     self.home.add_child(instance=chess)
     page = RecurringEventPage(owner=self.user,
                               slug="chess",
                               title="Chess",
                               repeat=Recurrence(dtstart=dt.date(
                                   2020, 1, 1),
                                                 freq=WEEKLY,
                                                 byweekday=[MO, WE, FR]),
                               time_from=dt.time(12),
                               time_to=dt.time(13),
                               holidays=self.calendar.holidays)
     chess.add_child(instance=page)
     page.save_revision().publish()
     shutdown = ExtCancellationPage(
         owner=self.user,
         slug="2020-03-20--cancellation",
         title="Cancelled from 20th March until further notice",
         overrides=page,
         cancelled_from_date=dt.date(2020, 3, 20))
     page.add_child(instance=shutdown)
     shutdown.save_revision().publish()
     vcal = VCalendar.fromPage(page, self._getRequest("/events/chess/"))
     export = vcal.to_ical()
     props = [
         b"SUMMARY:Chess",
         b"DTSTART;TZID=Asia/Tokyo:20200101T12000",
         b"DTEND;TZID=Asia/Tokyo:20200101T13000",
         b"DTSTAMP:20200121T040000Z",
         b"UID:",
         b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;WKST=SU",
         b"EXDATE;TZID=Asia/Tokyo:20200320T120000,20200323T120000,20200325T120000,",
         b",20200408T120000,20200410T120000,20200413T120000,20200415T120000,",
         b",20200928T120000,20200930T120000,20201002T120000,20201005T120000,",
         b",20201120T120000,20201123T120000,20201125T120000,20201127T120000,",
         b",20210614T120000,20210616T120000,20210618T120000,20210621T120000,",
         b",20240902T120000,20240904T120000,20240906T120000,20240909T120000,",
         b",20260213T120000,20260216T120000,20260218T120000,20260220T120000,",
         b",20371230T120000,20380101T120000",
         b"CREATED:20200121T040000Z",
         b"DESCRIPTION:",
         b"LAST-MODIFIED:20200121T040000Z",
         b"LOCATION:",
         b"URL:http://joy.test/chess-club/chess/",
     ]
     for prop in props:
         with self.subTest(prop=prop):
             self.assertIn(prop, export)
Пример #5
0
 def testFromEventPageClosedHolidays(self):
     chess = GroupPage(slug="chess-club", title="Chess Club")
     self.home.add_child(instance=chess)
     page = RecurringEventPage(owner=self.user,
                               slug="chess",
                               title="Chess",
                               repeat=Recurrence(dtstart=dt.date(
                                   2020, 1, 1),
                                                 freq=WEEKLY,
                                                 byweekday=[MO, WE, FR]),
                               time_from=dt.time(12),
                               time_to=dt.time(13),
                               holidays=self.calendar.holidays)
     chess.add_child(instance=page)
     page.save_revision().publish()
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        slug="closed-for-holidays",
                                        title="Closed for holidays",
                                        all_holidays=True,
                                        overrides=page,
                                        holidays=self.calendar.holidays)
     page.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     vcal = VCalendar.fromPage(page, self._getRequest("/events/chess/"))
     export = vcal.to_ical()
     props = [
         b"SUMMARY:Chess",
         b"DTSTART;TZID=Asia/Tokyo:20200101T12000",
         b"DTEND;TZID=Asia/Tokyo:20200101T13000",
         b"DTSTAMP:20200121T040000Z",
         b"UID:",
         b"SEQUENCE:1",
         b"RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;WKST=SU",
         b"EXDATE;TZID=Asia/Tokyo:20200101T120000,20200120T120000,20200127T120000,",
         b",20251024T120000,20251027T120000,20251103T120000,20251114T120000,",
         b",20281117T120000,20281127T120000,20281204T120000,20281225T",
         b",20341030T120000,20341117T120000,20341127T120000,20341204T120000,",
         b",20361226T120000,20370102T120000,20370119T120000,20370126T120000,",
         b",20381101T120000,20381112T120000,20381129T120000,20381227T120000",
         b"CREATED:20200121T040000Z",
         b"DESCRIPTION:",
         b"LAST-MODIFIED:20200121T040000Z",
         b"LOCATION:",
         b"URL:http://joy.test/chess-club/chess/",
     ]
     for prop in props:
         with self.subTest(prop=prop):
             self.assertIn(prop, export)
Пример #6
0
 def testFromEventPage(self):
     vcal = VCalendar.fromPage(self.event, self.request)
     export = vcal.to_ical()
     props = [b"SUMMARY:Chess Matches",
              b"DTSTART;TZID=Asia/Tokyo:20120801T120000",
              b"DTEND;TZID=Asia/Tokyo:20120801T130000",
              b"DTSTAMP:20191201T000000Z",
              b"UID:",
              b"SEQUENCE:1",
              b"RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;WKST=SU",
              b"CREATED:20120801T040000Z",
              b"DESCRIPTION:",
              b"LAST-MODIFIED:20120801T040000Z",
              b"LOCATION:",
              b"URL:http://localhost/chess-club/chess/", ]
     for prop in props:
         with self.subTest(prop=prop):
             self.assertIn(prop, export)
Пример #7
0
 def testFromSimpleEventPage(self):
     page = SimpleEventPage(owner = self.user,
                            slug  = "pet-show",
                            title = "Pet Show",
                            date  = dt.date(1987,6,5),
                            time_from = dt.time(11),
                            time_to   = dt.time(17,30),
                            tz = pytz.timezone("Australia/Sydney"))
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     vcal = VCalendar.fromPage(page, self._getRequest("/events/pet-show/"))
     export = vcal.to_ical()
     aest = b"\r\n".join([
              b"BEGIN:STANDARD",
              b"DTSTART;VALUE=DATE-TIME:19870315T020000",
              b"TZNAME:AEST",
              b"TZOFFSETFROM:+1100",
              b"TZOFFSETTO:+1000",
              b"END:STANDARD", ])
     aedt  = b"\r\n".join([
              b"BEGIN:DAYLIGHT",
              b"DTSTART;VALUE=DATE-TIME:19871025T030000",
              b"TZNAME:AEDT",
              b"TZOFFSETFROM:+1000",
              b"TZOFFSETTO:+1100",
              b"END:DAYLIGHT", ])
     props = [b"SUMMARY:Pet Show",
              b"DTSTART;TZID=Australia/Sydney:19870605T110000",
              b"DTEND;TZID=Australia/Sydney:19870605T173000",
              b"DTSTAMP:20180512T040000Z",
              b"UID:",
              b"SEQUENCE:1",
              b"CREATED:20180512T040000Z",
              b"DESCRIPTION:",
              b"LAST-MODIFIED:20180512T040000Z",
              b"LOCATION:",
              b"URL:http://joy.test/events/pet-show/",
              aest,
              aedt]
     for prop in props:
         with self.subTest(prop=prop.split(b'\r\n',1)[0]):
             self.assertIn(prop, export)