Skip to content

Commit

Permalink
Mongo Store correctly uses data model #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jun 20, 2022
1 parent a7bb57c commit c3ab176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pymongo
from reusable_data_service.model.case import Case
from json import loads
from bson.errors import InvalidId
from bson.json_util import dumps
Expand Down Expand Up @@ -28,14 +29,17 @@ def get_case_collection(self):
def case_by_id(self, id: str):
try:
case = self.get_case_collection().find_one({"_id": ObjectId(id)})
# case includes BSON fields like ObjectID - convert into JSON for use by the app
return loads(dumps(case))
if case is not None:
# case includes BSON fields like ObjectID - convert into JSON for use by the app
return Case.from_json(dumps(case))
else:
return None
except InvalidId:
return None

def all_cases(self):
cases = self.get_case_collection().find({})
return loads(dumps(cases))
return [Case.from_json(dumps(c)) for c in cases]

@staticmethod
def setup():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_get_case_with_known_id(client_with_patched_mongo):
result = response.get_json()
assert response.status_code == 200
assert result is not None
assert result["confirmation_date"] == "2021-12-31T01:23:45.678Z"
assert result["confirmation_date"] == "Fri, 31 Dec 2021 00:00:00 GMT"


def test_get_case_with_poorly_formatted_id(client_with_patched_mongo):
Expand Down

0 comments on commit c3ab176

Please sign in to comment.