def setUp(self): self.now = timezone.pytz.timezone('Atlantic/Azores').localize( timezone.datetime(2016, 1, 2, 11, 12)) self.earlier_timeslot = TimeSlotFactory( start_at=self.now + relativedelta(hours=-2), end_at=self.now + relativedelta(hours=-1)) self.now_timeslot = TimeSlotFactory( start_at=self.now + relativedelta(hours=-0.5), end_at=self.now + relativedelta(hours=+0.5)) self.later_timeslot = TimeSlotFactory( start_at=self.now + relativedelta(hours=+1), end_at=self.now + relativedelta(hours=+2))
def test_includes_a_timeslot_which_is_starting_now(self): timeslot = TimeSlotFactory(start_at=self.now, end_at=self.now + relativedelta(hours=+1)) with freeze_time(self.now): queryset = TimeSlot.objects.current() self.assertIn(timeslot, queryset)
def test_includes_a_timeslot_which_has_ended_now(self): timeslot = TimeSlotFactory(start_at=self.now + relativedelta(hours=-1), end_at=self.now) with freeze_time(self.now): queryset = TimeSlot.objects.past() self.assertIn(timeslot, queryset)
def test_excludes_a_timeslot_which_ended_yesterday(self): timeslot = TimeSlotFactory(start_at=self.now + relativedelta(hours=-26), end_at=self.now + relativedelta(hours=-25)) with freeze_time(self.now): queryset = TimeSlot.objects.current() self.assertNotIn(timeslot, queryset)
def test_excludes_a_timeslot_which_starts_tomorrow(self): timeslot = TimeSlotFactory(start_at=self.now + relativedelta(hours=+24), end_at=self.now + relativedelta(hours=+25)) with freeze_time(self.now): queryset = TimeSlot.objects.past() self.assertNotIn(timeslot, queryset)
def test_excludes_a_timeslot_which_is_happening_now(self): timeslot = TimeSlotFactory(start_at=self.now + relativedelta(hours=-0.5), end_at=self.now + relativedelta(hours=+0.5)) with freeze_time(self.now): queryset = TimeSlot.objects.past() self.assertNotIn(timeslot, queryset)