def test_error_for_incorrect_dates(self): """ An error is thrown if the end date is earlier than the start date """ with self.assertRaises(ValueError): start_date = datetime.now() end_date = start_date.replace(day=start_date.day - 1) get_days_in_range(start_date, end_date)
def get_rented_days(notified_rentals): days = 0 for notified_rental in notified_rentals: check_in = notified_rental["check_in"] check_out = notified_rental["check_out"] days += get_days_in_range(check_in, check_out) return days
def test_count_end_date_current_year(self): """ Only count the days in the current year when end date falls in the current year """ start_date = datetime(2019, 12, 25) end_date = datetime(2020, 1, 5) days = get_days_in_range(start_date, end_date) self.assertEqual(days, 4)
def test_no_days_in_range(self): """ When start date and end date are equal, days should be 0 """ start_date = datetime(2019, 12, 25) end_date = start_date days_in_range = get_days_in_range(start_date, end_date) self.assertEqual(days_in_range, 0)
def test_days_in_range(self): """ Returns correct days in range """ range_days = 3 start_date = datetime(2019, 12, 25) end_date = start_date.replace(day=start_date.day + range_days) days_in_range = get_days_in_range(start_date, end_date) self.assertEqual(days_in_range, range_days)