Skip to content

Commit bca6215

Browse files
linting
1 parent 6591256 commit bca6215

5 files changed

Lines changed: 97 additions & 146 deletions

File tree

tests/integration/conftest.py

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ def campaign_config_with_invalid_tokens(s3_client: BaseClient, rules_bucket: Buc
991991
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
992992

993993

994-
@pytest.fixture(scope="function")
994+
@pytest.fixture
995995
def multiple_campaign_configs(s3_client: BaseClient, rules_bucket: BucketName) -> Generator[list[CampaignConfig]]:
996996
"""Create and upload multiple campaign configs to S3, then clean up after tests."""
997997
campaigns, campaign_data_keys = [], []
@@ -1014,7 +1014,6 @@ def multiple_campaign_configs(s3_client: BaseClient, rules_bucket: BucketName) -
10141014
for i in range(3):
10151015
campaign = rule.CampaignConfigFactory.build(
10161016
name=f"campaign_{i}",
1017-
id=f"{targets[i]}_campaign_id",
10181017
target=targets[i],
10191018
type="V",
10201019
iterations=[
@@ -1111,71 +1110,8 @@ def campaign_config_with_missing_descriptions_missing_rule_text(
11111110
yield campaign
11121111
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
11131112

1114-
@pytest.fixture(scope="function")
1115-
def multiple_campaign_configs(request, s3_client: BaseClient, rules_bucket: BucketName) -> Generator[list[CampaignConfig]]:
1116-
"""Create and upload multiple campaign configs to S3, then clean up after tests."""
1117-
campaigns, campaign_data_keys = [], []
1118-
1119-
targets = getattr(request, "param", ["RSV", "COVID", "FLU"])
1120-
target_rules_map = {
1121-
targets[0]: [
1122-
rule.PersonAgeSuppressionRuleFactory.build(type=RuleType.filter, description="TOO YOUNG"),
1123-
rule.PostcodeSuppressionRuleFactory.build(type=RuleType.filter, priority=8, cohort_label="cohort_label4"),
1124-
],
1125-
targets[1]: [
1126-
rule.PersonAgeSuppressionRuleFactory.build(description="TOO YOUNG, your icb is: [[PERSON.ICB]]"),
1127-
rule.PostcodeSuppressionRuleFactory.build(
1128-
priority=12, cohort_label="cohort_label2", description="Your postcode is: [[PERSON.POSTCODE]]"
1129-
),
1130-
],
1131-
targets[2]: [rule.ICBRedirectRuleFactory.build()],
1132-
}
1133-
1134-
for i in range(3):
1135-
campaign = rule.CampaignConfigFactory.build(
1136-
name=f"campaign_{i}",
1137-
id=f"{targets[i]}_campaign_id",
1138-
target=targets[i],
1139-
type="V",
1140-
iterations=[
1141-
rule.IterationFactory.build(
1142-
iteration_rules=target_rules_map.get(targets[i]),
1143-
iteration_cohorts=[
1144-
rule.IterationCohortFactory.build(
1145-
cohort_label=f"cohort_label{i + 1}",
1146-
cohort_group=f"cohort_group{i + 1}",
1147-
positive_description=f"positive_desc_{i + 1}",
1148-
negative_description=f"negative_desc_{i + 1}",
1149-
),
1150-
rule.IterationCohortFactory.build(
1151-
cohort_label="cohort_label4",
1152-
cohort_group="cohort_group4",
1153-
positive_description="positive_desc_4",
1154-
negative_description="negative_desc_4",
1155-
),
1156-
],
1157-
status_text=StatusText(
1158-
NotEligible=f"You are not eligible to take {targets[i]} vaccines.",
1159-
NotActionable=f"You have taken {targets[i]} vaccine in the last 90 days",
1160-
Actionable=f"You can take {targets[i]} vaccine.",
1161-
),
1162-
)
1163-
],
1164-
)
1165-
campaign_data = {"CampaignConfig": campaign.model_dump(by_alias=True)}
1166-
key = f"{campaign.name}.json"
1167-
s3_client.put_object(
1168-
Bucket=rules_bucket, Key=key, Body=json.dumps(campaign_data), ContentType="application/json"
1169-
)
1170-
campaigns.append(campaign)
1171-
campaign_data_keys.append(key)
1172-
1173-
yield campaigns
11741113

1175-
for key in campaign_data_keys:
1176-
s3_client.delete_object(Bucket=rules_bucket, Key=key)
1177-
1178-
@pytest.fixture(scope="function")
1114+
@pytest.fixture
11791115
def campaign_configs(request, s3_client: BaseClient, rules_bucket: BucketName) -> Generator[list[CampaignConfig]]:
11801116
"""Create and upload multiple campaign configs to S3, then clean up after tests."""
11811117
campaigns, campaign_data_keys = [], []
@@ -1220,6 +1156,7 @@ def campaign_configs(request, s3_client: BaseClient, rules_bucket: BucketName) -
12201156
for key in campaign_data_keys:
12211157
s3_client.delete_object(Bucket=rules_bucket, Key=key)
12221158

1159+
12231160
@pytest.fixture(scope="class")
12241161
def consumer_mapping(s3_client: BaseClient, consumer_mapping_bucket: BucketName) -> Generator[ConsumerMapping]:
12251162
consumer_mapping = ConsumerMapping.model_validate({})
@@ -1235,11 +1172,16 @@ def consumer_mapping(s3_client: BaseClient, consumer_mapping_bucket: BucketName)
12351172
yield consumer_mapping
12361173
s3_client.delete_object(Bucket=consumer_mapping_bucket, Key="consumer_mapping.json")
12371174

1175+
12381176
@pytest.fixture(scope="class")
1239-
def consumer_mapping_for_rsv_and_covid(s3_client: BaseClient, consumer_mapping_bucket: BucketName) -> Generator[ConsumerMapping]:
1177+
def consumer_mapping_for_rsv_and_covid(
1178+
s3_client: BaseClient, consumer_mapping_bucket: BucketName
1179+
) -> Generator[ConsumerMapping]:
12401180
consumer_mapping = ConsumerMapping.model_validate({})
1241-
consumer_mapping.root[ConsumerId("consumer-id-mapped-to-rsv-and-covid")] = [CampaignID("RSV_campaign_id"),
1242-
CampaignID("COVID_campaign_id")]
1181+
consumer_mapping.root[ConsumerId("consumer-id-mapped-to-rsv-and-covid")] = [
1182+
CampaignID("RSV_campaign_id"),
1183+
CampaignID("COVID_campaign_id"),
1184+
]
12431185

12441186
consumer_mapping_data = consumer_mapping.model_dump(by_alias=True)
12451187
s3_client.put_object(
@@ -1251,6 +1193,7 @@ def consumer_mapping_for_rsv_and_covid(s3_client: BaseClient, consumer_mapping_b
12511193
yield consumer_mapping
12521194
s3_client.delete_object(Bucket=consumer_mapping_bucket, Key="consumer_mapping.json")
12531195

1196+
12541197
@pytest.fixture(scope="class")
12551198
def consumer_mapping_with_various_targets(
12561199
s3_client: BaseClient, consumer_mapping_bucket: BucketName

tests/integration/in_process/test_eligibility_endpoint.py

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
from hamcrest import (
99
assert_that,
1010
contains_exactly,
11+
contains_inanyorder,
1112
equal_to,
1213
has_entries,
1314
has_entry,
14-
has_key, has_item, all_of, has_length, contains, has_items, contains_inanyorder,
15+
has_key,
1516
)
1617

1718
from eligibility_signposting_api.config.constants import CONSUMER_ID
@@ -825,78 +826,83 @@ def test_not_actionable_and_check_response_when_rule_mapper_is_given(
825826
),
826827
)
827828

828-
829829
@pytest.mark.parametrize(
830-
"campaign_configs, consumer_mapping_for_rsv_and_covid, consumer_id, requested_conditions, expected_targets",
830+
(
831+
"campaign_configs",
832+
"consumer_mapping_for_rsv_and_covid",
833+
"consumer_id",
834+
"requested_conditions",
835+
"expected_targets",
836+
),
831837
[
832838
# Scenario 1: Intersection of mapped targets, requested targets, and active campaigns (Success)
833839
(
834-
["RSV", "COVID", "FLU"],
835-
"consumer_mapping_for_rsv_and_covid",
836-
"consumer-id-mapped-to-rsv-and-covid",
837-
"ALL",
838-
["RSV", "COVID"],
840+
["RSV", "COVID", "FLU"],
841+
"consumer_mapping_for_rsv_and_covid",
842+
"consumer-id-mapped-to-rsv-and-covid",
843+
"ALL",
844+
["RSV", "COVID"],
839845
),
840846
# Scenario 2: Explicit request for a single mapped target with an active campaign
841847
(
842-
["RSV", "COVID", "FLU"],
843-
"consumer_mapping_for_rsv_and_covid",
844-
"consumer-id-mapped-to-rsv-and-covid",
845-
"RSV",
846-
["RSV"],
848+
["RSV", "COVID", "FLU"],
849+
"consumer_mapping_for_rsv_and_covid",
850+
"consumer-id-mapped-to-rsv-and-covid",
851+
"RSV",
852+
["RSV"],
847853
),
848854
# Scenario 3: Request for an active campaign (FLU) that the consumer is NOT mapped to
849855
(
850-
["RSV", "COVID", "FLU"],
851-
"consumer_mapping_for_rsv_and_covid",
852-
"consumer-id-mapped-to-rsv-and-covid",
853-
"FLU",
854-
[],
856+
["RSV", "COVID", "FLU"],
857+
"consumer_mapping_for_rsv_and_covid",
858+
"consumer-id-mapped-to-rsv-and-covid",
859+
"FLU",
860+
[],
855861
),
856862
# Scenario 4: Request for a target that neither exists in system nor is mapped to consumer
857863
(
858-
["RSV", "COVID", "FLU"],
859-
"consumer_mapping_for_rsv_and_covid",
860-
"consumer-id-mapped-to-rsv-and-covid",
861-
"HPV",
862-
[],
864+
["RSV", "COVID", "FLU"],
865+
"consumer_mapping_for_rsv_and_covid",
866+
"consumer-id-mapped-to-rsv-and-covid",
867+
"HPV",
868+
[],
863869
),
864870
# Scenario 5: Consumer has no target mappings; requesting ALL should return empty
865871
(
866-
["RSV", "COVID", "FLU"],
867-
"consumer-id-mapped-to-rsv-and-covid",
868-
"consumer-id-with-no-mapping",
869-
"ALL",
870-
[],
872+
["RSV", "COVID", "FLU"],
873+
"consumer-id-mapped-to-rsv-and-covid",
874+
"consumer-id-with-no-mapping",
875+
"ALL",
876+
[],
871877
),
872878
# Scenario 6: Consumer has no target mappings; requesting specific target should return empty
873879
(
874-
["RSV", "COVID", "FLU"],
875-
"consumer-id-mapped-to-rsv-and-covid",
876-
"consumer-id-with-no-mapping",
877-
"RSV",
878-
[],
880+
["RSV", "COVID", "FLU"],
881+
"consumer-id-mapped-to-rsv-and-covid",
882+
"consumer-id-with-no-mapping",
883+
"RSV",
884+
[],
879885
),
880886
# Scenario 7: Consumer is mapped to targets (RSV/COVID), but those campaigns aren't active/present
881887
(
882-
["MMR"],
883-
"consumer_mapping_for_rsv_and_covid",
884-
"consumer-id-mapped-to-rsv-and-covid",
885-
"ALL",
886-
[],
888+
["MMR"],
889+
"consumer_mapping_for_rsv_and_covid",
890+
"consumer-id-mapped-to-rsv-and-covid",
891+
"ALL",
892+
[],
887893
),
888894
# Scenario 8: Request for specific mapped target (RSV), but those campaigns aren't active/present
889895
(
890-
["MMR"],
891-
"consumer_mapping_for_rsv_and_covid",
892-
"consumer-id-mapped-to-rsv-and-covid",
893-
"RSV",
894-
[],
896+
["MMR"],
897+
"consumer_mapping_for_rsv_and_covid",
898+
"consumer-id-mapped-to-rsv-and-covid",
899+
"RSV",
900+
[],
895901
),
896902
],
897-
indirect=["campaign_configs", "consumer_mapping_for_rsv_and_covid"]
903+
indirect=["campaign_configs", "consumer_mapping_for_rsv_and_covid"],
898904
)
899-
def test_valid_response_when_consumer_has_a_valid_campaign_config_mapping(
905+
def test_valid_response_when_consumer_has_a_valid_campaign_config_mapping( # noqa: PLR0913
900906
self,
901907
client: FlaskClient,
902908
persisted_person: NHSNumber,
@@ -911,7 +917,9 @@ def test_valid_response_when_consumer_has_a_valid_campaign_config_mapping(
911917
headers = {"nhs-login-nhs-number": str(persisted_person), CONSUMER_ID: consumer_id}
912918

913919
# When
914-
response = client.get(f"/patient-check/{persisted_person}?includeActions=Y&conditions={requested_conditions}", headers=headers)
920+
response = client.get(
921+
f"/patient-check/{persisted_person}?includeActions=Y&conditions={requested_conditions}", headers=headers
922+
)
915923

916924
assert_that(
917925
response,
@@ -922,10 +930,8 @@ def test_valid_response_when_consumer_has_a_valid_campaign_config_mapping(
922930
has_entry(
923931
"processedSuggestions",
924932
# This ensures ONLY these items exist, no extras like FLU
925-
contains_inanyorder(
926-
*[has_entry("condition", i) for i in expected_targets]
927-
)
933+
contains_inanyorder(*[has_entry("condition", i) for i in expected_targets]),
928934
)
929935
)
930-
)
936+
),
931937
)

tests/integration/lambda/test_app_running_as_lambda.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
424424
s3_client: BaseClient,
425425
audit_bucket: BucketName,
426426
api_gateway_endpoint: URL,
427+
secretsmanager_client: BaseClient, # noqa: ARG001
427428
):
428429
invoke_url = f"{api_gateway_endpoint}/patient-check/{persisted_person_all_cohorts}"
429430
response = httpx.get(

tests/unit/services/test_eligibility_services.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,33 @@ def test_eligibility_service_for_nonexistent_nhs_number():
6666

6767

6868
def test_get_eligibility_status_filters_permitted_campaigns(service, mock_repos):
69-
"""Tests that ONLY permitted campaigns reach the calculator factory."""
70-
# Given
71-
nhs_number = NHSNumber("1234567890")
72-
person_data = {"age": 65, "vulnerable": True}
73-
mock_repos["person"].get_eligibility_data.return_value = person_data
74-
75-
# Available campaigns in system
76-
camp_a = MagicMock(spec=CampaignConfig, id=CampaignID("CAMP_A"))
77-
camp_b = MagicMock(spec=CampaignConfig, id=CampaignID("CAMP_B"))
78-
mock_repos["campaign"].get_campaign_configs.return_value = [camp_a, camp_b]
79-
80-
# Consumer is only permitted to see CAMP_B
81-
mock_repos["consumer"].get_permitted_campaign_ids.return_value = [CampaignID("CAMP_B")]
82-
83-
# Mock calculator behavior
84-
mock_calc = MagicMock()
85-
mock_repos["factory"].get.return_value = mock_calc
86-
mock_calc.get_eligibility_status.return_value = "eligible_result"
87-
88-
# When
89-
result = service.get_eligibility_status(nhs_number, "Y", ["FLU"], "G1", "consumer_xyz")
90-
91-
# Then
92-
# Verify the factory was called ONLY with camp_b
93-
mock_repos["factory"].get.assert_called_once_with(person_data, [camp_b])
94-
assert result == "eligible_result"
69+
"""Tests that ONLY permitted campaigns reach the calculator factory."""
70+
# Given
71+
nhs_number = NHSNumber("1234567890")
72+
person_data = {"age": 65, "vulnerable": True}
73+
mock_repos["person"].get_eligibility_data.return_value = person_data
74+
75+
# Available campaigns in system
76+
camp_a = MagicMock(spec=CampaignConfig, id=CampaignID("CAMP_A"))
77+
camp_b = MagicMock(spec=CampaignConfig, id=CampaignID("CAMP_B"))
78+
mock_repos["campaign"].get_campaign_configs.return_value = [camp_a, camp_b]
79+
80+
# Consumer is only permitted to see CAMP_B
81+
mock_repos["consumer"].get_permitted_campaign_ids.return_value = [CampaignID("CAMP_B")]
82+
83+
# Mock calculator behavior
84+
mock_calc = MagicMock()
85+
mock_repos["factory"].get.return_value = mock_calc
86+
mock_calc.get_eligibility_status.return_value = "eligible_result"
87+
88+
# When
89+
result = service.get_eligibility_status(nhs_number, "Y", ["FLU"], "G1", "consumer_xyz")
90+
91+
# Then
92+
# Verify the factory was called ONLY with camp_b
93+
mock_repos["factory"].get.assert_called_once_with(person_data, [camp_b])
94+
assert result == "eligible_result"
95+
9596

9697
def test_raises_unknown_person_error_on_repo_not_found(service, mock_repos):
9798
"""Tests that NotFoundError from repo is translated to UnknownPersonError."""

tests/unit/views/test_eligibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def test_consumer_id_is_passed_to_service(app: Flask, client: FlaskClient):
606606
# Then
607607
# Verify the 5th positional argument or the keyword argument 'consumer_id'
608608
mock_service.get_eligibility_status.assert_called_once()
609-
args, kwargs = mock_service.get_eligibility_status.call_args
609+
args, _kwargs = mock_service.get_eligibility_status.call_args
610610

611611
# Check that 'specific_consumer_123' was the consumer_id passed
612612
assert args[4] == "specific_consumer_123"

0 commit comments

Comments
 (0)