Skip to content

Commit

Permalink
Case can be created if it has a confirmation date #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jun 17, 2022
1 parent c9ef37d commit b6876b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def from_json(cls, obj: str) -> type:
case = cls()
source = json.loads(obj)
for key in source:
setattr(case, key, source[key])
if key in ['confirmation_date']:
# parse as an ISO 8601 date
date = datetime.datetime.strptime(source[key], '%Y-%m-%dT%H:%M:%S.%fZ')
setattr(case, key, date)
else:
setattr(case, key, source[key])
case.validate()
return case

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"confirmation_date": "2021-12-31T01:23:45.678Z"
}
5 changes: 5 additions & 0 deletions data-serving/reusable-data-service/tests/test_case_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
def test_instantiating_case_from_empty_json_is_error():
with pytest.raises(ValueError):
case = Case.from_json('{}')

def test_case_from_minimal_json_is_valid():
with open('./tests/data/case.minimal.json', 'r') as minimal_file:
case = Case.from_json(minimal_file.read())
assert case is not None

0 comments on commit b6876b3

Please sign in to comment.