def testSubSiteAnotherGeneralCalendar(self): calendar = GeneralCalendarPage(owner=self.user, slug="events", title="Events") self.main.add_child(instance=calendar) calendar.save_revision().publish() self.assertFalse(GeneralCalendarPage.can_create_at(self.sub))
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 = PostponementPage.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 = GeneralCalendarPage(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) def testValidEndTimeBeforeStartTime(self): page = PostponementPage(owner=self.user) form = self.Form({'overrides': self.event, 'except_date': "2017-02-06", 'date': "2017-02-07", 'time_from': "13:00:00", 'time_to': "16:00:00", 'cancellation_title': "Meeting postponed", 'cancellation_details': rich_text("The meeting has been postponed until tomorrow"), 'postponement_title': "Committee Meeting"}, instance=page, parent_page=self.event) self.assertTrue(form.is_valid()) self.assertDictEqual(form.errors, {}) def testEndTimeBeforeStartTime(self): page = PostponementPage(owner=self.user) form = self.Form({'overrides': self.event, 'except_date': "2017-02-06", 'date': "2017-02-07", 'time_from': "13:00:00", 'time_to': "04:00:00", 'cancellation_title': "Meeting postponed", 'cancellation_details': rich_text("The meeting has been postponed until tomorrow"), 'postponement_title': "Committee Meeting"}, instance=page, parent_page=self.event) self.assertFalse(form.is_valid()) self.assertDictEqual(form.errors, {'time_to': ['Event cannot end before it starts']})
class Test(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 = MultidayRecurringEventPage( slug="test-session", title="Test Session", repeat=Recurrence(dtstart=dt.date(1990, 1, 2), freq=WEEKLY, byweekday=[TU], until=dt.date(1990, 3, 29)), num_days=3, time_from=dt.time(10), time_to=dt.time(16, 30)) self.calendar.add_child(instance=self.event) self.postponement = RescheduleMultidayEventPage( owner=self.user, overrides=self.event, except_date=dt.date(1990, 1, 9), postponement_title="Delayed Start Session", date=dt.date(1990, 1, 9), num_days=3, time_from=dt.time(13), time_to=dt.time(19, 30)) self.event.add_child(instance=self.postponement) self.postponement.save_revision().publish() def testWhen(self): self.assertEqual( self.postponement.when, "Tuesday 9th of January 1990 for 3 days " "starting at 1pm finishing at 7:30pm") @freeze_timetz("1990-02-08 18:00") def testStatus(self): postponement = RescheduleMultidayEventPage( owner=self.user, overrides=self.event, except_date=dt.date(1990, 2, 6), postponement_title="Quick Session", date=dt.date(1990, 2, 6), num_days=1, time_from=dt.time(13), time_to=dt.time(19, 30)) self.event.add_child(instance=postponement) postponement.save_revision().publish() self.assertIsNone(self.event.status)
def setUp(self): self.home = Page.objects.get(slug='home') self.user = User.objects.create_user('j', '*****@*****.**', 's3(r3t') calendar = GeneralCalendarPage(owner=self.user, slug="events", title="Events") self.home.add_child(instance=calendar) calendar.save_revision().publish() self.event = RecurringEventPage(slug="test-meeting", title="Test Meeting", repeat=Recurrence( dtstart=dt.date(1990, 1, 1), freq=WEEKLY, byweekday=[MO, WE, FR]), time_from=dt.time(13, 30), time_to=dt.time(16)) calendar.add_child(instance=self.event) self.event.save_revision().publish()
def testCalendarMixture(self): general = GeneralCalendarPage(owner=self.user, slug="events1", title="Events") self.main.add_child(instance=general) general.save_revision().publish() self.assertTrue(CalendarPage.can_create_at(self.main)) calendar = CalendarPage(owner=self.user, slug="events2", title="Events") self.main.add_child(instance=calendar) calendar.save_revision().publish() self.assertTrue(SpecificCalendarPage.can_create_at(self.main)) specific = SpecificCalendarPage(owner=self.user, slug="events3", title="Events") self.main.add_child(instance=specific) specific.save_revision().publish()
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
class Test(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 = MultidayRecurringEventPage( slug="test-session", title="Test Session", repeat=Recurrence(dtstart=dt.date(1990, 1, 2), freq=WEEKLY, byweekday=[TU], until=dt.date(1990, 3, 29)), num_days=3, time_from=dt.time(10), time_to=dt.time(16, 30)) self.calendar.add_child(instance=self.event) self.postponement = RescheduleMultidayEventPage( owner=self.user, overrides=self.event, except_date=dt.date(1990, 1, 9), postponement_title="Delayed Start Session", date=dt.date(1990, 1, 9), num_days=3, time_from=dt.time(13), time_to=dt.time(19, 30)) self.event.add_child(instance=self.postponement) self.postponement.save_revision().publish() def testWhat(self): self.assertEqual(self.postponement.what, "Postponed") def testWhen(self): self.assertEqual( self.postponement.when, "Tuesday 9th of January 1990 for 3 days " "starting at 1pm finishing at 7:30pm") @freeze_timetz("1990-02-08 16:00") def testEventStatus(self): self.assertEqual(self.event.status, "started") postponement = RescheduleMultidayEventPage( owner=self.user, overrides=self.event, except_date=dt.date(1990, 2, 6), postponement_title="Quick Session", date=dt.date(1990, 2, 6), num_days=1, time_from=dt.time(10), time_to=dt.time(16, 30)) self.event.add_child(instance=postponement) postponement.save_revision().publish() self.assertIsNone(self.event.status) def testRemoveContentPanels(self): RescheduleMultidayEventPage._removeContentPanels(["tz", "location"]) RescheduleMultidayEventPage._removeContentPanels("website") removed = ("tz", "location", "website") panels = RescheduleMultidayEventPage.content_panels self.assertFalse( any(field in removed for panel in panels for field in panel.required_fields())) @freeze_timetz("1990-01-11 18:00") def testStatus(self): self.assertEqual(self.postponement.status, "started") self.assertEqual(self.postponement.status_text, "This event has started.") def testAt(self): self.assertEqual(self.postponement.at.strip(), "1pm") @freeze_timetz("1990-01-11 18:00") def testCurrentDt(self): self.assertEqual(self.postponement._current_datetime_from, datetimetz(1990, 1, 9, 13, 0)) @freeze_timetz("1990-01-11 18:00") def testFutureDt(self): self.assertIsNone(self.postponement._future_datetime_from) def testPastDt(self): self.assertEqual(self.postponement._past_datetime_from, datetimetz(1990, 1, 9, 13, 0))
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, "") def testWhen(self): self.assertEqual(self.postponement.when, "Thursday 11th of October 1990 at 1pm to 4:30pm") @freeze_time("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")
class TestGeneralCalendar(TestCase): def setUp(self): GeneralCalendarPage.is_creatable = True self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t') self.request = RequestFactory().get("/test") self.request.user = self.user self.request.session = {} self.calendar = GeneralCalendarPage(owner=self.user, slug="calendar", title="My Calendar") home = getPage("/home/") home.add_child(instance=self.calendar) self.calendar.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="bbq", title="BBQ", uid="a94c3211-08e5-4e36-9448-86a869a47d89", date=dt.date(2011, 8, 20), time_from=dt.time(18, 30)) self.calendar.add_child(instance=event) event.save_revision().publish() self.group = GroupPage(slug="initech", title="Initech Corporation") home.add_child(instance=self.group) self.group.save_revision().publish() event = SimpleEventPage(owner=self.user, slug="planning-meeting", title="Planning to Plan", uid="a96484da-e350-45c7-af03-97ca2bb173d6", date=dt.date(2011, 8, 20), time_from=dt.time(8, 0)) self.group.add_child(instance=event) event.save_revision().publish() def testEventsOnDay(self): evod = self.calendar._getEventsOnDay(self.request, dt.date(2011, 8, 20)) self.assertEqual(evod.date, dt.date(2011, 8, 20)) self.assertEqual(len(evod.all_events), 2) self.assertEqual(len(evod.days_events), 2) events = evod.days_events self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[1].title, "BBQ") def testEventsByDay(self): evods = self.calendar._getEventsByDay(self.request, dt.date(2011, 8, 1), dt.date(2011, 8, 20)) self.assertEqual(len(evods), 20) evod = evods[19] self.assertEqual(evod.date, dt.date(2011, 8, 20)) self.assertEqual(len(evod.all_events), 2) events = evod.days_events self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[1].title, "BBQ") def testEventsByWeek(self): weeks = self.calendar._getEventsByWeek(self.request, 2011, 8) self.assertEqual(len(weeks), 5) self.assertIsNone(weeks[0][0]) evod = weeks[2][6] self.assertEqual(evod.date, dt.date(2011, 8, 20)) self.assertEqual(len(evod.all_events), 2) events = evod.days_events self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[1].title, "BBQ") @freeze_timetz("2011-08-21 15:00") def testUpcomingEvents(self): events = self.calendar._getUpcomingEvents(self.request) self.assertEqual(len(events), 0) @freeze_timetz("2011-08-21 15:00") def testPastEvents(self): events = self.calendar._getPastEvents(self.request) self.assertEqual(len(events), 2) title, event, url = events[0] self.assertEqual(title, "BBQ") self.assertEqual(event.slug, "bbq") title, event, url = events[1] self.assertEqual(event.slug, "planning-meeting") def testGetEventFromUid(self): event = self.calendar._getEventFromUid( self.request, "a94c3211-08e5-4e36-9448-86a869a47d89") self.assertEqual(event.title, "BBQ") event = self.calendar._getEventFromUid( self.request, "a96484da-e350-45c7-af03-97ca2bb173d6") self.assertEqual(event.title, "Planning to Plan") def testGetAllEventsByDay(self): events = self.calendar._getAllEvents(self.request) self.assertEqual(len(events), 2) self.assertEqual(events[0].title, "Planning to Plan") self.assertEqual(events[1].title, "BBQ")