예제 #1
0
 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)
예제 #2
0
 def testGetContext(self):
     rr = Recurrence(dtstart=dt.date(2014, 12, 1),
                     freq=MONTHLY,
                     byweekday=[MO(1), MO(3), MO(5)])
     attrs = {'id': "id_repeat"}
     widget = RecurrenceWidget(attrs)
     context = widget.get_context("repeat", rr, None)
     self.assertEqual(list(context.keys()), ["widget"])
     ctx = context['widget']
     self.assertEqual(ctx['attrs'], attrs)
     self.assertEqual(ctx['name'], "repeat")
     self.assertIsInstance(ctx['subwidgets'], list)
     self.assertEqual(len(ctx['subwidgets']), 13)
     self.assertEqual(ctx['template_name'],
                      "joyous/widgets/recurrence_widget.html")
     when = "The first Monday, third Monday and fifth Monday of the month"
     self.assertEqual(ctx['value'], when)
     self.assertEqual(ctx['value_s'], when)
     self.assertEqual(
         ctx['value_r'], "DTSTART:20141201\n"
         "RRULE:FREQ=MONTHLY;WKST=SU;BYDAY=+1MO,+3MO,+5MO")
예제 #3
0
 def testValidDates(self):
     widget = ExceptionDateInput()
     widget.overrides_repeat = Recurrence(dtstart=dt.date(2009, 1, 1),
                                          freq=MONTHLY,
                                          byweekday=MO(1))
     self.assertEqual(widget.valid_dates(), [
         "20180903", "20181001", "20181105", "20181203", "20190107",
         "20190204", "20190304", "20190401", "20190506", "20190603",
         "20190701", "20190805", "20190902", "20191007", "20191104",
         "20191202", "20200106", "20200203", "20200302", "20200406",
         "20200504", "20200601", "20200706", "20200803", "20200907",
         "20201005"
     ])
예제 #4
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()
 def testGetUpcomingEvents(self):
     event = RecurringEventPage(slug="RST",
                                title="Ruritania secret taxidermy",
                                repeat=Recurrence(dtstart=dt.date(
                                    1980, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(20))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(
         owner=self.user,
         overrides=event,
         all_holidays=False,
         cancellation_title="Closed for the holiday")
     closedHols.closed_for = [
         ClosedFor(name="Wellington Anniversary Day"),
         ClosedFor(name="Auckland Anniversary Day"),
         ClosedFor(name="Nelson Anniversary Day"),
         ClosedFor(name="Taranaki Anniversary Day"),
         ClosedFor(name="Otago Anniversary Day"),
         ClosedFor(name="Southland Anniversary Day"),
         ClosedFor(name="South Canterbury Anniversary Day"),
         ClosedFor(name="Hawke's Bay Anniversary Day"),
         ClosedFor(name="Marlborough Anniversary Day"),
         ClosedFor(name="Canterbury Anniversary Day"),
         ClosedFor(name="Chatham Islands Anniversary Day"),
         ClosedFor(name="Westland Anniversary Day")
     ]
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     events = ClosedForHolidaysPage.events.hols(self.calendar.holidays)   \
                                   .exclude(cancellation_title="")        \
                                   .upcoming().this().descendant_of(event)
     self.assertEqual(len(events), 1)
     title, page, url = events[0]
     self.assertEqual(title, "Closed for the holiday")
     self.assertEqual(page._future_datetime_from,
                      datetimetz(1990, 12, 3, 20, 0))
     self.assertEqual(url, "/events/RST/closed-for-holidays/")
 def testGetMyDates(self):
     event = RecurringEventPage(slug="UVW",
                                title="Underwater viking wombats",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False)
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.holidays = self.calendar.holidays
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
     closedHols.closed_for = [ClosedFor(name="Good Friday")]
     # Good Friday is never going to fall on a Monday
     dates = list(islice(closedHols._getMyDates(), 10))
     self.assertEqual(dates, [])
 def testWombatGetEventsByDay(self):
     event = RecurringEventPage(slug="UVW",
                                title="Underwater viking wombats",
                                repeat=Recurrence(dtstart=dt.date(
                                    1989, 1, 1),
                                                  freq=MONTHLY,
                                                  byweekday=[MO(1)]),
                                time_from=dt.time(19))
     self.calendar.add_child(instance=event)
     closedHols = ClosedForHolidaysPage(owner=self.user,
                                        overrides=event,
                                        all_holidays=False,
                                        cancellation_title="UVW Cancelled")
     closedHols.closed_for = [
         ClosedFor(name="New Year's Day"),
         ClosedFor(name="Day after New Year's Day"),
         ClosedFor(name="Good Friday"),
         ClosedFor(name="Easter Monday"),
         ClosedFor(name="Christmas Day"),
         ClosedFor(name="Boxing Day")
     ]
     event.add_child(instance=closedHols)
     closedHols.save_revision().publish()
     events = RecurringEventPage.events.hols(self.calendar.holidays)      \
                                .byDay(dt.date(1989,1,1), dt.date(1989,1,31))
     self.assertEqual(len(events), 31)
     evod = events[1]
     self.assertEqual(evod.date, dt.date(1989, 1, 2))
     self.assertEqual(evod.holiday, "Day after New Year's Day")
     self.assertEqual(len(evod.days_events), 1)
     self.assertEqual(len(evod.continuing_events), 0)
     title, page, url = evod.all_events[0]
     self.assertEqual(title, "UVW Cancelled")
     self.assertEqual(page.title, "Closed for holidays")
     self.assertEqual(page.at, "7pm")
     self.assertEqual(url, "/events/UVW/closed-for-holidays/")
예제 #8
0
 def testFirstMonMonthly(self):
     rr = Recurrence(dtstart=dt.date(2009, 1, 1),
                     freq=MONTHLY,
                     byweekday=MO(1))
     self.assertEqual(rr._getWhen(0), "The first Monday of the month")
예제 #9
0
 def setUp(self):
     self.rr = Recurrence(dtstart=dt.date(2011, 12, 13),
                          freq=MONTHLY,
                          byweekday=MO(1))
     self.ical = "DTSTART:20111213\nRRULE:FREQ=MONTHLY;WKST=SU;BYDAY=+1MO"