|
| 1 | +from datetime import datetime, timedelta |
| 2 | + |
| 3 | +import holidays |
| 4 | + |
| 5 | +from netsgiro.utils import OSLO_TZ, get_minimum_due_date |
| 6 | + |
| 7 | +monday = datetime(2022, 3, 28, 13, 59, tzinfo=OSLO_TZ) |
| 8 | + |
| 9 | + |
| 10 | +def test_minimum_due_date_before_cutoff(): |
| 11 | + """ |
| 12 | + Files generated before 14:00 Norwegian time should be |
| 13 | + adjusted by 4 days, minimum. |
| 14 | + """ |
| 15 | + assert get_minimum_due_date(monday) == (monday + timedelta(days=4)).date() |
| 16 | + |
| 17 | + |
| 18 | +monday_after_cutoff = datetime(2022, 4, 1, 14, 1, tzinfo=OSLO_TZ) |
| 19 | + |
| 20 | + |
| 21 | +def test_minimum_due_date_after_cutoff(): |
| 22 | + """ |
| 23 | + Because files sent in after 14:00 are processed the next day, files |
| 24 | + generated after 14:00 Norwegian time should be adjusted by 5 days. |
| 25 | + """ |
| 26 | + assert ( |
| 27 | + get_minimum_due_date(monday_after_cutoff) |
| 28 | + == (monday_after_cutoff + timedelta(days=5)).date() |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +day_before_easter = datetime(2022, 4, 13, 13, 59, tzinfo=OSLO_TZ) |
| 33 | + |
| 34 | + |
| 35 | +def test_minimum_due_date_with_holidays_before_cutoff(): |
| 36 | + """ |
| 37 | + There are 2 holidays in the span 13-17th of April 2022, |
| 38 | + so we expect the function to adjust the timedelta by 2 days. |
| 39 | + """ |
| 40 | + assert get_minimum_due_date(day_before_easter) == (day_before_easter + timedelta(days=6)).date() |
| 41 | + |
| 42 | + |
| 43 | +day_before_easter_after_cutoff = datetime(2022, 4, 13, 23, 59, tzinfo=OSLO_TZ) |
| 44 | + |
| 45 | + |
| 46 | +def test_minimum_due_date_with_holidays_after_cutoff(): |
| 47 | + """ |
| 48 | + If we send in the file after the cut-off, number of |
| 49 | + holidays is upped to 3, so we expect 2 more days of offsetting. |
| 50 | + """ |
| 51 | + assert ( |
| 52 | + get_minimum_due_date(day_before_easter_after_cutoff) |
| 53 | + == (day_before_easter_after_cutoff + timedelta(days=8)).date() |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +friday = datetime(2022, 4, 1, 23, 59, tzinfo=OSLO_TZ) |
| 58 | + |
| 59 | + |
| 60 | +def test_minimum_due_date_with_now_being_a_saturday(): |
| 61 | + assert get_minimum_due_date(friday) == (friday + timedelta(days=5)).date() |
| 62 | + |
| 63 | + |
| 64 | +def test_minimum_due_date_without_holiday_dependency(): |
| 65 | + """ |
| 66 | + Make sure an ImportError from a missing dependency isn't propagated. |
| 67 | + """ |
| 68 | + import sys |
| 69 | + |
| 70 | + sys.modules['holidays'] = None |
| 71 | + assert get_minimum_due_date(monday) == (monday + timedelta(days=4)).date() |
| 72 | + sys.modules['holidays'] = holidays |
0 commit comments