Skip to content

Commit afea6a3

Browse files
committed
eli-579 refactoring tests to use hamcrest
1 parent d656bcf commit afea6a3

1 file changed

Lines changed: 24 additions & 37 deletions

File tree

tests/integration/in_process/test_derived_values.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
from flask.testing import FlaskClient
3434
from hamcrest import (
3535
assert_that,
36+
greater_than_or_equal_to,
37+
has_entries,
38+
has_item,
3639
has_key,
40+
has_length,
41+
is_not,
42+
none,
3743
)
3844

3945
from eligibility_signposting_api.model.campaign_config import CampaignConfig
@@ -86,50 +92,35 @@ def test_add_days_calculates_next_dose_due_from_last_successful_date(
8692

8793
# Extract the processed suggestions
8894
body = response.get_json()
89-
assert body is not None
95+
assert_that(body, is_not(none()))
9096
processed_suggestions = body.get("processedSuggestions", [])
9197

9298
# Find the COVID condition
9399
covid_suggestion = next(
94100
(s for s in processed_suggestions if s.get("condition") == "COVID"),
95101
None,
96102
)
97-
assert covid_suggestion is not None, "Expected COVID condition in response"
103+
assert_that(covid_suggestion, is_not(none()))
98104

99105
# Extract actions
100-
actions = covid_suggestion.get("actions", [])
106+
actions = covid_suggestion.get("actions", []) # type: ignore[union-attr]
101107
expected_actions_count = 2
102-
assert len(actions) >= expected_actions_count, (
103-
f"Expected at least {expected_actions_count} actions, got {len(actions)}"
104-
)
105-
106-
# Find the vaccination date actions by action code
107-
date_of_last = next(
108-
(a for a in actions if a.get("actionCode") == "DateOfLastVaccination"),
109-
None,
110-
)
111-
date_of_next = next(
112-
(a for a in actions if a.get("actionCode") == "DateOfNextEarliestVaccination"),
113-
None,
114-
)
108+
assert_that(actions, has_length(greater_than_or_equal_to(expected_actions_count)))
115109

116110
# Verify DateOfLastVaccination shows the raw date
117-
assert date_of_last is not None, "Expected DateOfLastVaccination action"
118-
assert date_of_last["description"] == "20260128", (
119-
f"Expected DateOfLastVaccination to be '20260128', got '{date_of_last['description']}'"
111+
assert_that(
112+
actions,
113+
has_item(has_entries(actionType="DataValue", actionCode="DateOfLastVaccination", description="20260128")),
120114
)
121115

122116
# Verify DateOfNextEarliestVaccination shows the calculated date (2026-01-28 + 91 days = 2026-04-29)
123-
assert date_of_next is not None, "Expected DateOfNextEarliestVaccination action"
124-
assert date_of_next["description"] == "20260429", (
125-
f"Expected DateOfNextEarliestVaccination to be '20260429' (20260128 + 91 days), "
126-
f"got '{date_of_next['description']}'"
117+
assert_that(
118+
actions,
119+
has_item(
120+
has_entries(actionType="DataValue", actionCode="DateOfNextEarliestVaccination", description="20260429")
121+
),
127122
)
128123

129-
# Verify action types are DataValue as per requirement
130-
assert date_of_last["actionType"] == "DataValue"
131-
assert date_of_next["actionType"] == "DataValue"
132-
133124
def test_add_days_with_formatted_date_output(
134125
self,
135126
client: FlaskClient,
@@ -163,23 +154,19 @@ def test_add_days_with_formatted_date_output(
163154
)
164155

165156
body = response.get_json()
166-
assert body is not None
157+
assert_that(body, is_not(none()))
167158
processed_suggestions = body.get("processedSuggestions", [])
168159

169160
covid_suggestion = next(
170161
(s for s in processed_suggestions if s.get("condition") == "COVID"),
171162
None,
172163
)
173-
assert covid_suggestion is not None
164+
assert_that(covid_suggestion, is_not(none()))
174165

175-
actions = covid_suggestion.get("actions", [])
176-
date_of_next = next(
177-
(a for a in actions if a.get("actionCode") == "DateOfNextEarliestVaccination"),
178-
None,
179-
)
166+
actions = covid_suggestion.get("actions", []) # type: ignore[union-attr]
180167

181168
# Verify the formatted date output
182-
assert date_of_next is not None, "Expected DateOfNextEarliestVaccination action"
183-
assert date_of_next["description"] == "29 April 2026", (
184-
f"Expected formatted date '29 April 2026', got '{date_of_next['description']}'"
169+
assert_that(
170+
actions,
171+
has_item(has_entries(actionCode="DateOfNextEarliestVaccination", description="29 April 2026")),
185172
)

0 commit comments

Comments
 (0)