rename which_financial_year to get_financial_year_for_datetime

also fix bug on the very second of rollover, march 31st 23:00:00, and
add tests
This commit is contained in:
Leo Hemsted
2019-08-28 14:27:08 +01:00
parent 2abcda47a3
commit b7e8f1baa2
3 changed files with 24 additions and 8 deletions

View File

@@ -2,7 +2,12 @@ from datetime import datetime
import pytest
from app.dao.date_util import get_financial_year, get_april_fools, get_month_start_and_end_date_in_utc
from app.dao.date_util import (
get_financial_year,
get_april_fools,
get_month_start_and_end_date_in_utc,
get_financial_year_for_datetime,
)
def test_get_financial_year():
@@ -29,3 +34,13 @@ def test_get_month_start_and_end_date_in_utc(month, year, expected_start, expect
result = get_month_start_and_end_date_in_utc(month_year)
assert result[0] == expected_start
assert result[1] == expected_end
@pytest.mark.parametrize("dt, fy", [
(datetime(2018, 3, 31, 23, 0, 0), 2018),
(datetime(2019, 3, 31, 22, 59, 59), 2018),
(datetime(2019, 3, 31, 23, 0, 0), 2019),
(datetime(2020, 3, 31, 22, 59, 0), 2019),
])
def test_get_financial_year_for_datetime(dt, fy):
assert get_financial_year_for_datetime(dt) == fy