|
1 | | -from datetime import datetime |
| 1 | +from datetime import UTC, datetime |
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from pydantic import ValidationError |
@@ -64,7 +64,7 @@ def test_valid_name(self, name_value, valid_campaign_config_with_only_mandatory_ |
64 | 64 | def test_valid_iteration_date(self, date_value, valid_campaign_config_with_only_mandatory_fields): |
65 | 65 | data = {**valid_campaign_config_with_only_mandatory_fields["Iterations"][0], "IterationDate": date_value} |
66 | 66 | model = IterationValidation(**data) |
67 | | - expected_date = datetime.strptime(date_value, "%Y%m%d").date() |
| 67 | + expected_date = datetime.strptime(str(date_value), "%Y%m%d").replace(tzinfo=UTC).date() |
68 | 68 | assert model.iteration_date == expected_date, f"Expected {expected_date}, got {model.iteration_date}" |
69 | 69 |
|
70 | 70 | # Type |
@@ -143,34 +143,39 @@ def test_approval_maximum(self, approval_maximum, valid_campaign_config_with_onl |
143 | 143 |
|
144 | 144 |
|
145 | 145 | class TestIterationCohortsSchemaValidations: |
146 | | - def test_valid_iteration_if_actions_mapper_has_entry_for_the_provided_default_routing_key(self, valid_campaign_config_with_only_mandatory_fields): |
| 146 | + def test_valid_iteration_if_actions_mapper_has_entry_for_the_provided_default_routing_key( |
| 147 | + self, valid_campaign_config_with_only_mandatory_fields |
| 148 | + ): |
147 | 149 | expected_action = { |
148 | 150 | "ExternalRoutingCode": "BookLocal", |
149 | 151 | "ActionDescription": "##Getting the vaccine\n" |
150 | | - "You can get an RSV vaccination at your GP surgery.\n" |
151 | | - "Your GP surgery may contact you about getting the RSV vaccine. " |
152 | | - "This may be by letter, text, phone call, email or through the NHS App. " |
153 | | - "You do not need to wait to be contacted before booking your vaccination.", |
154 | | - "ActionType": "InfoText" |
| 152 | + "You can get an RSV vaccination at your GP surgery.\n" |
| 153 | + "Your GP surgery may contact you about getting the RSV vaccine. " |
| 154 | + "This may be by letter, text, phone call, email or through the NHS App. " |
| 155 | + "You do not need to wait to be contacted before booking your vaccination.", |
| 156 | + "ActionType": "InfoText", |
155 | 157 | } |
156 | 158 |
|
157 | | - data = {**valid_campaign_config_with_only_mandatory_fields["Iterations"][0], |
158 | | - "DefaultCommsRouting": "BOOK_LOCAL", "ActionsMapper": { |
159 | | - "BOOK_LOCAL": expected_action |
160 | | - }} |
| 159 | + data = { |
| 160 | + **valid_campaign_config_with_only_mandatory_fields["Iterations"][0], |
| 161 | + "DefaultCommsRouting": "BOOK_LOCAL", |
| 162 | + "ActionsMapper": {"BOOK_LOCAL": expected_action}, |
| 163 | + } |
161 | 164 | IterationValidation(**data) |
162 | 165 |
|
163 | | - def test_invalid_iteration_if_actions_mapper_has_no_entry_for_the_provided_default_routing_key(self, valid_campaign_config_with_only_mandatory_fields): |
164 | | - data = {**valid_campaign_config_with_only_mandatory_fields["Iterations"][0], |
165 | | - "DefaultCommsRouting": "BOOK_LOCAL", "ActionsMapper": {}} # Missing BOOK_LOCAL in ActionsMapper |
| 166 | + def test_invalid_iteration_if_actions_mapper_has_no_entry_for_the_provided_default_routing_key( |
| 167 | + self, valid_campaign_config_with_only_mandatory_fields |
| 168 | + ): |
| 169 | + data = { |
| 170 | + **valid_campaign_config_with_only_mandatory_fields["Iterations"][0], |
| 171 | + "DefaultCommsRouting": "BOOK_LOCAL", |
| 172 | + "ActionsMapper": {}, |
| 173 | + } # Missing BOOK_LOCAL in ActionsMapper |
166 | 174 |
|
167 | 175 | with pytest.raises(ValidationError) as error: |
168 | 176 | IterationValidation(**data) |
169 | 177 |
|
170 | 178 | errors = error.value.errors() |
171 | | - assert any( |
172 | | - e["loc"][-1] == "actions_mapper" and "BOOK_LOCAL" in str(e["msg"]) |
173 | | - for e in errors |
174 | | - ), "Expected validation error for missing BOOK_LOCAL entry in ActionsMapper" |
175 | | - |
176 | | - |
| 179 | + assert any(e["loc"][-1] == "actions_mapper" and "BOOK_LOCAL" in str(e["msg"]) for e in errors), ( |
| 180 | + "Expected validation error for missing BOOK_LOCAL entry in ActionsMapper" |
| 181 | + ) |
0 commit comments