def setUp(self): rule = Rule(frequency="WEEKLY") rule.save() cal = Calendar(name="MyCal") cal.save() data = { 'title': 'Recent Event', 'start': datetime.datetime(2008, 1, 5, 8, 0), 'end': datetime.datetime(2008, 1, 5, 9, 0), 'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0), 'rule': rule, 'calendar': cal } recurring_event = Event(**data) recurring_event.save() self.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
class TestMonth(TestCase): def setUp(self): rule = Rule(frequency="WEEKLY") rule.save() cal = Calendar(name="MyCal") cal.save() data = { 'title': 'Recent Event', 'start': datetime.datetime(2008, 1, 5, 8, 0), 'end': datetime.datetime(2008, 1, 5, 9, 0), 'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0), 'rule': rule, 'calendar': cal } recurring_event = Event(**data) recurring_event.save() self.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0)) def test_get_weeks(self): weeks = self.month.get_weeks() actuals = [(week.start, week.end) for week in weeks] if FIRST_DAY_OF_WEEK == 0: expecteds = [ (datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), (datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 10, 0, 0)), (datetime.datetime(2008, 2, 10, 0, 0), datetime.datetime(2008, 2, 17, 0, 0)), (datetime.datetime(2008, 2, 17, 0, 0), datetime.datetime(2008, 2, 24, 0, 0)), (datetime.datetime(2008, 2, 24, 0, 0), datetime.datetime(2008, 3, 2, 0, 0)) ] else: expecteds = [ (datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)), (datetime.datetime(2008, 2, 4, 0, 0), datetime.datetime(2008, 2, 11, 0, 0)), (datetime.datetime(2008, 2, 11, 0, 0), datetime.datetime(2008, 2, 18, 0, 0)), (datetime.datetime(2008, 2, 18, 0, 0), datetime.datetime(2008, 2, 25, 0, 0)), (datetime.datetime(2008, 2, 25, 0, 0), datetime.datetime(2008, 3, 3, 0, 0)) ] for actual, expected in zip(actuals, expecteds): self.assertEqual(actual, expected) def test_get_days(self): weeks = self.month.get_weeks() week = list(weeks)[0] days = week.get_days() actuals = [(len(day.occurrences), day.start, day.end) for day in days] if FIRST_DAY_OF_WEEK == 0: expecteds = [ (0, datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 1, 28, 0, 0))(0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)), (0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)), (0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)), (0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)), (0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)), (1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), ] else: expecteds = [ (0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)), (0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)), (0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)), (0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)), (0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)), (1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), (0, datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)) ] for actual, expected in zip(actuals, expecteds): self.assertEqual(actual, expected) def test_month_convenience_functions(self): self.assertEqual(self.month.prev_month().start, datetime.datetime(2008, 1, 1, 0, 0)) self.assertEqual(self.month.next_month().start, datetime.datetime(2008, 3, 1, 0, 0)) self.assertEqual(self.month.current_year().start, datetime.datetime(2008, 1, 1, 0, 0)) self.assertEqual(self.month.prev_year().start, datetime.datetime(2007, 1, 1, 0, 0)) self.assertEqual(self.month.next_year().start, datetime.datetime(2009, 1, 1, 0, 0))
class TestMonth(TestCase): def setUp(self): rule = Rule(frequency="WEEKLY") rule.save() cal = Calendar(name="MyCal") cal.save() data = { 'title': 'Recent Event', 'start': datetime.datetime(2008, 1, 5, 8, 0), 'end': datetime.datetime(2008, 1, 5, 9, 0), 'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0), 'rule': rule, 'calendar': cal } recurring_event = Event(**data) recurring_event.save() self.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0)) def test_get_weeks(self): weeks = self.month.get_weeks() actuals = [(week.start, week.end) for week in weeks] if FIRST_DAY_OF_WEEK == 0: expecteds = [ (datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), (datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 10, 0, 0)), (datetime.datetime(2008, 2, 10, 0, 0), datetime.datetime(2008, 2, 17, 0, 0)), (datetime.datetime(2008, 2, 17, 0, 0), datetime.datetime(2008, 2, 24, 0, 0)), (datetime.datetime(2008, 2, 24, 0, 0), datetime.datetime(2008, 3, 2, 0, 0)) ] else: expecteds = [ (datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)), (datetime.datetime(2008, 2, 4, 0, 0), datetime.datetime(2008, 2, 11, 0, 0)), (datetime.datetime(2008, 2, 11, 0, 0), datetime.datetime(2008, 2, 18, 0, 0)), (datetime.datetime(2008, 2, 18, 0, 0), datetime.datetime(2008, 2, 25, 0, 0)), (datetime.datetime(2008, 2, 25, 0, 0), datetime.datetime(2008, 3, 3, 0, 0)) ] for actual, expected in zip(actuals, expecteds): self.assertEqual(actual, expected) def test_get_days(self): weeks = self.month.get_weeks() week = list(weeks)[0] days = week.get_days() actuals = [(len(day.occurrences), day.start, day.end) for day in days] if FIRST_DAY_OF_WEEK == 0: expecteds = [ (0, datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 1, 28, 0, 0)) (0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)), (0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)), (0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)), (0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)), (0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)), (1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), ] else: expecteds = [ (0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)), (0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)), (0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)), (0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)), (0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)), (1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)), (0, datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)) ] for actual, expected in zip(actuals, expecteds): self.assertEqual(actual, expected) def test_month_convenience_functions(self): self.assertEqual(self.month.prev_month().start, datetime.datetime(2008, 1, 1, 0, 0)) self.assertEqual(self.month.next_month().start, datetime.datetime(2008, 3, 1, 0, 0)) self.assertEqual(self.month.current_year().start, datetime.datetime(2008, 1, 1, 0, 0)) self.assertEqual(self.month.prev_year().start, datetime.datetime(2007, 1, 1, 0, 0)) self.assertEqual(self.month.next_year().start, datetime.datetime(2009, 1, 1, 0, 0))