Esempio n. 1
0
 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="schedule",
                                  title="Schedule")
     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(2018, 1, 8),
                           freq=WEEKLY,
                           byweekday=[MO],
                           until=dt.date(2018, 4, 25)),
         num_days=3,
         time_from=dt.time(10),
         time_to=dt.time(12, 30))
     self.calendar.add_child(instance=self.event)
     self.info = ExtraInfoPage(owner=self.user,
                               overrides=self.event,
                               except_date=dt.date(2018, 2, 12),
                               extra_title="System Demo",
                               extra_information="<h3>System Demo</h3>")
     self.event.add_child(instance=self.info)
     self.info.save_revision().publish()
Esempio n. 2
0
 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()
Esempio n. 3
0
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))
Esempio n. 4
0
class TestMultiday(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="schedule",
                                     title="Schedule")
        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(2018, 1, 8),
                              freq=WEEKLY,
                              byweekday=[MO],
                              until=dt.date(2018, 4, 25)),
            num_days=3,
            time_from=dt.time(10),
            time_to=dt.time(12, 30))
        self.calendar.add_child(instance=self.event)
        self.info = ExtraInfoPage(owner=self.user,
                                  overrides=self.event,
                                  except_date=dt.date(2018, 2, 12),
                                  extra_title="System Demo",
                                  extra_information="<h3>System Demo</h3>")
        self.event.add_child(instance=self.info)
        self.info.save_revision().publish()

    def testStatusFinished(self):
        self.assertEqual(self.info.status, "finished")
        self.assertEqual(self.info.status_text, "This event has finished.")

    @freeze_timetz("2018-02-13 14:00:00")
    def testStatusStarted(self):
        self.assertEqual(self.info.status, "started")
        self.assertEqual(self.info.status_text, "This event has started.")

    def testWhen(self):
        self.assertEqual(
            self.info.when, "Monday 12th of February 2018 for 3 days "
            "starting at 10am finishing at 12:30pm")

    def testAt(self):
        self.assertEqual(self.info.at.strip(), "10am")

    @freeze_timetz("2018-02-13 17:00:00")
    def testCurrentDt(self):
        self.assertEqual(self.info._current_datetime_from,
                         datetimetz(2018, 2, 12, 10, 0))

    @freeze_timetz("2018-02-13 14:00:00")
    def testFutureDt(self):
        self.assertIsNone(self.info._future_datetime_from)

    def testPastDt(self):
        self.assertEqual(self.info._past_datetime_from,
                         datetimetz(2018, 2, 12, 10, 0))
Esempio n. 5
0
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)
Esempio n. 6
0
 def testShowMulidayRecurringEvent25(self):
     event = MultidayRecurringEventPage(slug      = "leaders-retreat",
                                        title     = "Leaders' Retreet",
                                        repeat    = Recurrence(dtstart=dt.date(2016,2,16),
                                                               freq=YEARLY,
                                                               bymonth=3,
                                                               byweekday=[FR(1)]),
                                        time_from = dt.time(19),
                                        num_days  = 3,
                                        tz        = "Asia/Tokyo")
     self.calendar.add_child(instance=event)
     event.save_revision().publish()
     panel = HiddenNumDaysPanel()
     panel = panel.bind_to(instance=event,
                           request=self._getRequest(),
                           form=self.form)
     content = panel.render_as_object()
     self.assertHTMLEqual(content, self.FIELD_CONTENT)
Esempio n. 7
0
 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()
Esempio n. 8
0
 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()
Esempio n. 9
0
 def testCanCancelMultidayEvent(self):
     event2 = MultidayRecurringEventPage(slug      = "test-session",
                                         title     = "Test Session",
                                         repeat    = Recurrence(dtstart=dt.date(2009,8,7),
                                                                freq=WEEKLY,
                                                                byweekday=[MO,WE,FR]),
                                         num_days  = 2,
                                         time_from = dt.time(10))
     self.group.add_child(instance=event2)
     self.assertCanCreate(event2, CancellationPage,
                          nested_form_data({'overrides':            self.event.id,
                                            'except_date':          dt.date(2009,8,14),
                                            'cancellation_title':   "Session Cancelled" }))
Esempio n. 10
0
 def testFromPage(self):
     page = MultidayRecurringEventPage(owner=self.user,
                                       slug="bought-from-rubber-man",
                                       title="Bought from a Rubber Man",
                                       repeat=Recurrence(dtstart=dt.date(
                                           2019, 4, 2),
                                                         freq=WEEKLY,
                                                         byweekday=[TU]),
                                       num_days=3,
                                       time_from=dt.time(16),
                                       time_to=dt.time(18),
                                       tz=pytz.timezone("Pacific/Auckland"))
     self.calendar.add_child(instance=page)
     page.save_revision().publish()
     vev = VEventFactory().makeFromPage(page)
     self.assertIs(type(vev), MultidayRecurringVEvent)
     tz = pytz.timezone("Pacific/Auckland")
     self.assertEqual(vev['DTSTART'].dt,
                      tz.localize(dt.datetime(2019, 4, 2, 16, 0)))
     self.assertEqual(vev['DTEND'].dt,
                      tz.localize(dt.datetime(2019, 4, 4, 18, 0)))
     self.assertEqual(vev['RRULE']['FREQ'], ["WEEKLY"])
     self.assertEqual(vev['RRULE']['BYDAY'], ["TU"])
Esempio n. 11
0
 def testCanRescheduleMultidayEvent(self):
     event2 = MultidayRecurringEventPage(slug      = "test-session",
                                         title     = "Test Session",
                                         repeat    = Recurrence(dtstart=dt.date(2009,8,7),
                                                                freq=WEEKLY,
                                                                byweekday=[MO,WE,FR]),
                                         num_days  = 2,
                                         time_from = dt.time(10))
     self.group.add_child(instance=event2)
     self.assertCanCreate(event2, RescheduleMultidayEventPage,
                          nested_form_data({'overrides':            self.event.id,
                                            'except_date':          dt.date(2009,8,16),
                                            'postponement_title':   "Shortened cycle",
                                            'date':                 dt.date(2009,8,16),
                                            'num_days':             1,
                                            'time_from':            dt.time(10)}))
Esempio n. 12
0
 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)
Esempio n. 13
0
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):
        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))
Esempio n. 15
0
 def testMultidayRecurringEventVerboseName(self):
     self.assertEqual(MultidayRecurringEventPage.get_verbose_name(),
                      "Page d'événements récurrents sur plusieurs jours")
Esempio n. 16
0
 def testMultidayRecurringEventVerboseName(self):
     self.assertEqual(MultidayRecurringEventPage.get_verbose_name(),
                      "Multiday recurring event page")