Skip to content

Commit 62861e6

Browse files
committed
[NRL-829] Finish fixup of unit tests
1 parent 3c32399 commit 62861e6

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

layer/nrlf/core/codes.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
from typing import Dict
1+
from typing import ClassVar
22

33
from nrlf.consumer.fhir.r4 import model as consumer_model
44
from nrlf.producer.fhir.r4 import model as producer_model
55

66

7-
class _CodeableConcept(producer_model.CodeableConcept, consumer_model.CodeableConcept):
7+
class _CodeableConcept(producer_model.CodeableConcept, consumer_model.CodeableConcept): # type: ignore
88
"""
99
Represents a codeable concept with a mapping of codes to text values.
1010
"""
1111

12-
_TEXT_MAP: Dict[str, str] = {}
13-
_SYSTEM: str = ""
12+
_TEXT_MAP: ClassVar[dict[str, str]] = {}
13+
_SYSTEM: ClassVar[str] = ""
1414

1515
@classmethod
1616
def from_code(cls, code: str) -> "_CodeableConcept":
1717
"""
1818
Creates a CodeableConcept instance from a given code.
1919
"""
20-
text_map = cls._TEXT_MAP.get_default()
21-
system = cls._SYSTEM.get_default()
22-
23-
if code not in text_map:
20+
if code not in cls._TEXT_MAP:
2421
raise ValueError(f"Unknown code: {code}")
2522

2623
return cls(
2724
coding=[
2825
producer_model.Coding(
29-
system=system,
26+
system=cls._SYSTEM,
3027
code=code,
31-
display=text_map[code],
28+
display=cls._TEXT_MAP[code],
3229
)
3330
]
3431
)

layer/nrlf/core/dynamodb/model.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,22 @@ class DocumentPointer(DynamoDBModel):
7474
document_id: str = Field(exclude=True)
7575
schemas: list = Field(default_factory=list)
7676

77-
def dict(self, **kwargs) -> dict:
77+
def model_dump(self, **kwargs) -> dict:
7878
"""
79-
Override dict() to include partition and sort keys
79+
Override model_dump() to include partition and sort keys
8080
"""
81-
default_dict = super().dict(**kwargs)
81+
default_dict = super().model_dump(**kwargs)
8282
return {
8383
**default_dict,
8484
**self.indexes,
8585
}
8686

87+
def dict(self, **kwargs: dict[str, Any]) -> dict[str, Any]:
88+
"""
89+
Define dict() to do same as model_dump
90+
"""
91+
return self.model_dump(**kwargs)
92+
8793
@classmethod
8894
def from_document_reference(
8995
cls, resource: DocumentReference, created_on: Optional[str] = None

layer/nrlf/core/tests/test_codes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from nrlf.core.codes import NRLResponseConcept, SpineErrorConcept, _CodeableConcept
44

5+
# TODO-NOW Fix up these codes impls to work better in test cases
6+
57

68
def test_from_code_known_code():
79
# Arrange

layer/nrlf/core/tests/test_decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def decorated_function(event, context, config, metadata, body) -> Response:
578578
}
579579
]
580580
},
581-
"diagnostics": "Request body could not be parsed (param1: str type expected)",
581+
"diagnostics": "Request body could not be parsed (param1: Input should be a valid string)",
582582
"expression": ["param1"],
583583
},
584584
{
@@ -593,7 +593,7 @@ def decorated_function(event, context, config, metadata, body) -> Response:
593593
}
594594
],
595595
},
596-
"diagnostics": "Request body could not be parsed (param2: value is not a valid integer)",
596+
"diagnostics": "Request body could not be parsed (param2: Input should be a valid integer, unable to parse string as an integer)",
597597
"expression": ["param2"],
598598
},
599599
],

layer/nrlf/core/tests/test_validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_document_reference_validator_parse_invalid():
174174
}
175175
]
176176
},
177-
"diagnostics": "Failed to parse DocumentReference resource (id: str type expected)",
177+
"diagnostics": "Failed to parse DocumentReference resource (id: Input should be a valid string)",
178178
"expression": ["id"],
179179
}
180180
assert exc.issues[1].model_dump(exclude_none=True) == {
@@ -189,7 +189,7 @@ def test_document_reference_validator_parse_invalid():
189189
}
190190
]
191191
},
192-
"diagnostics": "Failed to parse DocumentReference resource (type: value is not a valid dict)",
192+
"diagnostics": "Failed to parse DocumentReference resource (type: Input should be a valid dictionary or instance of CodeableConcept)",
193193
"expression": ["type"],
194194
}
195195

0 commit comments

Comments
 (0)