From 79a3d302dedf1e85ff85f3604daad0bd515b1c40 Mon Sep 17 00:00:00 2001 From: Graham Lee Date: Thu, 7 Jul 2022 10:51:14 +0100 Subject: [PATCH] Run black #2714 --- .../model/case_exclusion_metadata.py | 1 + .../data_service/model/case_reference.py | 2 +- .../data_service/model/document.py | 1 + .../data_service/stores/mongo_store.py | 23 +++++++++++-------- .../tests/test_case_controller.py | 4 +++- .../tests/test_case_end_to_end.py | 1 + 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/data-serving/reusable-data-service/data_service/model/case_exclusion_metadata.py b/data-serving/reusable-data-service/data_service/model/case_exclusion_metadata.py index bd63b072b..97c7d8a5a 100644 --- a/data-serving/reusable-data-service/data_service/model/case_exclusion_metadata.py +++ b/data-serving/reusable-data-service/data_service/model/case_exclusion_metadata.py @@ -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.""" diff --git a/data-serving/reusable-data-service/data_service/model/case_reference.py b/data-serving/reusable-data-service/data_service/model/case_reference.py index bf0c0b519..5786c43f4 100644 --- a/data-serving/reusable-data-service/data_service/model/case_reference.py +++ b/data-serving/reusable-data-service/data_service/model/case_reference.py @@ -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 diff --git a/data-serving/reusable-data-service/data_service/model/document.py b/data-serving/reusable-data-service/data_service/model/document.py index f7a2693b1..fb756d9fb 100644 --- a/data-serving/reusable-data-service/data_service/model/document.py +++ b/data-serving/reusable-data-service/data_service/model/document.py @@ -5,6 +5,7 @@ from typing import List + @dataclasses.dataclass class Document: """The base class for anything that's going into the database.""" diff --git a/data-serving/reusable-data-service/data_service/stores/mongo_store.py b/data-serving/reusable-data-service/data_service/stores/mongo_store.py index c4c07400e..556dd8c7b 100644 --- a/data-serving/reusable-data-service/data_service/stores/mongo_store.py +++ b/data-serving/reusable-data-service/data_service/stores/mongo_store.py @@ -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 = [ @@ -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 @@ -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) diff --git a/data-serving/reusable-data-service/tests/test_case_controller.py b/data-serving/reusable-data-service/tests/test_case_controller.py index d142f3273..968d471b5 100644 --- a/data-serving/reusable-data-service/tests/test_case_controller.py +++ b/data-serving/reusable-data-service/tests/test_case_controller.py @@ -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 diff --git a/data-serving/reusable-data-service/tests/test_case_end_to_end.py b/data-serving/reusable-data-service/tests/test_case_end_to_end.py index a50eaf27e..7960eca18 100644 --- a/data-serving/reusable-data-service/tests/test_case_end_to_end.py +++ b/data-serving/reusable-data-service/tests/test_case_end_to_end.py @@ -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