|
33 | 33 | from flask.testing import FlaskClient |
34 | 34 | from hamcrest import ( |
35 | 35 | assert_that, |
| 36 | + greater_than_or_equal_to, |
| 37 | + has_entries, |
| 38 | + has_item, |
36 | 39 | has_key, |
| 40 | + has_length, |
| 41 | + is_not, |
| 42 | + none, |
37 | 43 | ) |
38 | 44 |
|
39 | 45 | 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( |
86 | 92 |
|
87 | 93 | # Extract the processed suggestions |
88 | 94 | body = response.get_json() |
89 | | - assert body is not None |
| 95 | + assert_that(body, is_not(none())) |
90 | 96 | processed_suggestions = body.get("processedSuggestions", []) |
91 | 97 |
|
92 | 98 | # Find the COVID condition |
93 | 99 | covid_suggestion = next( |
94 | 100 | (s for s in processed_suggestions if s.get("condition") == "COVID"), |
95 | 101 | None, |
96 | 102 | ) |
97 | | - assert covid_suggestion is not None, "Expected COVID condition in response" |
| 103 | + assert_that(covid_suggestion, is_not(none())) |
98 | 104 |
|
99 | 105 | # Extract actions |
100 | | - actions = covid_suggestion.get("actions", []) |
| 106 | + actions = covid_suggestion.get("actions", []) # type: ignore[union-attr] |
101 | 107 | 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))) |
115 | 109 |
|
116 | 110 | # 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")), |
120 | 114 | ) |
121 | 115 |
|
122 | 116 | # 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 | + ), |
127 | 122 | ) |
128 | 123 |
|
129 | | - # Verify action types are DataValue as per requirement |
130 | | - assert date_of_last["actionType"] == "DataValue" |
131 | | - assert date_of_next["actionType"] == "DataValue" |
132 | | - |
133 | 124 | def test_add_days_with_formatted_date_output( |
134 | 125 | self, |
135 | 126 | client: FlaskClient, |
@@ -163,23 +154,19 @@ def test_add_days_with_formatted_date_output( |
163 | 154 | ) |
164 | 155 |
|
165 | 156 | body = response.get_json() |
166 | | - assert body is not None |
| 157 | + assert_that(body, is_not(none())) |
167 | 158 | processed_suggestions = body.get("processedSuggestions", []) |
168 | 159 |
|
169 | 160 | covid_suggestion = next( |
170 | 161 | (s for s in processed_suggestions if s.get("condition") == "COVID"), |
171 | 162 | None, |
172 | 163 | ) |
173 | | - assert covid_suggestion is not None |
| 164 | + assert_that(covid_suggestion, is_not(none())) |
174 | 165 |
|
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] |
180 | 167 |
|
181 | 168 | # 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")), |
185 | 172 | ) |
0 commit comments