def setUp(self): self.work_regimen = WorkRegimen() self.jan1st = date(2015, 1, 1) self.saturday = date(2015, 1, 3) self.sunday = date(2015, 1, 4) self.monday = date(2015, 1, 5) self.tuesday = date(2015, 1, 6) self.wednesday = date(2015, 1, 7) self.work_regimen.add_holiday(self.jan1st) self.work_regimen.work_hours = [ (time(9), time(17)) ]
class WorkRegimenTest(unittest.TestCase): """ January 2015 su mo tu wd th fr sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Holiday = 1 """ def setUp(self): self.work_regimen = WorkRegimen() self.jan1st = date(2015, 1, 1) self.saturday = date(2015, 1, 3) self.sunday = date(2015, 1, 4) self.monday = date(2015, 1, 5) self.tuesday = date(2015, 1, 6) self.wednesday = date(2015, 1, 7) self.work_regimen.add_holiday(self.jan1st) self.work_regimen.work_hours = [ (time(9), time(17)) ] def tearDown(self): pass def test_it_knows_a_holiday_is_not_a_working_day(self): result = self.work_regimen.is_working_day(self.jan1st) self.assertFalse(result) def test_it_knows_weekends_are_a_working_days(self): result = self.work_regimen.is_working_day(self.saturday) self.assertFalse(result) result = self.work_regimen.is_working_day(self.sunday) self.assertFalse(result) def test_it_knows_non_weekend_days_are_working_days(self): result = self.work_regimen.is_working_day(self.monday) self.assertTrue(result) def test_it_returns_empty_working_hours_for_a_non_working_day(self): result = self.work_regimen.work_hours_for(self.jan1st) self.assertEqual(result, DateRangeList()) def test_it_returns_working_hours_for_a_working_day(self): begin = datetime.combine(self.monday, time(9)) end = datetime.combine(self.monday, time(17)) expected = DateRangeList().add(begin, end) result = self.work_regimen.work_hours_for(self.monday) self.assertEqual(result, expected) def test_it_returns_working_hours_for_a_working_day_with_a_long_lunch(self): self.work_regimen.work_hours = [ (time(9), time(12)), (time(13), time(18)) ] begin = datetime.combine(self.monday, time(9)) end = datetime.combine(self.monday, time(12)) morning = DateRange(begin, end) begin = datetime.combine(self.monday, time(13)) end = datetime.combine(self.monday, time(18)) afternoon = DateRange(begin, end) expected = DateRangeList(morning, afternoon) result = self.work_regimen.work_hours_for(self.monday) self.assertEqual(result, expected) def test_it_returns_working_hours_for_a_night_worker(self): self.work_regimen.work_hours = [ (time(21), time(5)) ] begin = datetime.combine(self.monday, time(21)) end = datetime.combine(self.tuesday, time(5)) expected = DateRangeList( DateRange(begin, end) ) result = self.work_regimen.work_hours_for(self.monday) self.assertEqual(result, expected) def test_it_returns_working_hours_for_a_30_hours_residency_shift(self): self.work_regimen.work_hours = [ (time(21), time(21)), (time(7), time(13)) ] begin = datetime.combine(self.monday, time(21)) end = datetime.combine(self.tuesday, time(21)) first_duty = DateRange(begin, end) begin = datetime.combine(self.wednesday, time(7)) end = datetime.combine(self.wednesday, time(13)) second_duty = DateRange(begin, end) expected = DateRangeList(first_duty, second_duty) result = self.work_regimen.work_hours_for(self.monday) self.assertEqual(result, expected)