示例#1
0
 def testLoadRecurring(self):
     data = b"\r\n".join([
         b"BEGIN:VCALENDAR",
         b"VERSION:2.0",
         b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
         b"BEGIN:VEVENT",
         b"SUMMARY:Fierce Tango",
         b"DESCRIPTION:Argentine Show Tango Performance",
         b"DTSTART:20180405T193000",
         b"DTEND:20180405T220000",
         b"RECURRENCE-ID:20180405T193000",
         b"DTSTAMP:20180408T094745Z",
         b"LAST-MODIFIED:20180314T010000Z",
         b"UID:[email protected]",
         b"END:VEVENT",
         b"BEGIN:VEVENT",
         b"SUMMARY:Tango Thursdays",
         b"DESCRIPTION:Weekly tango lessons at the Dance Spot",
         b"DTSTART:20180329T193000",
         b"DTEND:20180329T220000",
         b"RRULE:FREQ=WEEKLY;BYDAY=TH",
         b"DTSTAMP:20180408T094745Z",
         b"LAST-MODIFIED:20180131T010000Z",
         b"EXDATE:20181025T193000",
         b"LOCATION:622 Bloor St. W., Toronto ON, M6G 1K7",
         b"SUMMARY:Tango Thursdays",
         b"UID:[email protected]",
         b"URL:http://torontodancespot.com/",
         b"END:VEVENT",
         b"END:VCALENDAR",
     ])
     vcal = VCalendar(self.calendar)
     vcal.load(self._getRequest(), data)
     events = RecurringEventPage.events.child_of(self.calendar).all()
     self.assertEqual(len(events), 1)
     event = events[0]
     self.assertEqual(event.slug, "tango-thursdays")
     self.assertEqual(event.title, "Tango Thursdays")
     self.assertEqual(repr(event.repeat),
                     "DTSTART:20180329\n" \
                     "RRULE:FREQ=WEEKLY;WKST=SU;BYDAY=TH")
     self.assertEqual(event.time_from, dt.time(19, 30))
     self.assertEqual(event.time_to, dt.time(22, 0))
     revisions = event.revisions.all()
     self.assertEqual(len(revisions), 1)
     info = ExtraInfoPage.events.child_of(event).get()
     self.assertEqual(info.slug, "2018-04-05-extra-info")
     self.assertEqual(info.title, "Extra-Info for Thursday 5th of April")
     self.assertEqual(info.extra_title, "Fierce Tango")
     self.assertEqual(info.extra_information,
                      "Argentine Show Tango Performance")
     self.assertEqual(info.except_date, dt.date(2018, 4, 5))
     revisions = info.revisions.all()
     self.assertEqual(len(revisions), 2)
     cancellations = CancellationPage.events.child_of(event).all()
     self.assertEqual(len(cancellations), 2)
     cancellation = cancellations[0]
     self.assertEqual(cancellation.except_date, dt.date(2019, 2, 14))
     cancellation = cancellations[1]
     self.assertEqual(cancellation.except_date, dt.date(2018, 10, 25))
示例#2
0
 def testNotInitializedLoad(self):
     data = b"\r\n".join([
         b"BEGIN:VCALENDAR",
         b"VERSION:2.0",
         b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
         b"CALSCALE:GREGORIAN",
         b"METHOD:PUBLISH",
         b"X-WR-CALNAME:Bloor & Spadina",
         b"X-ORIGINAL-URL:http://bloorneighbours.ca",
         b"X-WR-CALDESC:Events for Bloor & Spadina",
         b"BEGIN:VEVENT",
         b"DTSTART;TZID=UTC+0:20180407T093000",
         b"DTEND;TZID=UTC+0:20180407T113000",
         b"DTSTAMP:20180402T054745",
         b"CREATED:20180304T225154Z",
         b"LAST-MODIFIED:20180304T225154Z",
         b"UID:[email protected]",
         b"SUMMARY:Mini-Fair & Garage Sale",
         b"DESCRIPTION:",
         b"URL:http://bloorneighbours.ca/event/mini-fair-garage-sale/",
         b"END:VEVENT",
         b"END:VCALENDAR",
     ])
     vcal = VCalendar()
     with self.assertRaises(CalendarNotInitializedError):
         vcal.load(self.request, data)
示例#3
0
 def testLoadUnknownTZ(self):
     data  = b"\r\n".join([
             b"BEGIN:VCALENDAR",
             b"VERSION:2.0",
             b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
             b"CALSCALE:GREGORIAN",
             b"METHOD:PUBLISH",
             b"X-WR-CALNAME:Bloor & Spadina",
             b"X-ORIGINAL-URL:http://bloorneighbours.ca",
             b"X-WR-CALDESC:Events for Bloor & Spadina",
             b"X-WR-TIMEZONE:Canada/Toronto",
             b"BEGIN:VEVENT",
             b"UID:[email protected]",
             b"DTSTART:20180407T093000",
             b"DTEND:20180407T113000",
             b"DTSTAMP:20180402T054745",
             b"CREATED:20180304T225154Z",
             b"LAST-MODIFIED:20180304T225154Z",
             b"SUMMARY:Mini-Fair & Garage Sale",
             b"DESCRIPTION:",
             b"END:VEVENT",
             b"END:VCALENDAR",])
     vcal = VCalendar(self.calendar)
     request = self._getRequest()
     vcal.load(request, data)
     events = SimpleEventPage.events.child_of(self.calendar)            \
                                    .filter(date=dt.date(2018,4,7)).all()
     self.assertEqual(len(events), 1)
     self.assertEqual(events[0].tz.zone, "Asia/Tokyo")
     msgs = list(messages.get_messages(request))
     self.assertEqual(len(msgs), 2)
     self.assertEqual(msgs[0].level, messages.WARNING)
     self.assertEqual(msgs[0].message, "Unknown time zone Canada/Toronto")
     self.assertEqual(msgs[1].level, messages.SUCCESS)
     self.assertEqual(msgs[1].message, "1 iCal events loaded")
示例#4
0
 def testLoadEventMissingUID(self):
     data = b"\r\n".join([
         b"BEGIN:VCALENDAR",
         b"VERSION:2.0",
         b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
         b"CALSCALE:GREGORIAN",
         b"METHOD:PUBLISH",
         b"X-WR-CALNAME:Bloor & Spadina",
         b"X-ORIGINAL-URL:http://bloorneighbours.ca",
         b"X-WR-CALDESC:Events for Bloor & Spadina",
         b"BEGIN:VEVENT",
         b"DTSTART;TZID=UTC+0:20180407T093000",
         b"DTEND;TZID=UTC+0:20180407T113000",
         b"DTSTAMP:20180402T054745",
         b"CREATED:20180304T225154Z",
         b"LAST-MODIFIED:20180304T225154Z",
         b"SUMMARY:Mini-Fair & Garage Sale",
         b"DESCRIPTION:",
         b"URL:http://bloorneighbours.ca/event/mini-fair-garage-sale/",
         b"END:VEVENT",
         b"END:VCALENDAR",
     ])
     vcal = VCalendar(self.calendar)
     request = self._getRequest()
     vcal.load(request, data)
     events = SimpleEventPage.events.child_of(self.calendar)            \
                                    .filter(date=dt.date(2018,4,7)).all()
     self.assertEqual(len(events), 0)
     msgs = list(messages.get_messages(request))
     self.assertEqual(len(msgs), 1)
     msg = msgs[0]
     self.assertEqual(msg.level, messages.ERROR)
     self.assertEqual(msg.message, "Could not load 1 iCal events")
示例#5
0
 def testLoad(self):
     data  = b"\r\n".join([
             b"BEGIN:VCALENDAR",
             b"VERSION:2.0",
             b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
             b"CALSCALE:GREGORIAN",
             b"METHOD:PUBLISH",
             b"X-WR-CALNAME:Bloor & Spadina",
             b"X-ORIGINAL-URL:http://bloorneighbours.ca",
             b"X-WR-CALDESC:Events for Bloor & Spadina",
             b"BEGIN:VEVENT",
             b"DTSTART;TZID=UTC+0:20180407T093000",
             b"DTEND;TZID=UTC+0:20180407T113000",
             b"DTSTAMP:20180402T054745",
             b"CREATED:20180304T225154Z",
             b"LAST-MODIFIED:20180304T225154Z",
             b"UID:[email protected]",
             b"SUMMARY:Mini-Fair & Garage Sale",
             b"DESCRIPTION:",
             b"URL:http://bloorneighbours.ca/event/mini-fair-garage-sale/",
             b"END:VEVENT",
             b"END:VCALENDAR",])
     vcal = VCalendar(self.calendar)
     vcal.load(self._getRequest(), data)
     events = SimpleEventPage.events.child_of(self.calendar)            \
                                    .filter(date=dt.date(2018,4,7)).all()
     self.assertEqual(len(events), 1)
     event = events[0]
     self.assertEqual(event.owner,      self.user)
     self.assertEqual(event.slug,       "mini-fair-garage-sale")
     self.assertEqual(event.title,      "Mini-Fair & Garage Sale")
     self.assertEqual(event.details,    "")
     self.assertEqual(event.date,       dt.date(2018,4,7))
     self.assertEqual(event.time_from,  dt.time(9,30))
     self.assertEqual(event.time_to,    dt.time(11,30))
示例#6
0
 def testLoadInvalidFile(self):
     data = b"FOO:BAR:SNAFU"
     vcal = VCalendar(self.calendar)
     request = self._getRequest()
     vcal.load(request, data)
     msgs = list(messages.get_messages(request))
     self.assertEqual(len(msgs), 1)
     msg = msgs[0]
     self.assertEqual(msg.level, messages.ERROR)
     self.assertEqual(msg.message, "Could not parse iCalendar file ")
示例#7
0
 def testLoadRestricted(self):
     data = b"\r\n".join([
         b"BEGIN:VCALENDAR",
         b"VERSION:2.0",
         b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
         b"CALSCALE:GREGORIAN",
         b"METHOD:PUBLISH",
         b"X-WR-CALNAME:Bloor & Spadina",
         b"X-ORIGINAL-URL:http://bloorneighbours.ca",
         b"X-WR-CALDESC:Events for Bloor & Spadina",
         b"BEGIN:VEVENT",
         b"DTSTART;TZID=UTC+0:20130110T000000",
         b"DTEND;TZID=UTC+0:20130110T100000",
         b"DTSTAMP:20140509T110000",
         b"CREATED:20130304T225154Z",
         b"LAST-MODIFIED:20120304T225154Z",
         b"UID:80af64e7-84e6-40d9-8b4f-7edf92aab9f7",
         b"LOCATION:4 William James Lane, Toronto ON, M5S 1X9",
         b"SUMMARY:Private Rendezvous",
         b"DESCRIPTION:",
         b"END:VEVENT",
         b"END:VCALENDAR",
     ])
     vcal = VCalendar(self.calendar)
     request = self._getRequest()
     results = vcal.load(request, data)
     events = SimpleEventPage.events.child_of(self.calendar)            \
                                    .filter(date=dt.date(2013,1,10)).all()
     self.assertEqual(len(events), 1)
     event = events[0]
     self.assertEqual(event.title, "Private Rendezvous")
     self.assertEqual(event.location, "")
     revisions = event.revisions.all()
     self.assertEqual(len(revisions), 1)
     self.assertEqual(results.success, 0)
示例#8
0
 def testLoadInvalidFile(self):
     data = b"FOO:BAR:SNAFU"
     vcal = VCalendar(self.calendar)
     request = self._getRequest()
     results = vcal.load(request, data)
     self.assertEqual(results.success, 0)
     self.assertEqual(results.fail, 0)
     self.assertEqual(results.error, 1)
示例#9
0
 def testLoadRestrictedExtraInfo(self):
     data = b"\r\n".join([
         b"BEGIN:VCALENDAR",
         b"VERSION:2.0",
         b"PRODID:-//Bloor & Spadina - ECPv4.6.13//NONSGML v1.0//EN",
         b"BEGIN:VEVENT",
         b"SUMMARY:Surprise party",
         b"DESCRIPTION:Fierce Tango Final Friday",
         b"DTSTART:20180831T193000",
         b"DTEND:20180831T220000",
         b"RECURRENCE-ID:20180831T193000",
         b"DTSTAMP:20180408T094745Z",
         b"LAST-MODIFIED:20180314T010000Z",
         b"UID:[email protected]",
         b"END:VEVENT",
         b"BEGIN:VEVENT",
         b"SUMMARY:Fierce Tango Fridays",
         b"DESCRIPTION:Weekly fierce tango lessons at the Dance Spot",
         b"DTSTART:20180330T193000",
         b"DTEND:20180330T220000",
         b"RRULE:FREQ=WEEKLY;BYDAY=FR;UNTIL:20180831",
         b"DTSTAMP:20180408T094745Z",
         b"LAST-MODIFIED:20180131T010000Z",
         b"LOCATION:622 Bloor St. W., Toronto ON, M6G 1K7",
         b"SUMMARY:Fierce Tango Fridays",
         b"UID:[email protected]",
         b"URL:http://torontodancespot.com/",
         b"END:VEVENT",
         b"END:VCALENDAR",
     ])
     vcal = VCalendar(self.calendar)
     results = vcal.load(self._getRequest(), data)
     self.assertEqual(results.success, 0)
     self.assertEqual(results.fail, 1)
     self.assertEqual(results.error, 0)
     events = RecurringEventPage.events.child_of(self.calendar).all()
     self.assertEqual(len(events), 1)
     event = events[0]
     self.assertEqual(event.slug, "fierce-tango-fridays")
     self.assertEqual(event.title, "Fierce Tango Fridays")
     self.assertEqual(repr(event.repeat),
                     "DTSTART:20180330\n" \
                     "RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20180831;BYDAY=FR")
     self.assertEqual(event.time_from, dt.time(19, 30))
     self.assertEqual(event.time_to, dt.time(22, 0))
     self.assertEqual(event.revisions.count(), 1)
     info = ExtraInfoPage.events.child_of(event).get()
     self.assertEqual(info.slug, "2018-08-31-extra-info")
     self.assertEqual(info.title, "Extra-Info for Friday 31st of August")
     self.assertEqual(info.extra_title, "Surprise")
     self.assertEqual(info.extra_information, "Surprise party")
     self.assertEqual(info.except_date, dt.date(2018, 8, 31))
     self.assertEqual(info.revisions.count(), 1)