Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"VALID_DOSES_COUNT",
"INVALID_DOSES_COUNT",
"LAST_SUCCESSFUL_DATE",
"SUCCESSFUL_PROCEDURE_COUNT",
"LAST_VALID_DOSE_DATE",
"BOOKED_APPOINTMENT_DATE",
"BOOKED_APPOINTMENT_PROVIDER",
Expand Down
11 changes: 9 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def person_with_all_data(
gender="0",
postcode="SW18",
cohorts=["cohort_label1", "cohort_label2"],
vaccines={"RSV": {"LAST_SUCCESSFUL_DATE": None}},
vaccines={"RSV": {"LAST_SUCCESSFUL_DATE": None, "SUCCESSFUL_PROCEDURE_COUNT": "3"}},
icb="QE1",
gp_practice="C81002",
pcn="U78207",
Expand Down Expand Up @@ -952,12 +952,19 @@ def campaign_config_with_tokens(s3_client: BaseClient, rules_bucket: BucketName)
ActionDescription="## Token - PERSON.GENDER: [[PERSON.GENDER]].",
UrlLabel="Token - PERSON.DATE_OF_BIRTH: [[PERSON.DATE_OF_BIRTH]].",
),
"TOKEN_TEST3": AvailableAction(
ActionType="ButtonAuthLink",
ExternalRoutingCode="BookNBS",
ActionDescription="## "
"Token - TARGET.RSV.SUCCESSFUL_PROCEDURE_COUNT: [[TARGET.RSV.SUCCESSFUL_PROCEDURE_COUNT]].",
UrlLabel="",
),
}
),
iteration_rules=[
rule.PostcodeSuppressionRuleFactory.build(),
rule.PersonAgeSuppressionRuleFactory.build(),
rule.ICBNonEligibleActionRuleFactory.build(comms_routing="TOKEN_TEST|TOKEN_TEST2"),
rule.ICBNonEligibleActionRuleFactory.build(comms_routing="TOKEN_TEST|TOKEN_TEST2|TOKEN_TEST3"),
rule.ICBNonActionableActionRuleFactory.build(comms_routing="TOKEN_TEST"),
],
iteration_cohorts=[
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/lambda/test_app_running_as_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ def test_token_formatting_in_eligibility_response_and_audit( # noqa: PLR0913
assert response_actions[0]["urlLabel"] == "Token - PERSON.DATE_OF_BIRTH:DATE(%d %B %Y): 28 February 1990."
assert response_actions[1]["description"] == "## Token - PERSON.GENDER: 0."
assert response_actions[1]["urlLabel"] == "Token - PERSON.DATE_OF_BIRTH: 19900228."
assert response_actions[2]["description"] == "## Token - TARGET.RSV.SUCCESSFUL_PROCEDURE_COUNT: 3."
assert response_eligibility_cohorts[0]["cohortText"] == "Token - TARGET.RSV.LAST_SUCCESSFUL_DATE: "
assert response_eligibility_cohorts[1]["cohortText"] == "Token - TARGET.RSV.LAST_SUCCESSFUL_DATE:DATE(%d %B %Y): "

Expand All @@ -671,6 +672,7 @@ def test_token_formatting_in_eligibility_response_and_audit( # noqa: PLR0913
assert audit_actions[0]["actionUrlLabel"] == "Token - PERSON.DATE_OF_BIRTH:DATE(%d %B %Y): 28 February 1990."
assert audit_actions[1]["actionDescription"] == "## Token - PERSON.GENDER: 0."
assert audit_actions[1]["actionUrlLabel"] == "Token - PERSON.DATE_OF_BIRTH: 19900228."
assert audit_actions[2]["actionDescription"] == "## Token - TARGET.RSV.SUCCESSFUL_PROCEDURE_COUNT: 3."
assert audit_eligibility_cohorts[0]["cohortText"] == "Token - TARGET.RSV.LAST_SUCCESSFUL_DATE: "
assert audit_eligibility_cohorts[1]["cohortText"] == "Token - TARGET.RSV.LAST_SUCCESSFUL_DATE:DATE(%d %B %Y): "

Expand Down
15 changes: 11 additions & 4 deletions tests/unit/services/processors/test_token_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,26 +608,33 @@ def test_non_derived_token_with_invalid_target_attribute_raises_error(self):
raises(ValueError, pattern="Invalid attribute name 'CUSTOM_INVALID_FIELD'"),
)

def test_non_derived_token_with_valid_target_attribute_works(self):
@pytest.mark.parametrize(
("token", "expected"),
[
("TARGET.COVID.LAST_SUCCESSFUL_DATE", 20260128), # expect value which is an integer
("TARGET.COVID.SUCCESSFUL_PROCEDURE_COUNT", "3"), # expect value which is a string
],
)
def test_non_derived_token_with_valid_target_attribute_works(self, token, expected):
"""Test that non-derived tokens with valid target attributes work correctly."""
person = Person(
[
{"ATTRIBUTE_TYPE": "COVID", "LAST_SUCCESSFUL_DATE": "20260128"},
{"ATTRIBUTE_TYPE": "COVID", "LAST_SUCCESSFUL_DATE": "20260128", "SUCCESSFUL_PROCEDURE_COUNT": "3"},
]
)

condition = Condition(
condition_name=ConditionName("Test"),
status=Status.actionable,
status_text=StatusText("Last date: [[TARGET.COVID.LAST_SUCCESSFUL_DATE]]"),
status_text=StatusText(f"test token: [[{token}]]"),
cohort_results=[],
suitability_rules=[],
actions=[],
)

result = TokenProcessor.find_and_replace_tokens(person, condition)

assert_that(result.status_text, is_(equal_to("Last date: 20260128")))
assert_that(result.status_text, is_(equal_to(f"test token: {expected}")))

def test_person_level_attribute_with_add_days_without_explicit_source(self):
"""Test that ADD_DAYS works on PERSON-level attributes without explicit source."""
Expand Down
Loading