Skip to content

Commit

Permalink
Run black #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jul 7, 2022
1 parent fbd7760 commit 79a3d30
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from data_service.model.document import Document


@dataclasses.dataclass
class CaseExclusionMetadata(Document):
"""If a case is excluded, record when and why."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def from_dict(d: dict[str, str]):
ref.sourceId = bson.ObjectId(theId["$oid"])
else:
raise ValueError(f"Cannot interpret {theId} as an ObjectId")
ref.status = d["status"] if 'status' in d else 'UNVERIFIED'
ref.status = d["status"] if "status" in d else "UNVERIFIED"
return ref
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from typing import List


@dataclasses.dataclass
class Document:
"""The base class for anything that's going into the database."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ def replace_case(self, id: str, case: Case):
if result.modified_count != 1:
raise ValueError("Did not update any documents!")

def update_case_status(self, id:str, status: str, exclusion: CaseExclusionMetadata):
update = {
"$set": {
"caseReference.status": status
}
}
def update_case_status(
self, id: str, status: str, exclusion: CaseExclusionMetadata
):
update = {"$set": {"caseReference.status": status}}
if exclusion:
update["$set"]["caseExclusion"] = self.case_exclusion_to_bson_compatible_dict(exclusion)
update["$set"][
"caseExclusion"
] = self.case_exclusion_to_bson_compatible_dict(exclusion)
else:
update["$unset"] = { "caseExclusion": True }
self.get_case_collection().update_one({ "_id": ObjectId(id) }, update )
update["$unset"] = {"caseExclusion": True}
self.get_case_collection().update_one({"_id": ObjectId(id)}, update)

def batch_upsert(self, cases: List[Case]) -> Tuple[int, int]:
to_insert = [
Expand Down Expand Up @@ -140,7 +140,9 @@ def case_to_bson_compatible_dict(case: Case):
for field in Case.date_fields():
bson_case[field] = date_to_datetime(bson_case[field])
if case.caseExclusion is not None:
bson_case["caseExclusion"] = MongoStore.case_exclusion_to_bson_compatible_dict(case.caseExclusion)
bson_case[
"caseExclusion"
] = MongoStore.case_exclusion_to_bson_compatible_dict(case.caseExclusion)
return bson_case

@staticmethod
Expand All @@ -151,6 +153,7 @@ def case_exclusion_to_bson_compatible_dict(exclusion: CaseExclusionMetadata):
bson_exclusion[field] = date_to_datetime(bson_exclusion[field])
return bson_exclusion


def date_to_datetime(dt: datetime.date) -> datetime.datetime:
"""Convert datetime.date to datetime.datetime for encoding as BSON"""
return datetime.datetime(dt.year, dt.month, dt.day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def insert_case(self, case: Case):
def replace_case(self, id: str, case: Case):
self.put_case(id, case)

def update_case_status(self, id:str, status: str, exclusion: CaseExclusionMetadata):
def update_case_status(
self, id: str, status: str, exclusion: CaseExclusionMetadata
):
print(f"updating {id} to {status} with {exclusion}")
case = self.case_by_id(id)
case.caseReference.status = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def client_with_patched_mongo(monkeypatch):
monkeypatch.setenv("MONGO_CASE_COLLECTION", "cases")
monkeypatch.setenv("OUTBREAK_DATE", "2019-11-01")
db = mongomock.MongoClient()

def fake_mongo(connection_string):
return db

Expand Down

0 comments on commit 79a3d30

Please sign in to comment.