class Test40Day(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 = MultidayRecurringEventPage( owner=self.user, slug="ice-festival", title="Ice Festival", repeat=Recurrence(dtstart=dt.date(2000, 12, 25), until=dt.date(2020, 1, 31), freq=YEARLY, bymonth=12, byweekday=MO(4)), num_days=40) self.calendar.add_child(instance=self.event) self.event.save_revision().publish() def testGetEventsByDay(self): events = MultidayRecurringEventPage.events.byDay( dt.date(2020, 1, 1), dt.date(2020, 1, 31)) self.assertEqual(len(events), 31) evod = events[0] self.assertEqual(evod.date, dt.date(2020, 1, 1)) self.assertEqual(len(evod.days_events), 0) self.assertEqual(len(evod.continuing_events), 1) thisEvent = evod.continuing_events[0] self.assertEqual(thisEvent.title, "Ice Festival") evod = events[10] self.assertEqual(evod.date, dt.date(2020, 1, 11)) self.assertEqual(len(evod.continuing_events), 1) thisEvent = evod.continuing_events[0] self.assertEqual(thisEvent.title, "Ice Festival") def testStatus(self): with freeze_timetz("2019-12-20 13:00:00"): self.assertEqual(self.event.status_text, "") with freeze_timetz("2020-01-02 13:00:00"): self.assertEqual(self.event.status_text, "This event has started.") with freeze_timetz("2020-02-03 17:00:00"): self.assertEqual(self.event.status_text, "These events have finished.") def testAt(self): self.assertEqual(self.event.at.strip(), "") @freeze_timetz("2035-04-03 10:00:00") def testNextDate(self): self.assertEqual(self.event.next_date, None) @freeze_timetz("2035-04-03 10:00:00") def testPrevDate(self): self.assertEqual(self.event.prev_date, dt.date(2019, 12, 23))
class Test(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 = MultidayRecurringEventPage( owner=self.user, slug="team-retreat", title="Team Retreat", repeat=Recurrence(dtstart=dt.date(2000, 1, 1), freq=YEARLY, bymonth=8, byweekday=FR(1)), num_days=3, time_from=dt.time(18), time_to=dt.time(16, 30)) self.calendar.add_child(instance=self.event) self.event.save_revision().publish() def testGetEventsByDay(self): events = MultidayRecurringEventPage.events.byDay( dt.date(2017, 8, 1), dt.date(2017, 8, 31)) self.assertEqual(len(events), 31) evod = events[3] self.assertEqual(evod.date, dt.date(2017, 8, 4)) self.assertEqual(len(evod.days_events), 1) self.assertEqual(len(evod.continuing_events), 0) evod = events[4] self.assertEqual(evod.date, dt.date(2017, 8, 5)) self.assertEqual(len(evod.days_events), 0) self.assertEqual(len(evod.continuing_events), 1) evod = events[5] self.assertEqual(evod.date, dt.date(2017, 8, 6)) self.assertEqual(len(evod.days_events), 0) self.assertEqual(len(evod.continuing_events), 1) def testStatus(self): with freeze_timetz("2014-08-01 17:00:00"): self.assertEqual(self.event.status_text, "") with freeze_timetz("2014-08-02 13:00:00"): self.assertEqual(self.event.status_text, "This event has started.") with freeze_timetz("2014-08-03 15:00:00"): self.assertEqual(self.event.status_text, "This event has started.") with freeze_timetz("2014-08-03 17:00:00"): self.assertEqual(self.event.status_text, "") def testNextOn(self): request = RequestFactory().get("/test") request.user = self.user request.session = {} oldEvent = MultidayRecurringEventPage(owner=self.user, slug="same-old-thing", title="Same Ol'", repeat=Recurrence( dtstart=dt.date(1971, 1, 1), until=dt.date(1982, 1, 1), freq=WEEKLY, byweekday=SA(1)), num_days=2) self.calendar.add_child(instance=oldEvent) oldEvent.save_revision().publish() with freeze_timetz("1974-08-01 17:00:00"): self.assertEqual(oldEvent.next_date, dt.date(1974, 8, 3)) self.assertEqual(oldEvent._nextOn(request), "Saturday 3rd of August ") with freeze_timetz("1982-01-01 17:00:00"): self.assertIsNone(oldEvent.next_date) self.assertEqual(oldEvent._nextOn(request), None) def testWhen(self): self.assertEqual( self.event.when, "The first Friday of August for 3 days " "starting at 6pm finishing at 4:30pm") def testAt(self): self.assertEqual(self.event.at.strip(), "6pm") @freeze_timetz("2035-04-03 10:00:00") def testPrevDate(self): self.assertEqual(self.event.prev_date, dt.date(2034, 8, 4)) @freeze_timetz("2018-04-03 10:00:00") def testFutureExceptions(self): request = RequestFactory().get("/test") request.user = self.user request.session = {} info2018 = ExtraInfoPage(owner=self.user, overrides=self.event, except_date=dt.date(2018, 8, 3), extra_title="Team Retreat 2018", extra_information="Weekend at Bernie's") self.event.add_child(instance=info2018) exceptions = self.event._futureExceptions(request) self.assertEqual(len(exceptions), 1) info = exceptions[0] self.assertEqual(info.slug, "2018-08-03-extra-info") self.assertEqual(info.extra_title, "Team Retreat 2018") @freeze_timetz("2018-08-04 02:00:00") def testPastExcludeExtraInfo(self): info2018 = ExtraInfoPage(owner=self.user, overrides=self.event, except_date=dt.date(2018, 8, 3), extra_title="Team Retreat 2018", extra_information="Weekend at Bernie's") self.event.add_child(instance=info2018) before = self.event._past_datetime_from self.assertEqual(before, datetimetz(2017, 8, 4, 18))
class Test(TestCase): def setUp(self): Site.objects.update(hostname="joy.test") self.user = User.objects.create_user('i', '*****@*****.**', 's3cr3t') self.calendar = CalendarPage(owner = self.user, slug = "events", title = "Events") Page.objects.get(slug='home').add_child(instance=self.calendar) self.calendar.save() self.calendar.save_revision().publish() self.event = RecurringEventPage(owner = self.user, slug = "lug-meetup", title = "Linux Users Group Meetup", repeat = Recurrence(dtstart=dt.date(2017,8,5), freq=MONTHLY, byweekday=[TU(1)]), time_from = dt.time(18,30), time_to = dt.time(20), location = "6 Mackay St, Greymouth (upstairs)") self.calendar.add_child(instance=self.event) self.event.save_revision().publish() def testGetEventsByDay(self): events = RecurringEventPage.events.byDay(dt.date(2017,8,1), dt.date(2017,10,31)) self.assertEqual(len(events), 92) evod = events[35] self.assertEqual(evod.date, dt.date(2017,9,5)) self.assertEqual(len(evod.all_events), 1) self.assertEqual(len(evod.days_events), 1) self.assertEqual(len(evod.continuing_events), 0) def testStatus(self): pastEvent = RecurringEventPage(owner = self.user, slug = "past", title = "Past Event", repeat = Recurrence(dtstart=dt.date(2008,2,1), until=dt.date(2008,5,4), freq=WEEKLY, byweekday=[SA,SU])) self.calendar.add_child(instance=pastEvent) self.assertEqual(pastEvent.status, "finished") self.assertEqual(pastEvent.status_text, "These events have finished.") now = timezone.localtime() earlier = now - dt.timedelta(hours=1) if earlier.date() != now.date(): earlier = datetimetz(now.date(), dt.time.min) nowEvent = RecurringEventPage(owner = self.user, slug = "now", title = "Now Event", repeat = Recurrence(dtstart=dt.date(2010,1,1), freq=DAILY), time_from = earlier.time(), time_to = dt.time.max) self.calendar.add_child(instance=nowEvent) self.assertEqual(nowEvent.status, "started") self.assertEqual(nowEvent.status_text, "This event has started.") today = timezone.localdate() notToday = [weekday for weekday in EVERYWEEKDAY if weekday.weekday != today.weekday()] pastAndFutureEvent = RecurringEventPage(owner = self.user, slug = "not-today", title = "Any day but today", repeat = Recurrence(dtstart=dt.date(2009,8,7), freq=WEEKLY, byweekday=notToday)) self.calendar.add_child(instance=pastAndFutureEvent) self.assertIsNone(pastAndFutureEvent.status) self.assertEqual(pastAndFutureEvent.status_text, "") @freeze_timetz("2008-05-04 09:01") def testJustFinishedStatus(self): event = RecurringEventPage(owner = self.user, slug = "breakfast1", title = "Breakfast-in-bed", repeat = Recurrence(dtstart=dt.date(2008,2,1), until=dt.date(2008,5,9), freq=WEEKLY, byweekday=[SA,SU]), time_from = dt.time(8), time_to = dt.time(9)) self.calendar.add_child(instance=event) self.assertEqual(event.status, "finished") @freeze_timetz("2008-05-04 07:00") def testLastOccurenceCancelledStatus(self): event = RecurringEventPage(owner = self.user, slug = "breakfast2", title = "Breakfast-in-bed", repeat = Recurrence(dtstart=dt.date(2008,2,1), until=dt.date(2008,5,9), freq=WEEKLY, byweekday=[SA,SU]), time_from = dt.time(8), time_to = dt.time(9)) self.calendar.add_child(instance=event) cancellation = CancellationPage(owner = self.user, overrides = event, except_date = dt.date(2008, 5, 4), cancellation_title = "Fire in the kitchen", cancellation_details = "The bacon fat is burning") event.add_child(instance=cancellation) self.assertEqual(event.status, "finished") @freeze_timetz("2008-05-04 12:00") def testPostponementOccurenceLast(self): request = RequestFactory().get("/test") request.user = self.user request.session = {} event = RecurringEventPage(owner = self.user, slug = "breakfast3", title = "Breakfast-in-bed", repeat = Recurrence(dtstart=dt.date(2008,2,1), until=dt.date(2008,5,9), freq=WEEKLY, byweekday=[SA,SU]), time_from = dt.time(8), time_to = dt.time(9)) self.calendar.add_child(instance=event) postponement = PostponementPage(owner = self.user, overrides = event, except_date = dt.date(2008, 5, 3), postponement_title = "Breakfast in Bed owed from May", date = dt.date(2008, 5, 24), time_from = dt.time(8), time_to = dt.time(9)) event.add_child(instance=postponement) self.assertIsNone(event.status) self.assertEqual(event._nextOn(request), '<a class="inline-link" href="/events/breakfast3/2008-05-03-postponement/">Saturday 24th of May at 8am</a>') def testWhen(self): self.assertEqual(self.event.when, "The first Tuesday of the month at 6:30pm to 8pm") def testAt(self): self.assertEqual(self.event.at.strip(), "6:30pm") def testCurrentDt(self): lugDt = self.event._current_datetime_from self.assertEqual(lugDt.time(), dt.time(18,30)) self.assertEqual(lugDt.date().weekday(), 1) self.assertLess(lugDt.date().day, 8) movieNight = RecurringEventPage(owner = self.user, slug = "movies", title = "Movies", repeat = Recurrence(dtstart=dt.date(2005,2,1), freq=WEEKLY, byweekday=[TH,]), time_from = dt.time(20,15), time_to = dt.time(21,30)) self.calendar.add_child(instance=movieNight) now = timezone.localtime() myday = now.date() startTime = dt.time(20,15) if now.time() > startTime: myday += dt.timedelta(days=1) thursday = myday + dt.timedelta(days=(3-myday.weekday())%7) self.assertEqual(movieNight._current_datetime_from, datetimetz(thursday, startTime)) def testFutureDt(self): lugDt = self.event._future_datetime_from self.assertEqual(lugDt.time(), dt.time(18,30)) self.assertEqual(lugDt.date().weekday(), 1) self.assertLess(lugDt.date().day, 8) movieNight = RecurringEventPage(owner = self.user, slug = "movies", title = "Movies", repeat = Recurrence(dtstart=dt.date(2005,2,1), freq=WEEKLY, byweekday=[TH,]), time_from = dt.time(20,15), time_to = dt.time(21,30)) self.calendar.add_child(instance=movieNight) now = timezone.localtime() myday = now.date() startTime = dt.time(20,15) if now.time() > startTime: myday += dt.timedelta(days=1) thursday = myday + dt.timedelta(days=(3-myday.weekday())%7) self.assertEqual(movieNight._future_datetime_from, datetimetz(thursday, startTime)) def testPastDt(self): lugDt = self.event._past_datetime_from self.assertEqual(lugDt.time(), dt.time(18,30)) self.assertEqual(lugDt.date().weekday(), 1) self.assertLess(lugDt.date().day, 8) movieNight = RecurringEventPage(owner = self.user, slug = "movies", title = "Movies", repeat = Recurrence(dtstart=dt.date(2005,2,1), freq=WEEKLY, byweekday=[TH,]), time_from = dt.time(20,15), time_to = dt.time(21,30)) self.calendar.add_child(instance=movieNight) now = timezone.localtime() myday = now.date() startTime = dt.time(20,15) if now.time() < startTime: myday -= dt.timedelta(days=1) thursday = myday - dt.timedelta(days=(myday.weekday()-3)%7) self.assertEqual(movieNight._past_datetime_from, datetimetz(thursday, startTime)) def testGroup(self): self.assertIsNone(self.event.group) def testOccursOn(self): self.assertIs(self.event._occursOn(dt.date(2018,3,6)), True) self.assertIs(self.event._occursOn(dt.date(2018,3,13)), False)