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
8 changes: 3 additions & 5 deletions src/eligibility_signposting_api/views/eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ def build_actions(condition: Condition) -> list[eligibility.Action] | None:
eligibility.Action(
actionType=eligibility.ActionType(action.action_type),
actionCode=eligibility.ActionCode(action.action_code),
description=eligibility.Description(action.action_description)
if action.action_description is not None
else None,
urlLink=eligibility.HttpUrl(action.url_link) if action.url_link is not None else None,
urlLabel=eligibility.UrlLabel(action.url_label) if action.url_label is not None else None,
description=eligibility.Description(action.action_description or ""),
urlLabel=eligibility.UrlLabel(action.url_label or ""),
urlLink=eligibility.UrlLink(str(action.url_link)) if action.url_link else eligibility.UrlLink(""),
)
for action in condition.actions
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import StrEnum
from typing import NewType

from pydantic import UUID4, BaseModel, Field, HttpUrl, field_serializer
from pydantic import UUID4, BaseModel, Field, field_serializer
from pydantic_core.core_schema import SerializationInfo

LastUpdated = NewType("LastUpdated", datetime)
Expand All @@ -16,6 +16,7 @@
CohortCode = NewType("CohortCode", str)
CohortText = NewType("CohortText", str)
UrlLabel = NewType("UrlLabel", str)
UrlLink = NewType("UrlLink", str)


class Status(StrEnum):
Expand Down Expand Up @@ -49,9 +50,9 @@ class SuitabilityRule(BaseModel):
class Action(BaseModel):
action_type: ActionType = Field(..., alias="actionType")
action_code: ActionCode = Field(..., alias="actionCode")
description: Description | None
url_link: HttpUrl | None = Field(..., alias="urlLink")
url_label: UrlLabel | None = Field(..., alias="urlLabel")
description: Description = Field(default=Description(""))
url_link: UrlLink = Field(default=UrlLink(""), alias="urlLink")
url_label: UrlLabel = Field(default=UrlLabel(""), alias="urlLabel")

model_config = {"populate_by_name": True}

Expand Down
3 changes: 1 addition & 2 deletions tests/fixtures/builders/model/eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

from polyfactory import Use
from polyfactory.factories import DataclassFactory
from pydantic import HttpUrl

from eligibility_signposting_api.model import eligibility
from eligibility_signposting_api.model.eligibility import UrlLink


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


class ConditionFactory(DataclassFactory[eligibility.Condition]):
Expand Down
30 changes: 27 additions & 3 deletions tests/integration/in_process/test_eligibility_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,15 @@ def test_actionable(
"cohortText": "positive_description",
}
],
"actions": [{"actionType": "defaultcomms", "actionCode": "action_code"}],
"actions": [
{
"actionCode": "action_code",
"actionType": "defaultcomms",
"description": "",
"urlLabel": "",
"urlLink": "",
}
],
"suitabilityRules": [],
"statusText": "Status.actionable",
}
Expand Down Expand Up @@ -355,7 +363,15 @@ def test_actionable_when_only_magic_cohort_is_present(
"cohortText": "magic positive description",
}
],
"actions": [{"actionType": "defaultcomms", "actionCode": "action_code"}],
"actions": [
{
"actionCode": "action_code",
"actionType": "defaultcomms",
"description": "",
"urlLabel": "",
"urlLink": "",
}
],
"suitabilityRules": [],
"statusText": "Status.actionable",
}
Expand Down Expand Up @@ -511,7 +527,15 @@ def test_actionable(
"condition": "FLU",
"status": "Actionable",
"eligibilityCohorts": [],
"actions": [{"actionCode": "action_code", "actionType": "defaultcomms"}],
"actions": [
{
"actionCode": "action_code",
"actionType": "defaultcomms",
"description": "",
"urlLabel": "",
"urlLink": "",
}
],
"suitabilityRules": [],
"statusText": "Status.actionable",
}
Expand Down
25 changes: 12 additions & 13 deletions tests/unit/views/test_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from flask import Flask, Request
from flask.testing import FlaskClient
from hamcrest import assert_that, contains_exactly, has_entries, has_length, is_, none
from pydantic import HttpUrl
from wireup.integration.flask import get_app_container

from eligibility_signposting_api.audit.audit_service import AuditService
Expand Down Expand Up @@ -398,7 +397,7 @@ def test_no_suitability_rules_for_actionable():
action_type=ActionType("TYPE_A"),
action_code=ActionCode("CODE123"),
action_description=ActionDescription("Some description"),
url_link=UrlLink(HttpUrl("https://example.com")),
url_link=UrlLink("https://example.com"),
url_label=UrlLabel("Learn more"),
)
],
Expand All @@ -407,7 +406,7 @@ def test_no_suitability_rules_for_actionable():
actionType=eligibility.ActionType("TYPE_A"),
actionCode=eligibility.ActionCode("CODE123"),
description=eligibility.Description("Some description"),
urlLink=eligibility.HttpUrl("https://example.com"),
urlLink=eligibility.UrlLink("https://example.com"),
urlLabel=eligibility.UrlLabel("Learn more"),
)
],
Expand All @@ -426,9 +425,9 @@ def test_no_suitability_rules_for_actionable():
eligibility.Action(
actionType=eligibility.ActionType("TYPE_B"),
actionCode=eligibility.ActionCode("CODE123"),
description=None,
urlLink=None,
urlLabel=None,
description="",
urlLink="",
urlLabel="",
)
],
),
Expand Down Expand Up @@ -601,9 +600,9 @@ def test_excludes_nulls_via_build_response(client: FlaskClient):
eligibility.Action(
actionType=eligibility.ActionType("TYPE_A"),
actionCode=eligibility.ActionCode("CODE123"),
description=None, # Should be excluded
urlLink=None, # Should be excluded
urlLabel=None, # Should be excluded
description=eligibility.Description(""), # Should be an empty string
urlLink=eligibility.UrlLink(""), # Should be an empty string
urlLabel=eligibility.UrlLabel(""), # Should be an empty string
)
],
)
Expand Down Expand Up @@ -633,9 +632,9 @@ def test_excludes_nulls_via_build_response(client: FlaskClient):

assert action["actionType"] == "TYPE_A"
assert action["actionCode"] == "CODE123"
assert "description" not in action
assert "urlLink" not in action
assert "urlLabel" not in action
assert action["description"] == ""
assert action["urlLink"] == ""
assert action["urlLabel"] == ""


def test_build_response_include_values_that_are_not_null(client: FlaskClient):
Expand All @@ -654,7 +653,7 @@ def test_build_response_include_values_that_are_not_null(client: FlaskClient):
actionType=eligibility.ActionType("TYPE_A"),
actionCode=eligibility.ActionCode("CODE123"),
description=eligibility.Description("Contact GP"),
urlLink=eligibility.HttpUrl(HttpUrl("https://example.dummy/")),
urlLink=eligibility.UrlLink("https://example.dummy/"),
urlLabel=eligibility.UrlLabel("GP contact"),
)
],
Expand Down