Skip to content

Commit ee24f83

Browse files
committed
Address review round 2 comments
1 parent 0f72b14 commit ee24f83

File tree

8 files changed

+29
-14
lines changed

8 files changed

+29
-14
lines changed

lambdas/backend/src/controller/fhir_api_exception_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
CustomValidationError,
1010
IdentifierDuplicationError,
1111
InconsistentIdentifierError,
12-
InconsistentResourceVersion,
12+
InconsistentResourceVersionError,
1313
ResourceNotFoundError,
1414
)
1515
from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE
@@ -30,7 +30,7 @@
3030
)
3131

3232
_CUSTOM_EXCEPTION_TO_STATUS_MAP: dict[Type[Exception], int] = {
33-
InconsistentResourceVersion: 400,
33+
InconsistentResourceVersionError: 400,
3434
InconsistentIdentifierError: 400, # Identifier refers to the local FHIR identifier composed of system and value.
3535
InconsistentIdError: 400, # ID refers to the top-level ID of the FHIR resource.
3636
InvalidImmunizationIdError: 400,

lambdas/backend/tests/controller/test_fhir_api_exception_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CustomValidationError,
77
IdentifierDuplicationError,
88
InconsistentIdentifierError,
9-
InconsistentResourceVersion,
9+
InconsistentResourceVersionError,
1010
ResourceNotFoundError,
1111
)
1212
from controller.fhir_api_exception_handler import fhir_api_exception_handler
@@ -44,7 +44,7 @@ def test_exception_handler_handles_custom_exception_and_returns_fhir_response(se
4444
"""Test that custom exceptions are handled by the wrapper and a valid response is returned to the client"""
4545
test_cases = [
4646
(
47-
InconsistentResourceVersion("Resource versions do not match"),
47+
InconsistentResourceVersionError("Resource versions do not match"),
4848
400,
4949
"invariant",
5050
"Resource versions do not match",

lambdas/backend/tests/service/test_fhir_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
CustomValidationError,
1919
IdentifierDuplicationError,
2020
InconsistentIdentifierError,
21-
InconsistentResourceVersion,
21+
InconsistentResourceVersionError,
2222
ResourceNotFoundError,
2323
)
2424
from common.models.fhir_immunization import ImmunizationValidator
@@ -612,7 +612,7 @@ def test_update_immunization_raises_invalid_error_if_resource_version_does_not_m
612612
self.authoriser.authorise.return_value = True
613613

614614
# When
615-
with self.assertRaises(InconsistentResourceVersion) as error:
615+
with self.assertRaises(InconsistentResourceVersionError) as error:
616616
self.fhir_service.update_immunization(imms_id, updated_immunisation, "Test", 2)
617617

618618
# Then

lambdas/backend/tests/test_errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,18 @@ def test_errors_unhandled_response_error(self):
177177
self.assertEqual(issue.get("severity"), errors.Severity.error)
178178
self.assertEqual(issue.get("code"), errors.Code.server_error)
179179
self.assertEqual(issue.get("diagnostics"), f"{test_message}\n{test_response}")
180+
181+
def test_errors_invalid_stored_data_error(self):
182+
"""Test correct operation of UnhandledResponseError"""
183+
test_data_type = "test_data_type"
184+
185+
with self.assertRaises(errors.InvalidStoredDataError) as context:
186+
raise errors.InvalidStoredDataError(test_data_type)
187+
188+
self.assertEqual(str(context.exception), f"Invalid data stored for immunization record: {test_data_type}")
189+
outcome = context.exception.to_operation_outcome()
190+
self.assert_operation_outcome(outcome)
191+
issue = outcome.get("issue")[0]
192+
self.assertEqual(issue.get("severity"), errors.Severity.error)
193+
self.assertEqual(issue.get("code"), errors.Code.server_error)
194+
self.assertEqual(issue.get("diagnostics"), f"Invalid data stored for immunization record: {test_data_type}")

lambdas/shared/src/common/models/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def to_operation_outcome(self) -> dict:
8383

8484

8585
@dataclass
86-
class InconsistentResourceVersion(ApiValidationError):
86+
class InconsistentResourceVersionError(ApiValidationError):
8787
"""Use this when the resource version in the request and actual resource version do not match"""
8888

8989
message: str

lambdas/shared/src/common/models/utils/validation_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fhir.resources.R4B.identifier import Identifier
44

55
from common.models.constants import Constants, Urls
6-
from common.models.errors import InconsistentIdentifierError, InconsistentResourceVersion, MandatoryError
6+
from common.models.errors import InconsistentIdentifierError, InconsistentResourceVersionError, MandatoryError
77
from common.models.field_names import FieldNames
88
from common.models.obtain_field_value import ObtainFieldValue
99
from common.models.utils.base_utils import obtain_field_location
@@ -106,12 +106,12 @@ def validate_resource_versions_match(
106106
"""Checks if the resource version in the request and the resource version of the actual Immunization record matches.
107107
Raises a InconsistentResourceVersion if they do not match."""
108108
if actual_resource_version > resource_version_in_request:
109-
raise InconsistentResourceVersion(
109+
raise InconsistentResourceVersionError(
110110
f"Validation errors: The requested immunization resource {imms_id} has changed since the last retrieve."
111111
)
112112

113113
if actual_resource_version < resource_version_in_request:
114-
raise InconsistentResourceVersion(
114+
raise InconsistentResourceVersionError(
115115
f"Validation errors: The requested immunization resource {imms_id} version is inconsistent with the "
116116
f"existing version."
117117
)

lambdas/shared/tests/test_common/models/utils/test_validation_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fhir.resources.R4B.identifier import Identifier
55
from jsonpath_ng.ext import parse
66

7-
from common.models.errors import InconsistentIdentifierError, InconsistentResourceVersion
7+
from common.models.errors import InconsistentIdentifierError, InconsistentResourceVersionError
88
from common.models.fhir_immunization import ImmunizationValidator
99
from common.models.obtain_field_value import ObtainFieldValue
1010
from common.models.utils.generic_utils import (
@@ -299,7 +299,7 @@ def test_validate_resource_versions_match_raises_error_when_versions_do_not_matc
299299

300300
for actual_version, expected_error in test_cases:
301301
with self.subTest(actual_version=actual_version, expected_error=expected_error):
302-
with self.assertRaises(InconsistentResourceVersion) as error:
302+
with self.assertRaises(InconsistentResourceVersionError) as error:
303303
validate_resource_versions_match(3, actual_version, "12345-id")
304304

305305
self.assertEqual(str(error.exception), expected_error)

lambdas/shared/tests/test_common/test_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def test_errors_inconsistent_resource_version(self):
101101
"""Test correct operation of InconsistentResourceVersion"""
102102
test_message = "test_message"
103103

104-
with self.assertRaises(errors.InconsistentResourceVersion) as context:
105-
raise errors.InconsistentResourceVersion(test_message)
104+
with self.assertRaises(errors.InconsistentResourceVersionError) as context:
105+
raise errors.InconsistentResourceVersionError(test_message)
106106
self.assertEqual(context.exception.message, test_message)
107107

108108
outcome = context.exception.to_operation_outcome()

0 commit comments

Comments
 (0)