Skip to content

Commit b25000e

Browse files
authored
Merge pull request #56 from alan-turing-institute/usage-email-bug-fix
Usage email bug fix
2 parents 0830755 + 6a41448 commit b25000e

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

usage_function/tests/test_function_app.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_main(self) -> None:
3535
mock_get_all_usage.return_value = ["usage1", "usage2"]
3636

3737
with patch("usage.datetime") as mock_datetime:
38-
now = datetime(year=2022, month=7, day=10)
38+
now = datetime(year=2022, month=7, day=10, hour=10, minute=5, second=2)
3939
mock_datetime.now.return_value = now
4040

4141
with patch(
@@ -54,31 +54,29 @@ def test_main(self) -> None:
5454
_env_file=None,
5555
)
5656

57-
with patch("usage.date_range") as mock_date_range:
58-
mock_date_range.return_value = [33, 44]
57+
mock_timer = MagicMock()
58+
mock_timer.past_due = True
5959

60-
mock_timer = MagicMock()
61-
mock_timer.past_due = True
60+
usage.main(mock_timer)
6261

63-
usage.main(mock_timer)
64-
start_datetime = datetime(2022, 7, 8)
65-
end_datetime = datetime(2022, 7, 9)
66-
67-
mock_date_range.assert_called_once_with(
68-
start_datetime, end_datetime
69-
)
62+
eighth = datetime(
63+
year=2022, month=7, day=8, hour=0, minute=0, second=0
64+
)
65+
ninth = datetime(
66+
year=2022, month=7, day=9, hour=0, minute=0, second=0
67+
)
7068

7169
mock_get_all_usage.assert_has_calls(
7270
[
7371
call(
74-
44,
75-
44,
72+
ninth,
73+
ninth,
7674
billing_account_id=None,
7775
mgmt_group="mgmt-group",
7876
),
7977
call(
80-
33,
81-
33,
78+
eighth,
79+
eighth,
8280
billing_account_id=None,
8381
mgmt_group="mgmt-group",
8482
),
@@ -89,8 +87,14 @@ def test_main(self) -> None:
8987
call(
9088
HTTP_ADAPTER.validate_python("https://my.host"),
9189
["usage1", "usage2"],
92-
start_datetime.date(),
93-
end_datetime.date(),
90+
ninth,
91+
ninth,
92+
),
93+
call(
94+
HTTP_ADAPTER.validate_python("https://my.host"),
95+
["usage1", "usage2"],
96+
eighth,
97+
eighth,
9498
),
9599
]
96100
)

usage_function/usage/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def main(mytimer: func.TimerRequest) -> None:
6161
retrieve_and_send_usage(
6262
config.API_URL,
6363
usage,
64-
start_datetime.date(),
65-
end_datetime.date(),
64+
usage_date,
65+
usage_date,
6666
)
6767
break
6868
except HttpResponseError as e:

usage_function/utils/usage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def get_all_usage(
5252
credential=CREDENTIALS, subscription_id=str(UUID(int=0))
5353
)
5454

55+
# Note that the data we get back seems to ignore the time part
56+
# and requesting data between 2023-01-01T00:00:00Z and 2023-01-01T00:00:00Z
57+
# will return data for the whole of 2023-01-01.
5558
filter_from = "properties/usageEnd ge '{}'".format(
5659
start_time.strftime("%Y-%m-%dT%H:%M:%SZ")
5760
)

0 commit comments

Comments
 (0)