Skip to content

Commit c615de2

Browse files
more tests in IT
1 parent f59f45e commit c615de2

4 files changed

Lines changed: 94 additions & 24 deletions

File tree

tests/fixtures/matchers/eligibility.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from hamcrest.core.matcher import Matcher
22

3-
from eligibility_signposting_api.model.eligibility import Condition, EligibilityStatus, CohortResult, Reason
3+
from eligibility_signposting_api.model.eligibility import CohortResult, Condition, EligibilityStatus, Reason
44
from eligibility_signposting_api.model.rules import IterationCohort
55

66
from .meta import BaseAutoMatcher
@@ -14,6 +14,7 @@ class ConditionMatcher(BaseAutoMatcher[Condition]): ...
1414

1515
class CohortResultMatcher(BaseAutoMatcher[CohortResult]): ...
1616

17+
1718
class ReasonMatcher(BaseAutoMatcher[Reason]): ...
1819

1920

@@ -31,12 +32,10 @@ def is_condition() -> Matcher[Condition]:
3132
def is_cohort_result() -> Matcher[CohortResult]:
3233
return CohortResultMatcher()
3334

35+
3436
def is_reason() -> Matcher[Reason]:
3537
return ReasonMatcher()
3638

3739

3840
def is_iteration_cohort() -> Matcher[IterationCohort]:
3941
return IterationCohortMatcher()
40-
41-
42-

tests/integration/conftest.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,31 @@ def persisted_77yo_person(person_table: Any, faker: Faker) -> Generator[eligibil
241241
person_table.delete_item(Key={"NHS_NUMBER": row["NHS_NUMBER"], "ATTRIBUTE_TYPE": row["ATTRIBUTE_TYPE"]})
242242

243243

244+
@pytest.fixture
245+
def persisted_person_no_cohorts(person_table: Any, faker: Faker) -> Generator[eligibility.NHSNumber]:
246+
nhs_number = eligibility.NHSNumber(faker.nhs_number())
247+
248+
for row in (rows := person_rows_builder(nhs_number)):
249+
person_table.put_item(Item=row)
250+
251+
yield nhs_number
252+
253+
for row in rows:
254+
person_table.delete_item(Key={"NHS_NUMBER": row["NHS_NUMBER"], "ATTRIBUTE_TYPE": row["ATTRIBUTE_TYPE"]})
255+
256+
257+
@pytest.fixture
258+
def persisted_person_pc_sw19(person_table: Any, faker: Faker) -> Generator[eligibility.NHSNumber]:
259+
nhs_number = eligibility.NHSNumber(faker.nhs_number())
260+
for row in (rows := person_rows_builder(nhs_number, postcode="SW19")):
261+
person_table.put_item(Item=row)
262+
263+
yield nhs_number
264+
265+
for row in rows:
266+
person_table.delete_item(Key={"NHS_NUMBER": row["NHS_NUMBER"], "ATTRIBUTE_TYPE": row["ATTRIBUTE_TYPE"]})
267+
268+
244269
@pytest.fixture(scope="session")
245270
def bucket(s3_client: BaseClient) -> Generator[BucketName]:
246271
bucket_name = BucketName(os.getenv("RULES_BUCKET_NAME", "test-rules-bucket"))
@@ -255,7 +280,10 @@ def campaign_config(s3_client: BaseClient, bucket: BucketName) -> Generator[rule
255280
target="RSV",
256281
iterations=[
257282
rule.IterationFactory.build(
258-
iteration_rules=[rule.PersonAgeSuppressionRuleFactory.build()],
283+
iteration_rules=[
284+
rule.PostcodeSuppressionRuleFactory.build(type=rules.RuleType.filter),
285+
rule.PersonAgeSuppressionRuleFactory.build()
286+
],
259287
iteration_cohorts=[rule.IterationCohortFactory.build(cohort_label="cohort1")],
260288
)
261289
],
@@ -266,3 +294,5 @@ def campaign_config(s3_client: BaseClient, bucket: BucketName) -> Generator[rule
266294
)
267295
yield campaign
268296
s3_client.delete_object(Bucket=bucket, Key=f"{campaign.name}.json")
297+
298+

tests/integration/in_process/test_eligibility_endpoint.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,42 @@ def test_no_nhs_number_given(client: FlaskClient):
3737
)
3838

3939

40-
def test_actionable_by_rule(client: FlaskClient, persisted_77yo_person: NHSNumber, campaign_config: CampaignConfig): # noqa: ARG001
40+
def test_not_base_eligible(client: FlaskClient, persisted_person_no_cohorts: NHSNumber, campaign_config: CampaignConfig): # noqa: ARG001
4141
# Given
4242

4343
# When
44-
response = client.get(f"/patient-check/{persisted_77yo_person}")
44+
response = client.get(f"/patient-check/{persisted_person_no_cohorts}")
45+
46+
print("here is the respose")
47+
print(response.text)
4548

4649
# Then
4750
assert_that(
4851
response,
4952
is_response()
5053
.with_status_code(HTTPStatus.OK)
5154
.and_text(
52-
is_json_that(has_entry("processedSuggestions", has_item(has_entries(condition="RSV", status="Actionable"))))
55+
is_json_that(
56+
has_entry("processedSuggestions", has_item(has_entries(condition="RSV", status="NotEligible")))
57+
)
58+
),
59+
)
60+
61+
def test_not_eligible_by_rule(client: FlaskClient, persisted_person_pc_sw19: NHSNumber, campaign_config: CampaignConfig): # noqa: ARG001
62+
# Given
63+
64+
# When
65+
response = client.get(f"/patient-check/{persisted_person_pc_sw19}")
66+
67+
# Then
68+
assert_that(
69+
response,
70+
is_response()
71+
.with_status_code(HTTPStatus.OK)
72+
.and_text(
73+
is_json_that(
74+
has_entry("processedSuggestions", has_item(has_entries(condition="RSV", status="NotEligible")))
75+
)
5376
),
5477
)
5578

@@ -71,3 +94,23 @@ def test_not_actionable_by_rule(client: FlaskClient, persisted_person: NHSNumber
7194
)
7295
),
7396
)
97+
98+
99+
def test_actionable_by_rule(client: FlaskClient, persisted_77yo_person: NHSNumber, campaign_config: CampaignConfig): # noqa: ARG001
100+
# Given
101+
102+
# When
103+
response = client.get(f"/patient-check/{persisted_77yo_person}")
104+
105+
# Then
106+
assert_that(
107+
response,
108+
is_response()
109+
.with_status_code(HTTPStatus.OK)
110+
.and_text(
111+
is_json_that(has_entry("processedSuggestions", has_item(has_entries(condition="RSV", status="Actionable"))))
112+
),
113+
)
114+
115+
116+

tests/unit/services/calculators/test_eligibility_calculator.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
from eligibility_signposting_api.services.calculators.eligibility_calculator import EligibilityCalculator
1919
from tests.fixtures.builders.model import rule as rule_builder
2020
from tests.fixtures.builders.repos.person import person_rows_builder
21-
from tests.fixtures.matchers.eligibility import is_condition, is_eligibility_status, is_cohort_result, is_reason, \
22-
is_iteration_cohort
21+
from tests.fixtures.matchers.eligibility import (
22+
is_cohort_result,
23+
is_condition,
24+
is_eligibility_status,
25+
is_iteration_cohort,
26+
is_reason,
27+
)
2328

2429

2530
def test_not_base_eligible(faker: Faker):
@@ -892,17 +897,13 @@ def test_rules_stop_behavior(
892897
has_items(
893898
is_condition()
894899
.with_condition_name(ConditionName("RSV"))
895-
.and_status(
896-
equal_to(Status.not_actionable)
897-
)
900+
.and_status(equal_to(Status.not_actionable))
898901
.and_cohort_results(
899902
has_items(
900-
is_cohort_result()
901-
.with_reasons(
902-
contains_inanyorder(*[
903-
is_reason().with_rule_result(equal_to(result))
904-
for result in expected_reason_results
905-
])
903+
is_cohort_result().with_reasons(
904+
contains_inanyorder(
905+
*[is_reason().with_rule_result(equal_to(result)) for result in expected_reason_results]
906+
)
906907
)
907908
)
908909
)
@@ -991,10 +992,8 @@ def test_eligibility_results_when_multiple_cohorts(
991992
.and_cohort_results(
992993
contains_inanyorder(
993994
*[
994-
is_cohort_result()
995-
.with_cohort(
996-
is_iteration_cohort()
997-
.with_cohort_label(equal_to(cohort_label))
995+
is_cohort_result().with_cohort(
996+
is_iteration_cohort().with_cohort_label(equal_to(cohort_label))
998997
)
999998
for cohort_label in expected_cohorts
1000999
]
@@ -1003,4 +1002,3 @@ def test_eligibility_results_when_multiple_cohorts(
10031002
)
10041003
),
10051004
)
1006-

0 commit comments

Comments
 (0)