Example #1
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")
 def testGetUpcomingEvents(self):
     event = RecurringEventPage(slug="lemon",
                                title="Lemonade Stand",
                                repeat=Recurrence(dtstart=dt.date(
                                    2021, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[FR]),
                                time_from=dt.time(11),
                                time_to=dt.time(13))
     self.calendar.add_child(instance=event)
     shutdown = ExtCancellationPage(owner=self.user,
                                    overrides=event,
                                    cancelled_from_date=dt.date(
                                        2021, 2, 13),
                                    cancellation_title="Gone fishing")
     event.add_child(instance=shutdown)
     shutdown.save_revision().publish()
     events = ExtCancellationPage.events.exclude(cancellation_title="")   \
                                   .upcoming().this()                     \
                                   .descendant_of(event)
     self.assertEqual(len(events), 1)
     title, page, url = events[0]
     self.assertEqual(title, "Gone fishing")
     self.assertEqual(page._future_datetime_from,
                      datetimetz(2021, 2, 19, 11, 0))
     self.assertEqual(url, "/events/lemon/2021-02-13--cancellation/")
Example #3
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 #4
0
 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>')
Example #5
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 #6
0
class TestTZ(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('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="test-meeting",
                                        title="Test Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(1989, 1, 1),
                                            freq=WEEKLY,
                                            byweekday=[MO, WE, FR]),
                                        time_from=dt.time(13, 30),
                                        time_to=dt.time(16),
                                        tz=pytz.timezone("US/Eastern"))
        self.calendar.add_child(instance=self.event)
        self.cancellation = CancellationPage(
            owner=self.user,
            overrides=self.event,
            except_date=dt.date(1989, 2, 1),
            cancellation_title="Meeting Cancelled",
            cancellation_details="Cancelled due to lack of interest")
        self.event.add_child(instance=self.cancellation)
        self.cancellation.save_revision().publish()

    @timezone.override("Australia/Sydney")
    @freeze_timetz("1989-02-02T06:00:00+11:00")
    def testCurrentLocalDt(self):
        when = self.cancellation._current_datetime_from
        self.assertEqual(when.tzinfo.zone, "Australia/Sydney")
        self.assertEqual(when.time(), dt.time(5, 30))
        self.assertEqual(when.date(), dt.date(1989, 2, 2))

    @timezone.override("Australia/Sydney")
    @freeze_timetz("1989-02-02T06:00:00+11:00")
    def testFutureLocalDt(self):
        when = self.cancellation._future_datetime_from
        self.assertIsNone(when)

    @timezone.override("Australia/Sydney")
    def testPastLocalDt(self):
        when = self.cancellation._past_datetime_from
        self.assertEqual(when.tzinfo.zone, "Australia/Sydney")
        self.assertEqual(when.time(), dt.time(5, 30))
        self.assertEqual(when.date(), dt.date(1989, 2, 2))

    @timezone.override("Australia/Sydney")
    @freeze_timetz("1989-10-01T21:00:00+11:00")
    def testCopyFieldsFromParent(self):
        self.assertEqual(self.event.next_date, dt.date(1989, 10, 3))
        cancellation = CancellationPage(owner=self.user)
        cancellation._copyFieldsFromParent(self.event)
        self.assertEqual(cancellation.overrides, self.event)
        self.assertEqual(cancellation.except_date, dt.date(1989, 10, 2))
Example #7
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)
class TestTZ(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('j', '*****@*****.**', 's3(r3t')
        self.calendar = GeneralCalendarPage(owner=self.user,
                                            slug="events",
                                            title="Events")
        self.home.add_child(instance=self.calendar)
        self.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),
                                        tz=pytz.timezone("US/Eastern"))
        self.calendar.add_child(instance=self.event)
        self.postponement = PostponementPage(
            owner=self.user,
            overrides=self.event,
            postponement_title="Delayed Meeting",
            except_date=dt.date(1990, 10, 10),
            date=dt.date(1990, 10, 11),
            time_from=dt.time(13),
            time_to=dt.time(16, 30))
        self.event.add_child(instance=self.postponement)
        self.postponement.save_revision().publish()

    @timezone.override("Pacific/Auckland")
    def testLocalTitle(self):
        self.assertEqual(self.postponement.title,
                         "Postponement for Wednesday 10th of October 1990")
        self.assertEqual(self.postponement.local_title,
                         "Postponement for Thursday 11th of October 1990")

    @timezone.override("Asia/Colombo")
    def testGetEventsByDay(self):
        events = PostponementPage.events.byDay(dt.date(1990, 10, 1),
                                               dt.date(1990, 10, 31))
        self.assertEqual(len(events), 31)
        evod0 = events[10]
        self.assertEqual(evod0.date, dt.date(1990, 10, 11))
        self.assertEqual(len(evod0.days_events), 1)
        self.assertEqual(len(evod0.continuing_events), 0)
        title, page, url = evod0.days_events[0]
        self.assertEqual(title, "Delayed Meeting")
        self.assertIs(type(page), PostponementPage)
        evod1 = events[11]
        self.assertEqual(evod1.date, dt.date(1990, 10, 12))
        self.assertEqual(len(evod1.days_events), 0)
        self.assertEqual(len(evod1.continuing_events), 1)
        title, page, url = evod1.continuing_events[0]
        self.assertEqual(title, "Delayed Meeting")
        self.assertIs(type(page), PostponementPage)
class TestPageForm(TestCase):
    Form = ExtCancellationPage.get_edit_handler().get_form_class()

    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('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="committee-meeting",
                                        title="Committee Meeting",
                                        repeat=Recurrence(
                                            dtstart=dt.date(2017, 1, 1),
                                            freq=MONTHLY,
                                            byweekday=[MO(1), MO(3)]),
                                        time_from=dt.time(13),
                                        time_to=dt.time(15, 30))
        self.calendar.add_child(instance=self.event)
        self.shutdown = ExtCancellationPage(
            owner=self.user,
            overrides=self.event,
            cancelled_from_date=dt.date(2020, 3, 2),
            cancelled_to_date=dt.date(2020, 3, 6))
        self.event.add_child(instance=self.shutdown)
        self.shutdown.save_revision().publish()

    def testValid(self):
        page = ExtCancellationPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'cancelled_from_date': "2020-03-10"
            },
            instance=page,
            parent_page=self.event)
        self.assertTrue(form.is_valid())  # is_valid() calls full_clean()
        self.assertDictEqual(form.errors, {})

    def testExceptionAlreadyExists(self):
        page = ExtCancellationPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'cancelled_from_date': "2020-03-02"
            },
            instance=page,
            parent_page=self.event)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors, {
                'cancelled_from_date':
                ['There is already an extended cancellation for then']
            })
Example #10
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 #11
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)
class TestPageFormDeutsche(TestCase):
    Form = ExtraInfoPage.get_edit_handler().get_form_class()

    def setUp(self):
        translation.activate('de')
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
        self.calendar = CalendarPage(owner=self.user,
                                     slug="ereignisse",
                                     title="Ereignisse")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug="meeting",
                                        title="Testen Sie 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=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1999, 1, 5),
                                  extra_title="Freitag",
                                  extra_information="Besonderer Freitag")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def tearDown(self):
        translation.deactivate()

    def testExceptionAlreadyExists(self):
        page = ExtraInfoPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'except_date': "1999-01-05",
                'extra_title': "Es ist Freitag",
                'extra_information': rich_text("Besonderer spezieller Freitag")
            },
            instance=page,
            parent_page=self.event)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors, {
                'except_date':
                ['Dieses Datum enthält bereits zusätzliche information']
            })
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 testWhenEver(self):
     event = RecurringEventPage(slug="XYZ",
                                title="Xylophone yacht zombies",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[FR]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     cancellation = CancellationPage(owner=self.user,
                                     overrides=event,
                                     except_date=dt.date(1989, 3, 10),
                                     cancellation_title="Cancelled")
     event.add_child(instance=cancellation)
     cancellation.save_revision().publish()
     self.assertEqual(cancellation.when, "Friday 10th of March 1989 at 7pm")
 def testWhenEver(self):
     event = RecurringEventPage(slug="OpQ",
                                title="Orangepurple Quagga",
                                repeat=Recurrence(dtstart=dt.date(
                                    2020, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[FR(-1)]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     shutdown = ExtCancellationPage(owner=self.user,
                                    overrides=event,
                                    cancelled_from_date=dt.date(2020, 4, 1))
     event.add_child(instance=shutdown)
     shutdown.save_revision().publish()
     self.assertEqual(
         shutdown.when,
         "Cancelled from Wednesday 1st of April until further notice")
Example #16
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 #17
0
 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")
Example #18
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()
 def testClosedOn(self):
     event = RecurringEventPage(slug="XYZ",
                                title="Xylophone yacht zombies",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[FR]),
                                time_from=dt.time(19),
                                holidays=self.calendar.holidays)
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False,
                                        cancellation_title="XYZ Cancelled")
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     self.assertEqual(closedHols._closedOn(dt.date(1989, 3, 24)), False)
     closedHols.holidays = self.calendar.holidays
     self.assertEqual(closedHols._closedOn(dt.date(1989, 3, 24)), False)
Example #20
0
class TestNoCalendar(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.request.site = Site.objects.get(is_default_site=True)
        self.group = GroupPage(slug = "initech", title = "Initech Corporation")
        self.home.add_child(instance=self.group)
        self.standup = RecurringEventPage(slug   = "test-meeting",
                                          title  = "Test Meeting",
                                          repeat = Recurrence(dtstart=dt.date(2013,1,1),
                                                              until=dt.date(2013,5,31),
                                                              freq=WEEKLY,
                                                              byweekday=[MO,WE,FR]),
                                          time_from = dt.time(13,30),
                                          time_to   = dt.time(16),
                                          uid       = "initiative+technology")
        self.group.add_child(instance=self.standup)
        self.postponement = PostponementPage(owner = self.user,
                                             slug  = "2013-01-09-postponement",
                                             title = "Postponement for Wednesday 16th of October",
                                             overrides = self.standup,
                                             except_date = dt.date(2013,1,16),
                                             cancellation_title   = "Meeting Postponed",
                                             cancellation_details =
                                                 "The meeting has been postponed until tomorrow",
                                             postponement_title   = "A Meeting",
                                             date      = dt.date(2013,1,17),
                                             time_from = dt.time(13),
                                             time_to   = dt.time(16,30),
                                             details   = "Yes a test meeting on a Thursday")
        self.standup.add_child(instance=self.postponement)

    def testGetAllEventsByDay(self):
        events = getAllEventsByDay(self.request, dt.date(2013,1,1), dt.date(2013,1,31))
        self.assertEqual(len(events), 31)
        evod2 = events[1]
        self.assertEqual(evod2.date, dt.date(2013,1,2))
        self.assertEqual(len(evod2.all_events), 1)
        self.assertEqual(len(evod2.continuing_events), 0)
        self.assertEqual(len(evod2.days_events), 1)
class TestPageForm(TestCase):
    Form = ExtraInfoPage.get_edit_handler().get_form_class()

    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('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="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=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1999, 1, 5),
                                  extra_title="Fri-day",
                                  extra_information="Special Friday")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testExceptionAlreadyExists(self):
        page = ExtraInfoPage(owner=self.user)
        form = self.Form(
            {
                'overrides': self.event,
                'except_date': "1999-01-05",
                'extra_title': "It's Friday",
                'extra_information': rich_text("Special Special Friday")
            },
            instance=page,
            parent_page=self.event)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors,
            {'except_date': ['That date already has extra information']})
Example #22
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)
 def testGetUpcomingEvents(self):
     event = RecurringEventPage(slug="RST",
                                title="Ruritania secret taxidermy",
                                repeat=Recurrence(dtstart=dt.date(
                                    1980, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(20))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(
         owner=self.user,
         overrides=event,
         all_holidays=False,
         cancellation_title="Closed for the holiday")
     closedHols.closed_for = [
         ClosedFor(name="Wellington Anniversary Day"),
         ClosedFor(name="Auckland Anniversary Day"),
         ClosedFor(name="Nelson Anniversary Day"),
         ClosedFor(name="Taranaki Anniversary Day"),
         ClosedFor(name="Otago Anniversary Day"),
         ClosedFor(name="Southland Anniversary Day"),
         ClosedFor(name="South Canterbury Anniversary Day"),
         ClosedFor(name="Hawke's Bay Anniversary Day"),
         ClosedFor(name="Marlborough Anniversary Day"),
         ClosedFor(name="Canterbury Anniversary Day"),
         ClosedFor(name="Chatham Islands Anniversary Day"),
         ClosedFor(name="Westland Anniversary Day")
     ]
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     events = ClosedForHolidaysPage.events.hols(self.calendar.holidays)   \
                                   .exclude(cancellation_title="")        \
                                   .upcoming().this().descendant_of(event)
     self.assertEqual(len(events), 1)
     title, page, url = events[0]
     self.assertEqual(title, "Closed for the holiday")
     self.assertEqual(page._future_datetime_from,
                      datetimetz(1990, 12, 3, 20, 0))
     self.assertEqual(url, "/events/RST/closed-for-holidays/")
 def testFarFutureDt(self):
     event = RecurringEventPage(slug="UVW",
                                title="Underwater viking wombats",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=MONTHLY,
                                                  bymonthday=23),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False)
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.holidays = self.calendar.holidays
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.closed_for = [ClosedFor(name="Good Friday")]
     # Good Friday falls on 2038-04-23 but that is too far to calculate
     self.assertEqual(closedHols._future_datetime_from,
                      datetimetz(9999, 12, 29, 19, 0))
 def testGetMyDates(self):
     event = RecurringEventPage(slug="UVW",
                                title="Underwater viking wombats",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False)
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.holidays = self.calendar.holidays
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.closed_for = [ClosedFor(name="Good Friday")]
     # Good Friday is never going to fall on a Monday
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
Example #26
0
 def testGetGroupUpcomingEvents(self):
     meeting = RecurringEventPage(owner = self.user,
                                  slug  = "plan-plan",
                                  title = "Planning to Plan",
                                  repeat    = Recurrence(dtstart=dt.date(2018,5,1),
                                                         freq=WEEKLY,
                                                         byweekday=[TU]),
                                  time_from = dt.time(18,30),
                                  time_to   = dt.time(20),
                                  group_page = self.group)
     self.calendar.add_child(instance=meeting)
     memo = ExtraInfoPage(owner = self.user,
                          slug  = "plan-plan-extra-info",
                          title = "Extra Information Planning to Plan",
                          overrides = meeting,
                          except_date = meeting.next_date,
                          extra_title = "Gap Analysis",
                          extra_information = "Analyse your gaps")
     meeting.add_child(instance=memo)
     events = getGroupUpcomingEvents(self.request, self.group)
     self.assertEqual(len(events), 2)
     self.assertEqual(events[0].title, "Gap Analysis")
     self.assertEqual(events[1].title, "Planning to Plan")
 def testWhenEver(self):
     event = RecurringEventPage(slug="XYZ",
                                title="Xylophone yacht zombies",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=WEEKLY,
                                                  byweekday=[FR]),
                                time_from=dt.time(19),
                                holidays=self.calendar.holidays)
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False,
                                        cancellation_title="XYZ Cancelled",
                                        holidays=self.calendar.holidays)
     closedHols.closed_for = [
         ClosedFor(name="Good Friday"),
         ClosedFor(name="Easter Monday")
     ]
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     self.assertEqual(closedHols.when,
                      "Closed on Good Friday and Easter Monday")
     self.assertIs(event._occursOn(dt.date(1989, 3, 24)), False)
 def testWombatGetEventsByDay(self):
     event = RecurringEventPage(slug="UVW",
                                title="Underwater viking wombats",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False,
                                        cancellation_title="UVW Cancelled")
     closedHols.closed_for = [
         ClosedFor(name="New Year's Day"),
         ClosedFor(name="Day after New Year's Day"),
         ClosedFor(name="Good Friday"),
         ClosedFor(name="Easter Monday"),
         ClosedFor(name="Christmas Day"),
         ClosedFor(name="Boxing Day")
     ]
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     events = RecurringEventPage.events.hols(self.calendar.holidays)      \
                                .byDay(dt.date(1989,1,1), dt.date(1989,1,31))
     self.assertEqual(len(events), 31)
     evod = events[1]
     self.assertEqual(evod.date, dt.date(1989, 1, 2))
     self.assertEqual(evod.holiday, "Day after New Year's Day")
     self.assertEqual(len(evod.days_events), 1)
     self.assertEqual(len(evod.continuing_events), 0)
     title, page, url = evod.all_events[0]
     self.assertEqual(title, "UVW Cancelled")
     self.assertEqual(page.title, "Closed for holidays")
     self.assertEqual(page.at, "7pm")
     self.assertEqual(url, "/events/UVW/closed-for-holidays/")
class Test(TestCase):
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('j', '*****@*****.**', 's3(r3t')
        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.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))
        self.calendar.add_child(instance=self.event)
        self.postponement = PostponementPage(
            owner=self.user,
            overrides=self.event,
            except_date=dt.date(1990, 10, 10),
            cancellation_title="Meeting Postponed",
            cancellation_details=
            "The meeting has been postponed until tomorrow",
            postponement_title="A Meeting",
            date=dt.date(1990, 10, 11),
            time_from=dt.time(13),
            time_to=dt.time(16, 30),
            details="Yes a test meeting on a Thursday")
        self.event.add_child(instance=self.postponement)
        self.postponement.save_revision().publish()

    def testGetEventsByDay(self):
        events = RecurringEventPage.events.byDay(dt.date(1990, 10, 1),
                                                 dt.date(1990, 10, 31))
        self.assertEqual(len(events), 31)
        evod = events[9]
        self.assertEqual(evod.date, dt.date(1990, 10, 10))
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)
        title, page, url = evod.days_events[0]
        self.assertEqual(title, "Meeting Postponed")
        self.assertIs(type(page), CancellationPage)
        self.assertIs(type(page.postponementpage), PostponementPage)

        events = PostponementPage.events.byDay(dt.date(1990, 10, 1),
                                               dt.date(1990, 10, 31))
        self.assertEqual(len(events), 31)
        evod = events[10]
        self.assertEqual(evod.date, dt.date(1990, 10, 11))
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)
        title, page, url = evod.days_events[0]
        self.assertEqual(title, "A Meeting")
        self.assertIs(type(page), PostponementPage)

    def testStatus(self):
        self.assertEqual(self.postponement.status, "finished")
        self.assertEqual(self.postponement.status_text,
                         "This event has finished.")
        now = timezone.localtime()
        myday = now.date() + dt.timedelta(1)
        friday = myday + dt.timedelta(days=(4 - myday.weekday()) % 7)
        futureEvent = PostponementPage(
            owner=self.user,
            overrides=self.event,
            except_date=friday,
            cancellation_title="",
            cancellation_details="",
            postponement_title="Tuesday Meeting",
            date=friday + dt.timedelta(days=4),
            time_from=dt.time(13, 30),
            time_to=dt.time(16),
            details="The meeting postponed from last Friday")
        self.event.add_child(instance=futureEvent)
        self.assertIsNone(futureEvent.status)
        self.assertEqual(futureEvent.status_text, "")

    @freeze_timetz("1990-10-11 16:29:00")
    def testStatusStarted(self):
        self.assertEqual(self.postponement.status, "started")
        self.assertEqual(self.postponement.status_text,
                         "This event has started.")

    def testWhen(self):
        self.assertEqual(self.postponement.when,
                         "Thursday 11th of October 1990 at 1pm to 4:30pm")

    def testWhatPostponed(self):
        self.assertEqual(self.postponement.what, "Postponed")

    def testWhatRescheduled(self):
        reschedule = PostponementPage(owner=self.user,
                                      overrides=self.event,
                                      except_date=dt.date(1991, 1, 7),
                                      date=dt.date(1991, 1, 6),
                                      postponement_title="Rescheduled")
        self.event.add_child(instance=reschedule)
        self.assertEqual(reschedule.what, "Rescheduled")

    def testWhatSameTime(self):
        change = PostponementPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(1991, 1, 7),
                                  date=dt.date(1991, 1, 7),
                                  time_from=dt.time(13, 30),
                                  time_to=dt.time(16),
                                  postponement_title="Small Change")
        self.event.add_child(instance=change)
        self.assertIsNone(change.what)

    def testPostponedFrom(self):
        self.assertEqual(self.postponement.postponed_from,
                         "Wednesday 10th of October 1990")

    def testPostponedTo(self):
        self.assertEqual(self.postponement.postponed_to,
                         "Thursday 11th of October 1990")

    @freeze_timetz("2017-05-01")
    def testAt(self):
        self.assertEqual(self.postponement.at.strip(), "1pm")
        nextDate = self.event.next_date
        newDate = nextDate + dt.timedelta(1)
        reschedule = PostponementPage(
            owner=self.user,
            overrides=self.event,
            except_date=nextDate,
            cancellation_title="",
            cancellation_details="",
            postponement_title="Early Meeting",
            date=newDate,
            time_from=dt.time(8, 30),
            time_to=dt.time(11),
            details="The meeting will be held early tomorrow")
        self.event.add_child(instance=reschedule)
        nextOn = self.event._nextOn(self.request)
        url = "/events/test-meeting/{}-postponement/".format(nextDate)
        self.assertEqual(nextOn[:76],
                         '<a class="inline-link" href="{}">'.format(url))
        self.assertEqual(nextOn[-4:], '</a>')
        parts = nextOn[76:-4].split()
        self.assertEqual(len(parts), 6)
        self.assertEqual(parts[0], "{:%A}".format(newDate))
        self.assertEqual(int(parts[1][:-2]), newDate.day)
        self.assertIn(parts[1][-2:], ["st", "nd", "rd", "th"])
        self.assertEqual(parts[2], "of")
        self.assertEqual(parts[3], "{:%B}".format(newDate))
        self.assertEqual(parts[4], "at")
        self.assertEqual(parts[5], "8:30am")

    def testCurrentDt(self):
        self.assertIsNone(self.postponement._current_datetime_from)

    def testFutureDt(self):
        self.assertIsNone(self.postponement._future_datetime_from)

    def testPastDt(self):
        self.assertEqual(self.postponement._past_datetime_from,
                         datetimetz(1990, 10, 11, 13, 0))

    def testCancellationView(self):
        response = self.client.get(
            "/events/test-meeting/1990-10-10-postponement/from/")
        select = response.soup.select
        self.assertEqual(response.status_code, 200)
        title = select('.joy-title h1')[0]
        self.assertEqual(title.string.strip(), "Meeting Postponed")
        details = select('.joy-ev-details .rich-text')[0]
        self.assertEqual(details.string.strip(),
                         "The meeting has been postponed until tomorrow")
        toLink = select('.joy-ev-to-when a')[0]
        self.assertEqual(toLink.string.strip(),
                         "Thursday 11th of October 1990 at 1pm to 4:30pm")
        self.assertEqual(toLink['href'],
                         "/events/test-meeting/1990-10-10-postponement/")

    def testCancellationUrl(self):
        self.assertEqual(self.postponement.getCancellationUrl(self.request),
                         "/events/test-meeting/1990-10-10-postponement/from/")
        was = wagtail.core.models.WAGTAIL_APPEND_SLASH
        wagtail.core.models.WAGTAIL_APPEND_SLASH = False
        self.assertEqual(self.postponement.getCancellationUrl(self.request),
                         "/events/test-meeting/1990-10-10-postponement/from")
        wagtail.core.models.WAGTAIL_APPEND_SLASH = was
Example #30
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()