Example #1
0
 def testServeRecurring(self):
     page = RecurringEventPage(owner=self.user,
                               slug="lunch-and-code",
                               title="Lunch and Code",
                               repeat=Recurrence(dtstart=dt.date(
                                   2017, 3, 15),
                                                 freq=MONTHLY,
                                                 byweekday=[FR(-1)]),
                               time_from=dt.time(12),
                               time_to=dt.time(13),
                               tz=pytz.timezone("Pacific/Auckland"),
                               location="70 Molesworth Street, Wellington")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     response = self.handler.serve(
         page, self._getRequest("/events/lunch-and-code/"
                                "?format=google"))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(
         response.url,
         "http://www.google.com/calendar/event?action=TEMPLATE&"
         "text=Lunch+and+Code&"
         "location=70+Molesworth+Street%2C+Wellington&"
         "dates=20170331T120000%2F20170331T130000&"
         "ctz=Pacific%2FAuckland&"
         "recur=RRULE%3AFREQ%3DMONTHLY%3BWKST%3DSU%3BBYDAY%3D-1FR")
Example #2
0
 def testCancellation(self):
     # NOTE:
     # Cancellations are represented by EXDATE in VEVENT not as their own
     # VEVENT instance.  Yes, this means the cancellation_title and
     # cancellation_details are lost.
     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",
         cancellation_title="Get up early",
         overrides=page,
         except_date=dt.date(2018, 6, 9))
     page.add_child(instance=except1)
     except1.save_revision().publish()
     vexcept = CancellationVEvent.fromPage(except1)
     self.assertEqual(vexcept['SUMMARY'], "Get up early")
     self.assertEqual(vexcept['DESCRIPTION'], "")
     self.assertEqual(vexcept.to_ical(), b"\r\n")
Example #3
0
 def testFromPage(self):
     page = RecurringEventPage(owner=self.user,
                               slug="lunch-and-code",
                               title="Lunch and Code",
                               details="What we'll do really depends on "
                               "what the group feels is useful, "
                               "some ideas are:\n"
                               "- Providing feedback on past, or "
                               "in progress, projects\n"
                               "- Pair programming\n"
                               "- Coding\n",
                               repeat=Recurrence(dtstart=dt.date(
                                   2017, 3, 15),
                                                 freq=MONTHLY,
                                                 byweekday=[FR(-1)]),
                               time_from=dt.time(12),
                               time_to=dt.time(13),
                               tz=pytz.timezone("Pacific/Auckland"),
                               location="70 Molesworth Street, Wellington")
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     gev = RecurringGEvent.fromPage(page)
     self.assertEqual(
         gev.url, "http://www.google.com/calendar/event?"
         "action=TEMPLATE&"
         "text=Lunch+and+Code&"
         "details=What+we%27ll+do+really+depends+on+what+the+"
         "group+feels+is+useful%2C+some+ideas+are%3A%0A"
         "-+Providing+feedback+on+past%2C+or+in+progress%2C+projects%0A"
         "-+Pair+programming%0A-+Coding%0A&"
         "location=70+Molesworth+Street%2C+Wellington&"
         "dates=20170331T120000%2F20170331T130000&"
         "ctz=Pacific%2FAuckland&"
         "recur=RRULE%3AFREQ%3DMONTHLY%3BWKST%3DSU%3BBYDAY%3D-1FR")
Example #4
0
 def _setUpVeterisSubsite(self):
     main = getPage("/home/")
     home = Page(slug="veteris", title="Veteris Council")
     main.add_child(instance=home)
     home.save_revision().publish()
     activities = Page(slug="activities", title="Veteris Calendar")
     home.add_child(instance=activities)
     activities.save_revision().publish()
     Site.objects.create(hostname='veteris.joy.test',
                         root_page_id=home.id,
                         is_default_site=False)
     events = CalendarPage(owner=self.user,
                           slug="veteris-events",
                           title="Veteris Events")
     home.add_child(instance=events)
     events.save_revision().publish()
     committee = RecurringEventPage(owner=self.user,
                                    slug="veteris-committee",
                                    title="Committee Meeting",
                                    repeat=Recurrence(
                                        dtstart=dt.date(1970, 1, 5),
                                        freq=MONTHLY,
                                        byweekday=[MO],
                                        until=dt.date(1978, 8, 7)),
                                    time_from=dt.time(14),
                                    time_to=dt.time(15))
     events.add_child(instance=committee)
     committee.save_revision().publish()
Example #5
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]),
         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 = RecurringVEvent.fromPage(page)
     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;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)
Example #6
0
class TestTZ(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
        self.request = RequestFactory().get("/test")
        self.request.user = self.user
        self.request.session = {}
        self.calendar = GeneralCalendarPage(owner = self.user,
                                            slug  = "events",
                                            title = "Events")
        self.home.add_child(instance=self.calendar)

        self.night = RecurringEventPage(slug   = "pacnight",
                                        title  = "Pacific Night",
                                        repeat = Recurrence(dtstart=dt.date(2018,12,1),
                                                            count=1,
                                                            freq=MONTHLY,
                                                            byweekday=[SU(-1)]),
                                        time_from = dt.time(23,0),
                                        time_to   = dt.time(23,30),
                                        tz = pytz.timezone("Pacific/Pago_Pago"))
        self.calendar.add_child(instance=self.night)
        self.night.save_revision().publish()

    @timezone.override("Pacific/Kiritimati")
    def testExtremeTZGetAllEventsByDay(self):
        events = getAllEventsByDay(self.request, dt.date(2019,1,1), dt.date(2019,1,31))
        self.assertEqual(len(events), 31)
        evod1 = events[0]
        self.assertEqual(evod1.date, dt.date(2019,1,1))
        self.assertEqual(len(evod1.all_events), 1)
        self.assertEqual(len(evod1.days_events), 1)
        self.assertEqual(evod1.days_events[0].title, "Pacific Night")
Example #7
0
 def testServeException(self):
     event = RecurringEventPage(slug="test-meeting",
                                title="Test Meeting",
                                repeat=Recurrence(dtstart=dt.date(
                                    1988, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[MO, WE, FR]),
                                time_from=dt.time(13),
                                time_to=dt.time(15, 30))
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     info = ExtraInfoPage(owner=self.user,
                          overrides=event,
                          except_date=dt.date(1988, 11, 11),
                          extra_title="System Demo",
                          extra_information="<h3>System Demo</h3>")
     event.add_child(instance=info)
     info.save_revision().publish()
     response = self.handler.serve(
         info,
         self._getRequest("/events/test-meeting/1998-11-11/extra-info/"
                          "?format=google"))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(
         response.url,
         "http://www.google.com/calendar/event?action=TEMPLATE&"
         "text=Test+Meeting&"
         "dates=19880101T130000%2F19880101T153000&"
         "ctz=Asia%2FTokyo&"
         "recur=RRULE%3AFREQ%3DWEEKLY%3BWKST%3DSU%3BBYDAY%3DMO%2CWE%2CFR")
Example #8
0
class Test(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('j', '*****@*****.**', 's3(r3t')
        calendar = GeneralCalendarPage(owner=self.user,
                                       slug="events",
                                       title="Events")
        self.home.add_child(instance=calendar)
        calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="test-meeting",
                                        title="Test Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(1990, 1, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(13, 30),
                                        time_to=dt.time(16))
        calendar.add_child(instance=self.event)
        self.event.save_revision().publish()

    @freeze_timetz("1991-01-01 15:00")
    def testIdentifyExpectantParent(self):
        postponement = PostponementPage()
        identifyExpectantParent(self.testIdentifyExpectantParent,
                                parent=self.event,
                                page=postponement)
        self.assertEqual(postponement.overrides, self.event)
        self.assertEqual(postponement.except_date, dt.date(1991, 1, 2))
        self.assertEqual(postponement.date, dt.date(1991, 1, 3))
        self.assertEqual(postponement.postponement_title, "Test Meeting")
        self.assertIsNone(postponement.category)
        self.assertEqual(postponement.num_days, 1)
        self.assertEqual(postponement.time_from, dt.time(13, 30))
        self.assertEqual(postponement.time_to, dt.time(16))
Example #9
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)
Example #10
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)
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
0
 def _setUpNovaSubsite(self):
     main = getPage("/home/")
     home = Page(slug="nova", title="Nova Homepage")
     main.add_child(instance=home)
     home.save_revision().publish()
     activities = Page(slug="activities", title="Nova Activities")
     home.add_child(instance=activities)
     activities.save_revision().publish()
     Site.objects.create(hostname='nova.joy.test',
                         root_page_id=home.id,
                         is_default_site=False)
     events = CalendarPage(owner=self.user,
                           slug="nova-events",
                           title="Nova Events")
     home.add_child(instance=events)
     events.save_revision().publish()
     committee = RecurringEventPage(owner=self.user,
                                    slug="executive-meeting",
                                    title="Executive Committee Meeting",
                                    repeat=Recurrence(dtstart=dt.date(
                                        1984, 8, 5),
                                                      freq=WEEKLY,
                                                      byweekday=[TH]),
                                    time_from=dt.time(13),
                                    time_to=dt.time(15))
     events.add_child(instance=committee)
     committee.save_revision().publish()
     event = SimpleEventPage(owner=self.user,
                             slug="rubbish-blitz",
                             title="Rubbish Blitz",
                             date=dt.date(1984, 9, 13),
                             time_from=dt.time(12, 30),
                             time_to=dt.time(17))
     events.add_child(instance=event)
     event.save_revision().publish()
     cancellation = CancellationPage(
         owner=self.user,
         slug="1984-09-13-cancellation",
         title="Cancellation for Thursday 13th of September",
         overrides=committee,
         except_date=dt.date(1984, 9, 13),
         cancellation_title="Meeting Cancelled",
         cancellation_details="The committee will be at "
         "the working bee")
     committee.add_child(instance=cancellation)
     cancellation.save_revision().publish()
Example #15
0
 def setUp(self):
     site = Site.objects.get(is_default_site=True)
     site.hostname = "joy.test"
     site.save()
     self.home = getPage("/home/")
     self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
     self.requestFactory = RequestFactory()
     self.calendar = CalendarPage(owner=self.user,
                                  slug="events",
                                  title="Events")
     self.home.add_child(instance=self.calendar)
     self.calendar.save_revision().publish()
     event = RecurringEventPage(
         owner=self.user,
         slug="fierce-tango-fridays",
         title="Fierce Tango Fridays",
         details="Weekly fierce tango lessons at the Dance Spot",
         repeat=Recurrence(dtstart=dt.date(2018, 3, 30),
                           until=dt.date(2018, 8, 31),
                           freq=WEEKLY,
                           byweekday=[FR]),
         time_from=dt.time(19, 30),
         time_to=dt.time(22, 0),
         tz=pytz.timezone("US/Eastern"),
         website="http://torontodancespot.com/",
         location="622 Bloor St. W., Toronto ON, M6G 1K7",
         uid="*****@*****.**")
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     GROUPS = PageViewRestriction.GROUPS
     self.group = Group.objects.create(name="Friday Class")
     info = ExtraInfoPage(owner=self.user,
                          slug="2018-08-31-extra-info",
                          title="Extra-Info for Friday 31st of August",
                          overrides=event,
                          except_date=dt.date(2018, 8, 31),
                          extra_title="Surprise",
                          extra_information="Surprise party")
     event.add_child(instance=info)
     info.save_revision().publish()
     restriction = PageViewRestriction.objects.create(
         restriction_type=GROUPS, page=info)
     restriction.groups.set([self.group])
     restriction.save()
Example #16
0
 def testPostponement(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()
     post = PostponementPage(owner=self.user,
                             slug="2017-06-13-postponement",
                             title="Postponement for Tuesday 13th of June",
                             postponement_title="Code for Boston (on Weds)",
                             overrides=page,
                             except_date=dt.date(2017, 6, 13),
                             date=dt.date(2017, 6, 14))
     page.add_child(instance=post)
     post.save_revision().publish()
     vev = VEventFactory().makeFromPage(page)
     self.assertIs(type(vev), RecurringVEvent)
     self.assertEqual(len(vev.vchildren), 1)
     vchild = vev.vchildren[0]
     vchild.set('UID', "this-is-not-a-unique-identifier")
     self.assertIs(type(vchild), PostponementVEvent)
     talk = b"\r\n".join([
         b"BEGIN:VEVENT", b"SUMMARY:Code for Boston (on Weds)",
         b"DTSTART;TZID=US/Eastern:20170614T000000",
         b"DTEND;TZID=US/Eastern:20170614T235959",
         b"DTSTAMP:20170515T000000Z",
         b"UID:this-is-not-a-unique-identifier",
         b"RECURRENCE-ID;TZID=US/Eastern:20170613T190000", b"SEQUENCE:1",
         b"CREATED:20170515T000000Z", b"DESCRIPTION:",
         b"LAST-MODIFIED:20170515T000000Z", b"LOCATION:",
         b"URL:http://joy.test/events/code-for-boston/2017-06-13-postponement/",
         b"END:VEVENT", b""
     ])
     self.assertEqual(vchild.to_ical(), talk)
Example #17
0
 def setUp(self):
     self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
     home = getPage("/home/")
     chess = GroupPage(slug="chess-club", title="Chess Club")
     home.add_child(instance=chess)
     chess.save_revision().publish()
     event = RecurringEventPage(owner=self.user,
                                slug="lunchtime-matches",
                                title="Lunchtime Chess Matches",
                                repeat=Recurrence(dtstart=dt.date(
                                    1984, 8, 5),
                                                  freq=WEEKLY,
                                                  byweekday=[MO, WE, FR]),
                                time_from=dt.time(12),
                                time_to=dt.time(13))
     chess.add_child(instance=event)
     event.save_revision().publish()
     self.request = RequestFactory().get("/test")
     self.request.user = self.user
     self.request.session = {}
     self.request.site = Site.objects.get(is_default_site=True)
Example #18
0
class TestConcealedPanel(TestCase):
    def setUp(self):
        self.home = getPage("/home/")
        self.user = User.objects.create_superuser('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="leaders-meeting",
                                        title="Leaders' Meeting",
                                        repeat=Recurrence(dtstart=dt.date(
                                            2016, 2, 16),
                                                          freq=MONTHLY,
                                                          byweekday=[TU(3)]),
                                        time_from=dt.time(19),
                                        tz="Asia/Tokyo")
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()

    def _getRequest(self):
        request = RequestFactory().get("/test")
        request.user = self.user
        request.session = {}
        request.site = Site.objects.get(is_default_site=True)
        return request

    def testInit(self):
        panel = ConcealedPanel([], "Test", help_text="Nothing")
        self.assertEqual(panel._heading, "Test")
        self.assertEqual(panel._help_text, "Nothing")
        self.assertEqual(panel.heading, "")
        self.assertEqual(panel.help_text, "")

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testConcealed25(self):
        panel = ConcealedPanel([], "Test")
        panel = panel.bind_to(instance=self.event)
        panel = panel.bind_to(request=self._getRequest())
        content = panel.render()
        self.assertEqual(content, "")
        self.assertEqual(panel.heading, "")
        self.assertEqual(panel.help_text, "")

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testShown25(self):
        class ShownPanel(ConcealedPanel):
            def _show(self):
                return True

        panel = ShownPanel([], "Test", help_text="Nothing")
        panel = panel.bind_to(instance=self.event)
        self.assertEqual(panel.heading, "")
        self.assertEqual(panel.help_text, "")
        panel = panel.bind_to(request=self._getRequest())
        content = panel.render()
        self.assertHTMLEqual(
            content, """
<fieldset>
    <legend>Test</legend>
    <ul class="fields">
    </ul>
</fieldset>
""")
        self.assertEqual(panel.heading, "Test")
        self.assertEqual(panel.help_text, "Nothing")
Example #19
0
 def _setUpMainSite(self):
     Site.objects.filter(is_default_site=True).update(hostname="joy.test")
     home = getPage("/home/")
     events = CalendarPage(owner=self.user, slug="events", title="Events")
     home.add_child(instance=events)
     events.save_revision().publish()
     chess = GroupPage(slug="chess-club", title="Chess Club")
     home.add_child(instance=chess)
     chess.save_revision().publish()
     event = RecurringEventPage(owner=self.user,
                                slug="lunchtime-matches",
                                title="Lunchtime Chess Matches",
                                repeat=Recurrence(dtstart=dt.date(
                                    1984, 8, 5),
                                                  freq=WEEKLY,
                                                  byweekday=[MO, WE, FR]),
                                time_from=dt.time(12),
                                time_to=dt.time(13))
     chess.add_child(instance=event)
     event.save_revision().publish()
     cancellation = CancellationPage(
         owner=self.user,
         slug="1984-10-01-cancellation",
         title="Cancellation for Monday 1st of October",
         overrides=event,
         except_date=dt.date(1984, 10, 1),
         cancellation_title="No Chess Club Today")
     event.add_child(instance=cancellation)
     cancellation.save_revision().publish()
     postponement = PostponementPage(
         owner=self.user,
         slug="1984-10-03-postponement",
         title="Postponement for Wednesday 3rd of October",
         overrides=event,
         except_date=dt.date(1984, 10, 3),
         cancellation_title="",
         postponement_title="Early Morning Matches",
         date=dt.date(1984, 10, 4),
         time_from=dt.time(7, 30),
         time_to=dt.time(8, 30))
     event.add_child(instance=postponement)
     postponement.save_revision().publish()
     event = RecurringEventPage(owner=self.user,
                                slug="flea-market",
                                title="Flea Market",
                                repeat=Recurrence(dtstart=dt.date(
                                    1984, 7, 1),
                                                  freq=YEARLY,
                                                  byweekday=[SA(1),
                                                             SA(3)],
                                                  bymonth=range(2, 12)),
                                time_from=dt.time(8),
                                time_to=dt.time(13))
     events.add_child(instance=event)
     event.save_revision().publish()
     event = RecurringEventPage(owner=self.user,
                                slug="drama-practice",
                                title="Drama Group",
                                repeat=Recurrence(dtstart=dt.date(
                                    1984, 8, 14),
                                                  freq=WEEKLY,
                                                  byweekday=[TH],
                                                  interval=2),
                                time_from=dt.time(17))
     events.add_child(instance=event)
     event.save_revision().publish()
     event = SimpleEventPage(owner=self.user,
                             slug="public-lecture3",
                             title="The Human Environment",
                             date=dt.date(1984, 9, 14),
                             time_from=dt.time(19),
                             location="Lecture Hall C")
     events.add_child(instance=event)
     event.save_revision().publish()
Example #20
0
class TestTZ(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     title = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(owner = self.user,
                                        slug  = "code-for-boston",
                                        title = "Code for Boston",
                                        repeat    = Recurrence(dtstart=dt.date(2017,1,1),
                                                               freq=WEEKLY,
                                                               byweekday=[TU]),
                                        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=self.event)
        self.event.save_revision().publish()

    def testGetEventsByLocalDay(self):
        events = RecurringEventPage.events.byDay(dt.date(2018,4,1),
                                                 dt.date(2018,4,30))
        self.assertEqual(len(events), 30)
        evod1 = events[3]
        self.assertEqual(evod1.date, dt.date(2018,4,4))
        self.assertEqual(len(evod1.days_events), 1)
        self.assertEqual(len(evod1.continuing_events), 0)

    @freeze_timetz("2017-05-31")
    def testLocalWhen(self):
        with timezone.override("America/Los_Angeles"):
            self.assertEqual(self.event.when,
                             "Tuesdays at 4pm to 6:30pm")
        with timezone.override("Australia/Perth"):
            self.assertEqual(self.event.when,
                             "Wednesdays at 7am to 9:30am")

    @timezone.override("America/Los_Angeles")
    def testLocalAt(self):
        self.assertEqual(self.event.at, "4pm")

    @timezone.override("America/Los_Angeles")
    def testCurrentLocalDt(self):
        when = self.event._current_datetime_from
        self.assertEqual(when.tzinfo.zone, "America/Los_Angeles")
        self.assertEqual(when.weekday(), calendar.TUESDAY)

    @timezone.override("America/Los_Angeles")
    def testFutureLocalDt(self):
        when = self.event._future_datetime_from
        self.assertEqual(when.tzinfo.zone, "America/Los_Angeles")
        self.assertEqual(when.weekday(), calendar.TUESDAY)

    @timezone.override("Pacific/Auckland")
    def testPastLocalDt(self):
        when = self.event._past_datetime_from
        self.assertEqual(when.tzinfo.zone, "Pacific/Auckland")
        self.assertEqual(when.weekday(), calendar.WEDNESDAY)

    @timezone.override("Pacific/Kiritimati")
    def testExtremeTimeZones(self):
        lions = RecurringEventPage(owner = self.user,
                                   slug  = "pago-pago-lions",
                                   title = "Pago Pago Lions Club",
                                   repeat = Recurrence(dtstart=dt.date(2015,2,1),
                                                       freq=MONTHLY,
                                                       byweekday=[TH(1),TH(3)]),
                                   time_from = dt.time(23,0),
                                   tz = pytz.timezone("Pacific/Pago_Pago"),
                                   location = "Lions Den, Tafuna, PagoPago",
                                   website = "http://www.lionsclubs.org.nz")
        self.calendar.add_child(instance=lions)
        self.assertEqual(lions.when,
                         "The Saturday after the first Thursday and "
                         "Saturday after the third Thursday of the month at 12am")
Example #21
0
class TestFeed(TestCase):
    @freeze_time("2016-03-24")
    def setUp(self):
        imgFile = get_test_image_file()
        imgFile.name = "logo.png"
        self.img = Image.objects.create(title="Logo", file=imgFile)
        imgName = os.path.splitext(os.path.basename(self.img.file.name))[0]
        self.rendName = "{}.width-350.format-png.png".format(imgName)
        Site.objects.update(hostname="joy.test")
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(R3t')
        self.requestFactory = RequestFactory()
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     title = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(owner = self.user,
                                        slug  = "workshop",
                                        title = "Workshop",
                                        image = self.img,
                                        repeat    = Recurrence(dtstart=dt.date(2017,1,1),
                                                               freq=MONTHLY,
                                                               byweekday=[TU(1)],
                                                               until=dt.date(2017,12,26)))
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()
        self.handler = RssHandler()

    def tearDown(self):
        self.img.file.delete(False)
        for rend in self.img.renditions.all():
            rend.file.delete(False)

    def _getRequest(self, path="/"):
        request = self.requestFactory.get(path)
        request.user = self.user
        request.site = self.home.get_site()
        request.session = {}
        request._messages = FallbackStorage(request)
        request.POST = request.POST.copy()
        request.POST['action-publish'] = "action-publish"
        return request

    @freeze_time("2016-12-02")
    def testServe(self):
        response = self.handler.serve(self.calendar,
                                      self._getRequest("/events/"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Type'), "application/xml; charset=utf-8")
        self.assertIn(b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>', response.content)
        soup = BeautifulSoup(response.content, "xml")
        channel = soup.channel
        self.assertEqual(channel.title.string, "Events")
        self.assertEqual(channel.description.string, "Events")
        self.assertEqual(channel.link.string, "http://joy.test/events/")
        self.assertEqual(channel.generator.string, "ls.joyous")
        self.assertEqual(len(channel("image")), 1)
        image = channel.image
        self.assertEqual(image.url.string, "http://joy.test/static/joyous/img/logo.png")
        self.assertEqual(image.title.string, "Events")
        self.assertEqual(image.link.string, "http://joy.test/events/")
        self.assertEqual(channel.lastBuildDate.string, "Fri, 02 Dec 2016 00:00:00 +0000")
        self.assertEqual(len(channel("item")), 1)
        item = channel.item
        self.assertEqual(item.title.string, "Workshop")
        self.assertEqual(item.link.string, "http://joy.test/events/workshop/")
        self.assertEqual(item.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(self.rendName))
        self.assertEqual(item.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    The first Tuesday of the month (until 26 December 2017)
  &lt;/div&gt;\n
  &lt;div class="joy-ev-next-on joy-field"&gt;
    Next on Tuesday 3rd of January 2017 
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;&lt;/div&gt;\n</description>""")
        self.assertEqual(item.guid.get("isPermaLink"), "true")
        self.assertEqual(item.guid.string, "http://joy.test/events/workshop/")
        self.assertEqual(item.pubDate.string, "Thu, 24 Mar 2016 00:00:00 +0000")

    def testServeUnsupported(self):
        response = self.handler.serve(self.event,
                                      self._getRequest("/events/workshop"))
        self.assertIsNone(response)

    @freeze_time("2016-03-25")
    def testServeExtraInfo(self):
        info = ExtraInfoPage(owner = self.user,
                             overrides = self.event,
                             except_date = dt.date(2017,2,7),
                             extra_title = "System Demo",
                             extra_information = "<h3>System Demo</h3>")
        self.event.add_child(instance=info)
        info.save_revision().publish()
        response = self.handler.serve(self.calendar,
                                      self._getRequest("/events/"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Type'), "application/xml; charset=utf-8")
        soup = BeautifulSoup(response.content, "xml")
        channel = soup.channel
        self.assertEqual(channel.title.string, "Events")
        self.assertEqual(len(channel("item")), 2)
        item = channel("item")[1]
        self.assertEqual(item.title.string, "System Demo")
        self.assertEqual(item.link.string, "http://joy.test/events/workshop/2017-02-07-extra-info/")
        self.assertEqual(item.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(self.rendName))
        self.assertEqual(item.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    Tuesday 7th of February 2017
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;&lt;h3&gt;System Demo&lt;/h3&gt;&lt;/div&gt;
&lt;div class="rich-text"&gt;&lt;/div&gt;\n</description>""")
        self.assertEqual(item.guid.get("isPermaLink"), "true")
        self.assertEqual(item.guid.string, "http://joy.test/events/workshop/2017-02-07-extra-info/")
        self.assertEqual(item.pubDate.string, "Fri, 25 Mar 2016 00:00:00 +0000")

    @freeze_time("2016-03-26")
    def testServePostponement(self):
        imgFile = get_test_image_file(filename="logo2.png", colour="red")
        newLogo = Image.objects.create(title="Logo", file=imgFile)
        imgName = os.path.splitext(os.path.basename(newLogo.file.name))[0]
        newLogoRender = "{}.width-350.format-png.png".format(imgName)
        postponement = PostponementPage(owner = self.user,
                                        overrides = self.event,
                                        except_date = dt.date(2017,4,4),
                                        image = newLogo,
                                        cancellation_title   = "Workshop Postponed",
                                        cancellation_details = "Workshop will take place next week",
                                        postponement_title   = "Workshop",
                                        date      = dt.date(2017, 4, 11),
                                        details   = "Interesting stuff")
        self.event.add_child(instance=postponement)
        postponement.save_revision().publish()
        response = self.handler.serve(self.calendar,
                                      self._getRequest("/events/"))
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, "xml")
        channel = soup.channel
        self.assertEqual(channel.title.string, "Events")
        self.assertEqual(len(channel("item")), 3)
        item1 = channel("item")[1]
        self.assertEqual(item1.title.string, "Workshop Postponed")
        self.assertEqual(item1.link.string, "http://joy.test/events/workshop/2017-04-04-postponement/from/")
        self.assertEqual(item1.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(self.rendName))
        self.assertEqual(item1.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    Tuesday 4th of April 2017
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;Workshop will take place next week&lt;/div&gt;\n</description>""")
        self.assertEqual(item1.guid.get("isPermaLink"), "true")
        self.assertEqual(item1.guid.string, "http://joy.test/events/workshop/2017-04-04-postponement/from/")
        self.assertEqual(item1.pubDate.string, "Sat, 26 Mar 2016 00:00:00 +0000")
        item2 = channel("item")[2]
        self.assertEqual(item2.title.string, "Workshop")
        self.assertEqual(item2.link.string, "http://joy.test/events/workshop/2017-04-04-postponement/")
        self.assertEqual(item2.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(newLogoRender))
        self.assertEqual(item2.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    Tuesday 11th of April 2017
  &lt;/div&gt;\n
  &lt;div class="joy-ev-from-when joy-field"&gt;
    Postponed from Tuesday 4th of April 2017
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;Interesting stuff&lt;/div&gt;\n</description>""")
        self.assertEqual(item2.guid.get("isPermaLink"), "true")
        self.assertEqual(item2.guid.string, "http://joy.test/events/workshop/2017-04-04-postponement/")
        self.assertEqual(item2.pubDate.string, "Sat, 26 Mar 2016 00:00:00 +0000")

    @freeze_time("2016-03-27")
    def testServeCancellation(self):
        cancellation = CancellationPage(owner = self.user,
                                        overrides = self.event,
                                        except_date = dt.date(2017,5,2),
                                        cancellation_title   = "Workshop Cancelled",
                                        cancellation_details = "No workshop this month")
        self.event.add_child(instance=cancellation)
        cancellation.save_revision().publish()
        response = self.handler.serve(self.calendar,
                                      self._getRequest("/events/"))
        self.assertEqual(response.status_code, 200)
        soup = BeautifulSoup(response.content, "xml")
        channel = soup.channel
        self.assertEqual(channel.title.string, "Events")
        self.assertEqual(len(channel("item")), 2)
        item = channel("item")[1]
        self.assertEqual(item.title.string, "Workshop Cancelled")
        self.assertEqual(item.link.string, "http://joy.test/events/workshop/2017-05-02-cancellation/")
        self.assertEqual(item.enclosure.decode(),
                         '<enclosure length="773" type="image/png" '
                         'url="http://joy.test/media/images/{}"/>'.format(self.rendName))
        self.assertEqual(item.description.decode(), """<description>\n\n\n
  &lt;div class="joy-ev-when joy-field"&gt;
    Tuesday 2nd of May 2017
  &lt;/div&gt;\n\n\n\n
&lt;div class="rich-text"&gt;No workshop this month&lt;/div&gt;\n</description>""")
        self.assertEqual(item.guid.get("isPermaLink"), "true")
        self.assertEqual(item.guid.string, "http://joy.test/events/workshop/2017-05-02-cancellation/")
        self.assertEqual(item.pubDate.string, "Sun, 27 Mar 2016 00:00:00 +0000")
Example #22
0
class TestNoCalendar(TestCase):
    @freeze_timetz("2012-08-01 13:00")
    def setUp(self):
        self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
        home = getPage("/home/")
        chess = GroupPage(slug="chess-club", title="Chess Club")
        home.add_child(instance=chess)
        chess.save_revision().publish()
        self.event = RecurringEventPage(owner=self.user,
                                        slug="chess",
                                        title="Chess Matches",
                                        repeat=Recurrence(
                                            dtstart=dt.date(2012, 8, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(12),
                                        time_to=dt.time(13))
        chess.add_child(instance=self.event)
        self.event.save_revision().publish()
        self.request = RequestFactory().get("/test")
        self.request.user = self.user
        self.request.session = {}
        self.request.site = Site.objects.get(is_default_site=True)

    @freeze_timetz("2019-12-01 9:00")
    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)

    def testNotInitializedLoad(self):
        data = b"\r\n".join([
            b"BEGIN:VCALENDAR",
            b"VERSION:2.0",
            b"PRODID:-//Bloor &amp; Spadina - ECPv4.6.13//NONSGML v1.0//EN",
            b"CALSCALE:GREGORIAN",
            b"METHOD:PUBLISH",
            b"X-WR-CALNAME:Bloor &amp; Spadina",
            b"X-ORIGINAL-URL:http://bloorneighbours.ca",
            b"X-WR-CALDESC:Events for Bloor &amp; 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)
Example #23
0
class TestExceptionDatePanel(TestCase):
    def setUp(self):
        self.home = getPage("/home/")
        self.user = User.objects.create_superuser('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="leaders-meeting",
                                        title="Leaders' Meeting",
                                        repeat=Recurrence(dtstart=dt.date(
                                            2016, 2, 16),
                                                          freq=MONTHLY,
                                                          byweekday=[TU(3)]),
                                        time_from=dt.time(19),
                                        tz="Asia/Tokyo")
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()

    def _getRequest(self):
        request = RequestFactory().get("/test")
        request.user = self.user
        request.session = {}
        request.site = Site.objects.get(is_default_site=True)
        return request

    def testWidget(self):
        self.assertIs(ExceptionDatePanel.widget, ExceptionDateInput)

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testBindWithoutForm25(self):
        cancellation = CancellationPage(owner=self.user,
                                        except_date=dt.date(2019, 1, 21))
        panel = ExceptionDatePanel('except_date', classname='full-width')
        panel = panel.bind_to(instance=cancellation)
        self.assertIsNone(panel.form)

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testBindWithoutOverrides25(self):
        cancellation = CancellationPage(owner=self.user,
                                        except_date=dt.date(2019, 1, 21))
        Form = get_form_for_model(CancellationPage,
                                  form_class=CancellationPageForm)
        form = Form(instance=cancellation, parent_page=self.event)
        panel = ExceptionDatePanel('except_date', classname='full-width')
        panel = panel.bind_to(instance=cancellation)
        panel = panel.bind_to(request=self._getRequest())
        panel = panel.bind_to(form=form)
        self.assertIsNotNone(panel.form)
        self.assertIsNone(panel.instance.overrides)

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testBindOverridesRepeat25(self):
        cancellation = CancellationPage(owner=self.user,
                                        overrides=self.event,
                                        except_date=dt.date(2019, 1, 21))
        Form = get_form_for_model(CancellationPage,
                                  form_class=CancellationPageForm)
        form = Form(instance=cancellation, parent_page=self.event)
        widget = form['except_date'].field.widget
        panel = ExceptionDatePanel('except_date', classname='full-width')
        panel = panel.bind_to(instance=cancellation)
        panel = panel.bind_to(request=self._getRequest())
        panel = panel.bind_to(form=form)
        self.assertIs(widget.overrides_repeat, self.event.repeat)
        self.assertIsNone(panel.exceptionTZ)

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    @timezone.override("America/Los_Angeles")
    def testBindExceptionTZ25(self):
        cancellation = CancellationPage(owner=self.user,
                                        overrides=self.event,
                                        except_date=dt.date(2019, 1, 21))
        Form = get_form_for_model(CancellationPage,
                                  form_class=CancellationPageForm)
        form = Form(instance=cancellation, parent_page=self.event)
        panel = ExceptionDatePanel('except_date', classname='full-width')
        panel = panel.bind_to(instance=cancellation)
        panel = panel.bind_to(request=self._getRequest())
        panel = panel.bind_to(form=form)
        self.assertEqual(panel.exceptionTZ, "Asia/Tokyo")
Example #24
0
class TestHiddenNumDaysPanel(TestCase):
    FIELD_CONTENT = """
<fieldset>
  <legend>Number of days</legend>
  <ul class="fields">
    <li>
      <div class="field integer_field number_input ">
        <div class="field-content">
          <div class="input  ">
            <input type="number" name="num_days" value="1" required id="id_num_days">
            <span></span>
          </div>
        </div>
      </div>
    </li>
  </ul>
</fieldset>
"""

    def setUp(self):
        self.home = getPage("/home/")
        self.user = User.objects.create_superuser('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="leaders-meeting",
                                        title="Leaders' Meeting",
                                        repeat=Recurrence(dtstart=dt.date(
                                            2016, 2, 16),
                                                          freq=MONTHLY,
                                                          byweekday=[TU(3)]),
                                        time_from=dt.time(19),
                                        tz="Asia/Tokyo")
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()
        Form = get_form_for_model(RecurringEventPage,
                                  form_class=RecurringEventPageForm)
        self.form = Form(instance=self.event, parent_page=self.calendar)

    def _getRequest(self):
        request = RequestFactory().get("/test")
        request.user = self.user
        request.session = {}
        request.site = Site.objects.get(is_default_site=True)
        return request

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testHidden25(self):
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=self.event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertEqual(content, "")
        content = panel.render_as_field()
        self.assertEqual(content, "")

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testShowWith2Days25(self):
        self.event.num_days = 2
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=self.event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertHTMLEqual(content, self.FIELD_CONTENT)

    @skipUnless(WagtailVersion >= (2, 5, 0), "Wagtail <2.5")
    def testShowMulidayRecurringEvent25(self):
        event = MultidayRecurringEventPage(slug="leaders-retreat",
                                           title="Leaders' Retreet",
                                           repeat=Recurrence(
                                               dtstart=dt.date(2016, 2, 16),
                                               freq=YEARLY,
                                               bymonth=3,
                                               byweekday=[FR(1)]),
                                           time_from=dt.time(19),
                                           num_days=3,
                                           tz="Asia/Tokyo")
        self.calendar.add_child(instance=event)
        event.save_revision().publish()
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertHTMLEqual(content, self.FIELD_CONTENT)
Example #25
0
class Test(TestCase):
    def setUp(self):
        Site.objects.update(hostname="joy.test")
        self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     title = "Events")
        Page.objects.get(slug='home').add_child(instance=self.calendar)
        self.calendar.save()
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(owner = self.user,
                                        slug  = "lug-meetup",
                                        title = "Linux Users Group Meetup",
                                        repeat = Recurrence(dtstart=dt.date(2017,8,5),
                                                            freq=MONTHLY,
                                                            byweekday=[TU(1)]),
                                        time_from = dt.time(18,30),
                                        time_to   = dt.time(20),
                                        location  = "6 Mackay St, Greymouth (upstairs)")
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()

    def testGetEventsByDay(self):
        events = RecurringEventPage.events.byDay(dt.date(2017,8,1),
                                                 dt.date(2017,10,31))
        self.assertEqual(len(events), 92)
        evod = events[35]
        self.assertEqual(evod.date, dt.date(2017,9,5))
        self.assertEqual(len(evod.all_events), 1)
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)

    def testStatus(self):
        pastEvent = RecurringEventPage(owner = self.user,
                                       slug  = "past",
                                       title = "Past Event",
                                       repeat = Recurrence(dtstart=dt.date(2008,2,1),
                                                           until=dt.date(2008,5,4),
                                                           freq=WEEKLY,
                                                           byweekday=[SA,SU]))
        self.calendar.add_child(instance=pastEvent)
        self.assertEqual(pastEvent.status, "finished")
        self.assertEqual(pastEvent.status_text, "These events have finished.")
        now = timezone.localtime()
        earlier = now - dt.timedelta(hours=1)
        if earlier.date() != now.date():
            earlier = datetimetz(now.date(), dt.time.min)
        nowEvent = RecurringEventPage(owner = self.user,
                                      slug  = "now",
                                      title = "Now Event",
                                      repeat = Recurrence(dtstart=dt.date(2010,1,1),
                                                          freq=DAILY),
                                      time_from = earlier.time(),
                                      time_to   = dt.time.max)
        self.calendar.add_child(instance=nowEvent)
        self.assertEqual(nowEvent.status, "started")
        self.assertEqual(nowEvent.status_text, "This event has started.")
        today = timezone.localdate()
        notToday = [weekday for weekday in EVERYWEEKDAY if weekday.weekday != today.weekday()]
        pastAndFutureEvent = RecurringEventPage(owner = self.user,
                                                slug  = "not-today",
                                                title = "Any day but today",
                                                repeat = Recurrence(dtstart=dt.date(2009,8,7),
                                                                    freq=WEEKLY,
                                                                    byweekday=notToday))
        self.calendar.add_child(instance=pastAndFutureEvent)
        self.assertIsNone(pastAndFutureEvent.status)
        self.assertEqual(pastAndFutureEvent.status_text, "")

    @freeze_timetz("2008-05-04 09:01")
    def testJustFinishedStatus(self):
        event = RecurringEventPage(owner = self.user,
                                   slug  = "breakfast1",
                                   title = "Breakfast-in-bed",
                                   repeat = Recurrence(dtstart=dt.date(2008,2,1),
                                                       until=dt.date(2008,5,9),
                                                       freq=WEEKLY,
                                                       byweekday=[SA,SU]),
                                      time_from = dt.time(8),
                                      time_to   = dt.time(9))
        self.calendar.add_child(instance=event)
        self.assertEqual(event.status, "finished")

    @freeze_timetz("2008-05-04 07:00")
    def testLastOccurenceCancelledStatus(self):
        event = RecurringEventPage(owner = self.user,
                                   slug  = "breakfast2",
                                   title = "Breakfast-in-bed",
                                   repeat = Recurrence(dtstart=dt.date(2008,2,1),
                                                       until=dt.date(2008,5,9),
                                                       freq=WEEKLY,
                                                       byweekday=[SA,SU]),
                                   time_from = dt.time(8),
                                   time_to   = dt.time(9))
        self.calendar.add_child(instance=event)
        cancellation = CancellationPage(owner = self.user,
                                        overrides = event,
                                        except_date = dt.date(2008, 5, 4),
                                        cancellation_title   = "Fire in the kitchen",
                                        cancellation_details = "The bacon fat is burning")
        event.add_child(instance=cancellation)
        self.assertEqual(event.status, "finished")

    @freeze_timetz("2008-05-04 12:00")
    def testPostponementOccurenceLast(self):
        request = RequestFactory().get("/test")
        request.user = self.user
        request.session = {}
        event = RecurringEventPage(owner = self.user,
                                   slug  = "breakfast3",
                                   title = "Breakfast-in-bed",
                                   repeat = Recurrence(dtstart=dt.date(2008,2,1),
                                                       until=dt.date(2008,5,9),
                                                       freq=WEEKLY,
                                                       byweekday=[SA,SU]),
                                   time_from = dt.time(8),
                                   time_to   = dt.time(9))
        self.calendar.add_child(instance=event)
        postponement = PostponementPage(owner = self.user,
                                        overrides = event,
                                        except_date = dt.date(2008, 5, 3),
                                        postponement_title = "Breakfast in Bed owed from May",
                                        date      = dt.date(2008, 5, 24),
                                        time_from = dt.time(8),
                                        time_to   = dt.time(9))
        event.add_child(instance=postponement)
        self.assertIsNone(event.status)
        self.assertEqual(event._nextOn(request),
                         '<a class="inline-link" href="/events/breakfast3/2008-05-03-postponement/">Saturday 24th of May at 8am</a>')

    def testWhen(self):
        self.assertEqual(self.event.when, "The first Tuesday of the month at 6:30pm to 8pm")

    def testAt(self):
        self.assertEqual(self.event.at.strip(), "6:30pm")

    def testCurrentDt(self):
        lugDt = self.event._current_datetime_from
        self.assertEqual(lugDt.time(), dt.time(18,30))
        self.assertEqual(lugDt.date().weekday(), 1)
        self.assertLess(lugDt.date().day, 8)
        movieNight = RecurringEventPage(owner = self.user,
                                        slug  = "movies",
                                        title = "Movies",
                                        repeat = Recurrence(dtstart=dt.date(2005,2,1),
                                                            freq=WEEKLY,
                                                            byweekday=[TH,]),
                                        time_from = dt.time(20,15),
                                        time_to   = dt.time(21,30))
        self.calendar.add_child(instance=movieNight)
        now = timezone.localtime()
        myday = now.date()
        startTime = dt.time(20,15)
        if now.time() > startTime:
            myday += dt.timedelta(days=1)
        thursday = myday + dt.timedelta(days=(3-myday.weekday())%7)
        self.assertEqual(movieNight._current_datetime_from,
                         datetimetz(thursday, startTime))

    def testFutureDt(self):
        lugDt = self.event._future_datetime_from
        self.assertEqual(lugDt.time(), dt.time(18,30))
        self.assertEqual(lugDt.date().weekday(), 1)
        self.assertLess(lugDt.date().day, 8)
        movieNight = RecurringEventPage(owner = self.user,
                                        slug  = "movies",
                                        title = "Movies",
                                        repeat = Recurrence(dtstart=dt.date(2005,2,1),
                                                            freq=WEEKLY,
                                                            byweekday=[TH,]),
                                        time_from = dt.time(20,15),
                                        time_to   = dt.time(21,30))
        self.calendar.add_child(instance=movieNight)
        now = timezone.localtime()
        myday = now.date()
        startTime = dt.time(20,15)
        if now.time() > startTime:
            myday += dt.timedelta(days=1)
        thursday = myday + dt.timedelta(days=(3-myday.weekday())%7)
        self.assertEqual(movieNight._future_datetime_from,
                         datetimetz(thursday, startTime))

    def testPastDt(self):
        lugDt = self.event._past_datetime_from
        self.assertEqual(lugDt.time(), dt.time(18,30))
        self.assertEqual(lugDt.date().weekday(), 1)
        self.assertLess(lugDt.date().day, 8)
        movieNight = RecurringEventPage(owner = self.user,
                                        slug  = "movies",
                                        title = "Movies",
                                        repeat = Recurrence(dtstart=dt.date(2005,2,1),
                                                            freq=WEEKLY,
                                                            byweekday=[TH,]),
                                        time_from = dt.time(20,15),
                                        time_to   = dt.time(21,30))
        self.calendar.add_child(instance=movieNight)
        now = timezone.localtime()
        myday = now.date()
        startTime = dt.time(20,15)
        if now.time() < startTime:
            myday -= dt.timedelta(days=1)
        thursday = myday - dt.timedelta(days=(myday.weekday()-3)%7)
        self.assertEqual(movieNight._past_datetime_from,
                         datetimetz(thursday, startTime))

    def testGroup(self):
        self.assertIsNone(self.event.group)

    def testOccursOn(self):
        self.assertIs(self.event._occursOn(dt.date(2018,3,6)), True)
        self.assertIs(self.event._occursOn(dt.date(2018,3,13)), False)
class TestHiddenNumDaysPanel(TestCase):
    FIELDSET_CONTENT = """
<fieldset>
  <legend>Number of days</legend>
  <ul class="fields">
    <li>
      <div class="field integer_field number_input ">
        <div class="field-content">
          <div class="input  ">
            <input type="number" name="num_days" value="1" required id="id_num_days">
            <span></span>
          </div>
        </div>
      </div>
    </li>
  </ul>
</fieldset>
"""
    COMMENT_CONTROL_CONTENT = """
<div class="field-comment-control field-comment-control--object">
  <button aria-label="Add comment" class="u-hidden" data-comment-add data-component="add-comment-button" type="button">
    <svg aria-hidden="true" class="icon icon-comment-add icon-default initial" focusable="false">
      <use href="#icon-comment-add">
    </svg>
    <svg aria-hidden="true" class="icon icon-comment-add icon-reversed initial" focusable="false">
      <use href="#icon-comment-add-reversed">
    </svg>
  </button>
</div>
"""

    def setUp(self):
        if WagtailVersion > (2, 13, 0):
            self.FIELD_CONTENT = """
<div data-contentpath="num_days">
    {}
    {}
</div>
""".format(self.FIELDSET_CONTENT, self.COMMENT_CONTROL_CONTENT)
        else:
            self.FIELD_CONTENT = self.FIELDSET_CONTENT
        self.maxDiff = None
        self.home = getPage("/home/")
        self.user = User.objects.create_superuser('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="events",
                                     title="Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="leaders-meeting",
                                        title="Leaders' Meeting",
                                        repeat=Recurrence(dtstart=dt.date(
                                            2016, 2, 16),
                                                          freq=MONTHLY,
                                                          byweekday=[TU(3)]),
                                        time_from=dt.time(19),
                                        tz="Asia/Tokyo")
        self.calendar.add_child(instance=self.event)
        self.event.save_revision().publish()
        Form = get_form_for_model(RecurringEventPage,
                                  form_class=RecurringEventPageForm)
        self.form = Form(instance=self.event, parent_page=self.calendar)

    def _getRequest(self):
        request = RequestFactory().get("/test")
        request.user = self.user
        request.session = {}
        request.site = Site.objects.get(is_default_site=True)
        return request

    def testHidden(self):
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=self.event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertEqual(content, "")
        content = panel.render_as_field()
        self.assertEqual(content, "")

    def testShowWith2Days(self):
        self.event.num_days = 2
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=self.event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertHTMLEqual(content, self.FIELD_CONTENT)

    def testShowMulidayRecurringEvent(self):
        event = MultidayRecurringEventPage(slug="leaders-retreat",
                                           title="Leaders' Retreet",
                                           repeat=Recurrence(
                                               dtstart=dt.date(2016, 2, 16),
                                               freq=YEARLY,
                                               bymonth=3,
                                               byweekday=[FR(1)]),
                                           time_from=dt.time(19),
                                           num_days=3,
                                           tz="Asia/Tokyo")
        self.calendar.add_child(instance=event)
        event.save_revision().publish()
        panel = HiddenNumDaysPanel()
        panel = panel.bind_to(instance=event,
                              request=self._getRequest(),
                              form=self.form)
        content = panel.render_as_object()
        self.assertHTMLEqual(content, self.FIELD_CONTENT)