Esempio n. 1
0
class Test(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(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,
            slug="1988-11-11-extra-info",
            title="Extra Information for Friday 11th of November",
            overrides=self.event,
            except_date=dt.date(1988, 11, 11),
            extra_title="System Demo",
            extra_information="<h3>System Demo</h3>")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testGetEventsByDay(self):
        events = RecurringEventPage.events.byDay(dt.date(1988, 11, 1),
                                                 dt.date(1988, 11, 30))
        self.assertEqual(len(events), 30)
        evod = events[10]
        self.assertEqual(evod.date, dt.date(1988, 11, 11))
        self.assertEqual(len(evod.all_events), 1)
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)
        title, page, url = evod.days_events[0]
        self.assertEqual(title, "System Demo")
        self.assertIs(type(page), ExtraInfoPage)

    def testStatus(self):
        self.assertEqual(self.info.status, "finished")
        self.assertEqual(self.info.status_text, "This event has finished.")
        now = timezone.localtime()
        myday = now.date() + dt.timedelta(days=1)
        friday = myday + dt.timedelta(days=(4 - myday.weekday()) % 7)
        futureInfo = ExtraInfoPage(owner=self.user,
                                   slug="fri-extra-info",
                                   title="Extra Information for Friday",
                                   overrides=self.event,
                                   except_date=friday,
                                   extra_title="It's Friday",
                                   extra_information="Special")
        self.event.add_child(instance=futureInfo)
        self.assertIsNone(futureInfo.status)
        self.assertEqual(futureInfo.status_text, "")

    def testWhen(self):
        self.assertEqual(self.info.when,
                         "Friday 11th of November 1988 at 1pm to 3:30pm")

    def testAt(self):
        self.assertEqual(self.info.at.strip(), "1pm")

    def testUpcomingDt(self):
        self.assertIsNone(self.info._upcoming_datetime_from)

    def testPastDt(self):
        self.assertEqual(self.info._past_datetime_from,
                         datetimetz(1988, 11, 11, 13, 0))

    def testGroup(self):
        self.assertIsNone(self.info.group)
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 testUpcomingLocalDt(self):
        when = self.event._upcoming_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")
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 testUpcomingDt(self):
        lugDt = self.event._upcoming_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._upcoming_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 TestRecurringEvent(TestCase):
    def setUp(self):
        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=WEEKEND))
        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 EVERYDAY 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, "")

    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 testUpcomingDt(self):
        lugDt = self.event._upcoming_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._upcoming_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)
Esempio n. 5
0
class TestCancellation(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),
                                        time_to=dt.time(15, 30))
        self.calendar.add_child(instance=self.event)
        self.cancellation = CancellationPage(
            owner=self.user,
            slug="1989-02-01-cancellation",
            title="Cancellation for Wednesday 1st of February",
            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()

    def testGetEventsByDay(self):
        hiddenCancellation = CancellationPage(
            owner=self.user,
            slug="1989-02-13-cancellation",
            title="Cancellation for Monday 13th of February",
            overrides=self.event,
            except_date=dt.date(1989, 2, 13))
        self.event.add_child(instance=hiddenCancellation)
        events = RecurringEventPage.events.byDay(dt.date(1989, 2, 1),
                                                 dt.date(1989, 2, 28))
        self.assertEqual(len(events), 28)
        evod1 = events[0]
        self.assertEqual(evod1.date, dt.date(1989, 2, 1))
        self.assertEqual(len(evod1.days_events), 1)
        self.assertEqual(len(evod1.continuing_events), 0)
        title, page = evod1.days_events[0]
        self.assertEqual(title, "Meeting Cancelled")
        self.assertIs(type(page), CancellationPage)
        evod2 = events[12]
        self.assertEqual(evod2.date, dt.date(1989, 2, 13))
        self.assertEqual(len(evod2.days_events), 0)
        self.assertEqual(len(evod2.continuing_events), 0)

    def testStatus(self):
        self.assertEqual(self.cancellation.status, "cancelled")
        self.assertEqual(self.cancellation.status_text,
                         "This event has been cancelled.")
        now = dt.datetime.now()
        myday = now.date() + dt.timedelta(1)
        friday = myday + dt.timedelta(days=(4 - myday.weekday()) % 7)
        futureCan = CancellationPage(owner=self.user,
                                     slug="fri-cancellation",
                                     title="Cancellation for Friday",
                                     overrides=self.event,
                                     except_date=friday,
                                     cancellation_title="",
                                     cancellation_details="")
        self.event.add_child(instance=futureCan)
        self.assertEqual(futureCan.status, "cancelled")
        self.assertEqual(futureCan.status_text,
                         "This event has been cancelled.")

    def testWhen(self):
        self.assertEqual(self.cancellation.when,
                         "Wednesday 1st of February 1989 at 1pm to 3:30pm")

    def testAt(self):
        self.assertEqual(self.cancellation.at.strip(), "1pm")
Esempio n. 6
0
class Test(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),
                                        time_to=dt.time(15, 30))
        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()

    def testGetEventsByDay(self):
        hiddenCancellation = CancellationPage(owner=self.user,
                                              overrides=self.event,
                                              except_date=dt.date(1989, 2, 13))
        self.event.add_child(instance=hiddenCancellation)
        events = RecurringEventPage.events.byDay(dt.date(1989, 2, 1),
                                                 dt.date(1989, 2, 28))
        self.assertEqual(len(events), 28)
        evod1 = events[0]
        self.assertEqual(evod1.date, dt.date(1989, 2, 1))
        self.assertEqual(len(evod1.days_events), 1)
        self.assertEqual(len(evod1.continuing_events), 0)
        title, page, url = evod1.days_events[0]
        self.assertEqual(title, "Meeting Cancelled")
        self.assertIs(type(page), CancellationPage)
        evod2 = events[12]
        self.assertEqual(evod2.date, dt.date(1989, 2, 13))
        self.assertEqual(len(evod2.days_events), 0)
        self.assertEqual(len(evod2.continuing_events), 0)

    def testOccursOn(self):
        self.assertIs(self.event._occursOn(dt.date(1989, 2, 1)), False)
        self.assertIs(self.event._occursOn(dt.date(1989, 2, 3)), True)

    def testUnexplainedCancellation(self):
        self._cancel_1999_02_08()

        events = RecurringEventPage.events.byDay(dt.date(1999, 2, 1),
                                                 dt.date(1999, 2, 28))
        self.assertEqual(len(events), 28)
        evod = events[7]
        self.assertEqual(evod.date, dt.date(1999, 2, 8))
        self.assertEqual(len(evod.days_events), 0)
        self.assertEqual(len(evod.continuing_events), 0)

    def testUnexplainedCancellationExplained(self):
        restriction = self._cancel_1999_02_08()

        request = RequestFactory().get("/test")
        request.user = self.user
        KEY = PageViewRestriction.passed_view_restrictions_session_key
        request.session = {KEY: [restriction.id]}
        events = RecurringEventPage.events(request).byDay(
            dt.date(1999, 2, 1), dt.date(1999, 2, 28))
        self.assertEqual(len(events), 28)
        evod = events[7]
        self.assertEqual(evod.date, dt.date(1999, 2, 8))
        self.assertEqual(len(evod.days_events), 1)
        self.assertEqual(len(evod.continuing_events), 0)
        title, page, url = evod.days_events[0]
        self.assertEqual(title, "Restructure Pending")
        self.assertIs(type(page), CancellationPage)

    def _cancel_1999_02_08(self):
        cancellation = CancellationPage(
            owner=self.user,
            overrides=self.event,
            except_date=dt.date(1999, 2, 8),
            cancellation_title="Restructure Pending",
            cancellation_details="Keep it quiet")
        self.event.add_child(instance=cancellation)
        PASSWORD = PageViewRestriction.PASSWORD
        restriction = PageViewRestriction.objects.create(
            restriction_type=PASSWORD, password="******", page=cancellation)
        restriction.save()
        return restriction

    def testStatus(self):
        self.assertEqual(self.cancellation.status, "cancelled")
        self.assertEqual(self.cancellation.status_text,
                         "This event has been cancelled.")
        now = dt.datetime.now()
        myday = now.date() + dt.timedelta(1)
        friday = myday + dt.timedelta(days=(4 - myday.weekday()) % 7)
        futureCan = CancellationPage(owner=self.user,
                                     overrides=self.event,
                                     except_date=friday,
                                     cancellation_title="",
                                     cancellation_details="")
        self.event.add_child(instance=futureCan)
        self.assertEqual(futureCan.status, "cancelled")
        self.assertEqual(futureCan.status_text,
                         "This event has been cancelled.")

    def testWhen(self):
        self.assertEqual(self.cancellation.when,
                         "Wednesday 1st of February 1989 at 1pm to 3:30pm")

    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 testAt(self):
        self.assertEqual(self.cancellation.at.strip(), "1pm")

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

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

    def testPastDt(self):
        self.assertEqual(self.cancellation._past_datetime_from,
                         datetimetz(1989, 2, 1, 13, 0))

    def testNeverOccursOn(self):
        cancellation = CancellationPage(owner=self.user,
                                        overrides=self.event,
                                        except_date=dt.date(1989, 2, 7),
                                        cancellation_title="Tuesday",
                                        cancellation_details="Banner")
        self.event.add_child(instance=cancellation)
        self.assertIsNone(cancellation._current_datetime_from)
        self.assertIsNone(cancellation._future_datetime_from)
        self.assertIsNone(cancellation._past_datetime_from)

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

    def testOverridesRepeat(self):
        self.assertEqual(self.cancellation.overrides_repeat, self.event.repeat)

    def testGetContext(self):
        request = RequestFactory().get("/test")
        context = self.cancellation.get_context(request)
        self.assertIn('overrides', context)