def test_working_delta(self): start_date = datetime.date(2016, 1, 1) end_date = ACPHoliday.working_delta(start_date, 15) self.assertEqual(datetime.date(2016, 1, 25), end_date) end_date = ACPHoliday.working_delta(start_date, 5) self.assertEqual(datetime.date(2016, 1, 11), end_date)
def test_validate_dates_first_holiday(self): first_holiday = ACPHoliday.objects.all().first() last_holiday = ACPHoliday.objects.all().last() try: ACPHoliday.validate_dates(first_holiday.date - datetime.timedelta(days=1), last_holiday.date) self.fail('Value error should have been raised') except ACPCalendarException as e: self.assertEqual('Start date precedes the first registered holiday', str(e))
def test_validate_dates_first_holiday(self): first_holiday = ACPHoliday.objects.all().first() last_holiday = ACPHoliday.objects.all().last() try: ACPHoliday.validate_dates(first_holiday.date - datetime.timedelta(days=1), last_holiday.date) self.fail('Value error should have been raised') except ValueError as e: self.assertEqual('Start date precedes the first registered holiday', str(e))
def test_validate_dates_last_holiday(self): first_holiday = ACPHoliday.objects.all().first() last_holiday = ACPHoliday.objects.all().last() try: ACPHoliday.validate_dates(first_holiday.date, last_holiday.date + datetime.timedelta(days=1)) self.fail('Value error should have been raised') except ValueError as e: self.assertEqual('End date exceed the last registered holiday', str(e))
def test_validate_dates_last_holiday(self): first_holiday = ACPHoliday.objects.all().first() last_holiday = ACPHoliday.objects.all().last() try: ACPHoliday.validate_dates( first_holiday.date, last_holiday.date + datetime.timedelta(days=1)) self.fail('Value error should have been raised') except ValueError as e: self.assertEqual('End date exceed the last registered holiday', str(e))
def test_get_working_days_for_month_illegal_month(self): try: working_days = ACPHoliday.get_working_days_for_month(2016, 13) self.assertEqual(22, working_days) self.fail('IllegalMonthError was not thrown') except ACPCalendarException as e: self.assertEqual('bad month number 13; must be 1-12', str(e))
def test_days_in_range_generator(self): start_date = datetime.date(2016, 1,1) end_date = datetime.date(2016,1,31) jan_days = list(ACPHoliday.days_in_range_generator(start_date, end_date)) self.assertEqual(31, len(jan_days)) self.assertEqual(jan_days[0], start_date) self.assertEqual(jan_days[30], end_date)
def test_get_working_days_wrong_dates(self): start_date = datetime.date(2016, 1, 5) end_date = datetime.date(2016, 1, 2) try: working_days = ACPHoliday.get_working_days(start_date, end_date) self.fail('Did not throw Value error') except ACPCalendarException as e: self.assertEqual('Start date cannot occur after end date', str(e))
def test_convert_to_date_invalid(self): try: study_date = ACPHoliday.convert_to_date(5) self.fail( 'should throw error for dates must be either string or date objects' ) except ACPCalendarException as e: self.assertEqual('Dates must be either string or date objects', str(e))
def test_get_working_days_no_work(self): start_date = datetime.date(2016, 1, 1) end_date = datetime.date(2016, 1, 2) working_days = ACPHoliday.get_working_days(start_date, end_date) self.assertEqual(0, working_days)
def test_convert_to_date(self): study_date = ACPHoliday.convert_to_date('2016-07-08') self.assertEqual(datetime.date(2016, 7, 8), study_date)
def test_get_working_days_for_month(self): working_days = ACPHoliday.get_working_days_for_month(2016, 3) self.assertEqual(22, working_days)
def test_week_end_days(self): start_date = datetime.date(2016, 1, 1) end_date = datetime.date(2016, 1, 31) week_end_days = ACPHoliday.week_end_days(start_date, end_date) self.assertEqual(10, week_end_days)
def test_get_working_days_no_work(self): start_date = datetime.date(2016, 1,1) end_date = datetime.date(2016,1,2) working_days = ACPHoliday.get_working_days(start_date, end_date) self.assertEqual(0, working_days)
def test_convert_to_date_invalid(self): try: study_date = ACPHoliday.convert_to_date(5) self.fail('should throw error for dates must be either string or date objects') except ACPCalendarException as e: self.assertEqual('Dates must be either string or date objects', str(e))