Skip to content

Commit 0e92df9

Browse files
authored
Merge pull request #219 from NHSDigital/bug/eli-317-return-empty-string-actions
Bug/eli 317 return empty string actions
2 parents fac3739 + 47decfe commit 0e92df9

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

src/eligibility_signposting_api/views/eligibility.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ def build_actions(condition: Condition) -> list[eligibility.Action] | None:
137137
eligibility.Action(
138138
actionType=eligibility.ActionType(action.action_type),
139139
actionCode=eligibility.ActionCode(action.action_code),
140-
description=eligibility.Description(action.action_description)
141-
if action.action_description is not None
142-
else None,
143-
urlLink=eligibility.HttpUrl(action.url_link) if action.url_link is not None else None,
144-
urlLabel=eligibility.UrlLabel(action.url_label) if action.url_label is not None else None,
140+
description=eligibility.Description(action.action_description or ""),
141+
urlLabel=eligibility.UrlLabel(action.url_label or ""),
142+
urlLink=eligibility.UrlLink(str(action.url_link)) if action.url_link else eligibility.UrlLink(""),
145143
)
146144
for action in condition.actions
147145
]

src/eligibility_signposting_api/views/response_model/eligibility.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import StrEnum
33
from typing import NewType
44

5-
from pydantic import UUID4, BaseModel, Field, HttpUrl, field_serializer
5+
from pydantic import UUID4, BaseModel, Field, field_serializer
66
from pydantic_core.core_schema import SerializationInfo
77

88
LastUpdated = NewType("LastUpdated", datetime)
@@ -16,6 +16,7 @@
1616
CohortCode = NewType("CohortCode", str)
1717
CohortText = NewType("CohortText", str)
1818
UrlLabel = NewType("UrlLabel", str)
19+
UrlLink = NewType("UrlLink", str)
1920

2021

2122
class Status(StrEnum):
@@ -49,9 +50,9 @@ class SuitabilityRule(BaseModel):
4950
class Action(BaseModel):
5051
action_type: ActionType = Field(..., alias="actionType")
5152
action_code: ActionCode = Field(..., alias="actionCode")
52-
description: Description | None
53-
url_link: HttpUrl | None = Field(..., alias="urlLink")
54-
url_label: UrlLabel | None = Field(..., alias="urlLabel")
53+
description: Description = Field(default=Description(""))
54+
url_link: UrlLink = Field(default=UrlLink(""), alias="urlLink")
55+
url_label: UrlLabel = Field(default=UrlLabel(""), alias="urlLabel")
5556

5657
model_config = {"populate_by_name": True}
5758

tests/fixtures/builders/model/eligibility.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
from polyfactory import Use
55
from polyfactory.factories import DataclassFactory
6-
from pydantic import HttpUrl
76

87
from eligibility_signposting_api.model import eligibility
98
from eligibility_signposting_api.model.eligibility import UrlLink
109

1110

1211
class SuggestedActionFactory(DataclassFactory[eligibility.SuggestedAction]):
13-
url_link = UrlLink(HttpUrl("https://test-example.com"))
12+
url_link = UrlLink("https://test-example.com")
1413

1514

1615
class ConditionFactory(DataclassFactory[eligibility.Condition]):

tests/integration/in_process/test_eligibility_endpoint.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,15 @@ def test_actionable(
218218
"cohortText": "positive_description",
219219
}
220220
],
221-
"actions": [{"actionType": "defaultcomms", "actionCode": "action_code"}],
221+
"actions": [
222+
{
223+
"actionCode": "action_code",
224+
"actionType": "defaultcomms",
225+
"description": "",
226+
"urlLabel": "",
227+
"urlLink": "",
228+
}
229+
],
222230
"suitabilityRules": [],
223231
"statusText": "Status.actionable",
224232
}
@@ -355,7 +363,15 @@ def test_actionable_when_only_magic_cohort_is_present(
355363
"cohortText": "magic positive description",
356364
}
357365
],
358-
"actions": [{"actionType": "defaultcomms", "actionCode": "action_code"}],
366+
"actions": [
367+
{
368+
"actionCode": "action_code",
369+
"actionType": "defaultcomms",
370+
"description": "",
371+
"urlLabel": "",
372+
"urlLink": "",
373+
}
374+
],
359375
"suitabilityRules": [],
360376
"statusText": "Status.actionable",
361377
}
@@ -511,7 +527,15 @@ def test_actionable(
511527
"condition": "FLU",
512528
"status": "Actionable",
513529
"eligibilityCohorts": [],
514-
"actions": [{"actionCode": "action_code", "actionType": "defaultcomms"}],
530+
"actions": [
531+
{
532+
"actionCode": "action_code",
533+
"actionType": "defaultcomms",
534+
"description": "",
535+
"urlLabel": "",
536+
"urlLink": "",
537+
}
538+
],
515539
"suitabilityRules": [],
516540
"statusText": "Status.actionable",
517541
}

tests/unit/views/test_eligibility.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from flask import Flask, Request
1212
from flask.testing import FlaskClient
1313
from hamcrest import assert_that, contains_exactly, has_entries, has_length, is_, none
14-
from pydantic import HttpUrl
1514
from wireup.integration.flask import get_app_container
1615

1716
from eligibility_signposting_api.audit.audit_service import AuditService
@@ -398,7 +397,7 @@ def test_no_suitability_rules_for_actionable():
398397
action_type=ActionType("TYPE_A"),
399398
action_code=ActionCode("CODE123"),
400399
action_description=ActionDescription("Some description"),
401-
url_link=UrlLink(HttpUrl("https://example.com")),
400+
url_link=UrlLink("https://example.com"),
402401
url_label=UrlLabel("Learn more"),
403402
)
404403
],
@@ -407,7 +406,7 @@ def test_no_suitability_rules_for_actionable():
407406
actionType=eligibility.ActionType("TYPE_A"),
408407
actionCode=eligibility.ActionCode("CODE123"),
409408
description=eligibility.Description("Some description"),
410-
urlLink=eligibility.HttpUrl("https://example.com"),
409+
urlLink=eligibility.UrlLink("https://example.com"),
411410
urlLabel=eligibility.UrlLabel("Learn more"),
412411
)
413412
],
@@ -426,9 +425,9 @@ def test_no_suitability_rules_for_actionable():
426425
eligibility.Action(
427426
actionType=eligibility.ActionType("TYPE_B"),
428427
actionCode=eligibility.ActionCode("CODE123"),
429-
description=None,
430-
urlLink=None,
431-
urlLabel=None,
428+
description="",
429+
urlLink="",
430+
urlLabel="",
432431
)
433432
],
434433
),
@@ -601,9 +600,9 @@ def test_excludes_nulls_via_build_response(client: FlaskClient):
601600
eligibility.Action(
602601
actionType=eligibility.ActionType("TYPE_A"),
603602
actionCode=eligibility.ActionCode("CODE123"),
604-
description=None, # Should be excluded
605-
urlLink=None, # Should be excluded
606-
urlLabel=None, # Should be excluded
603+
description=eligibility.Description(""), # Should be an empty string
604+
urlLink=eligibility.UrlLink(""), # Should be an empty string
605+
urlLabel=eligibility.UrlLabel(""), # Should be an empty string
607606
)
608607
],
609608
)
@@ -633,9 +632,9 @@ def test_excludes_nulls_via_build_response(client: FlaskClient):
633632

634633
assert action["actionType"] == "TYPE_A"
635634
assert action["actionCode"] == "CODE123"
636-
assert "description" not in action
637-
assert "urlLink" not in action
638-
assert "urlLabel" not in action
635+
assert action["description"] == ""
636+
assert action["urlLink"] == ""
637+
assert action["urlLabel"] == ""
639638

640639

641640
def test_build_response_include_values_that_are_not_null(client: FlaskClient):
@@ -654,7 +653,7 @@ def test_build_response_include_values_that_are_not_null(client: FlaskClient):
654653
actionType=eligibility.ActionType("TYPE_A"),
655654
actionCode=eligibility.ActionCode("CODE123"),
656655
description=eligibility.Description("Contact GP"),
657-
urlLink=eligibility.HttpUrl(HttpUrl("https://example.dummy/")),
656+
urlLink=eligibility.UrlLink("https://example.dummy/"),
658657
urlLabel=eligibility.UrlLabel("GP contact"),
659658
)
660659
],

0 commit comments

Comments
 (0)