rename days_ago to midnight_n_days_ago

also add some more timezone boundary tests and minor code cleanup
This commit is contained in:
Leo Hemsted
2018-04-30 11:50:56 +01:00
parent 310b8eda4c
commit 0efa223fb2
6 changed files with 54 additions and 25 deletions

View File

@@ -8,7 +8,7 @@ from app.utils import (
get_midnight_for_day_before,
convert_utc_to_bst,
convert_bst_to_utc,
days_ago,
midnight_n_days_ago,
last_n_days
)
@@ -51,22 +51,26 @@ def test_convert_bst_to_utc():
assert utc == datetime(2017, 5, 12, 12, 15)
@pytest.mark.parametrize('current_time, expected_datetime', [
@pytest.mark.parametrize('current_time, arg, expected_datetime', [
# winter
('2018-01-10 23:59', datetime(2018, 1, 9, 0, 0)),
('2018-01-11 00:00', datetime(2018, 1, 10, 0, 0)),
('2018-01-10 23:59', 1, datetime(2018, 1, 9, 0, 0)),
('2018-01-11 00:00', 1, datetime(2018, 1, 10, 0, 0)),
# bst switchover at 1am 25th
('2018-03-25 10:00', datetime(2018, 3, 24, 0, 0)),
('2018-03-26 10:00', datetime(2018, 3, 25, 0, 0)),
('2018-03-27 10:00', datetime(2018, 3, 25, 23, 0)),
('2018-03-25 10:00', 1, datetime(2018, 3, 24, 0, 0)),
('2018-03-26 10:00', 1, datetime(2018, 3, 25, 0, 0)),
('2018-03-27 10:00', 1, datetime(2018, 3, 25, 23, 0)),
# summer
('2018-06-05 10:00', datetime(2018, 6, 3, 23, 0))
('2018-06-05 10:00', 1, datetime(2018, 6, 3, 23, 0)),
# zero days ago
('2018-01-11 00:00', 0, datetime(2018, 1, 11, 0, 0)),
('2018-06-05 10:00', 0, datetime(2018, 6, 4, 23, 0)),
])
def test_days_ago(current_time, expected_datetime):
def test_midnight_n_days_ago(current_time, arg, expected_datetime):
with freeze_time(current_time):
assert days_ago(1) == expected_datetime
assert midnight_n_days_ago(arg) == expected_datetime
def test_last_n_days():
@@ -80,3 +84,8 @@ def test_last_n_days():
datetime(2018, 3, 26, 0, 0),
datetime(2018, 3, 27, 0, 0)
]
@pytest.mark.parametrize('arg', [0, -1])
def test_last_n_days_invalid_arg(arg):
assert last_n_days(arg) == []