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 27, 2022
1 parent 564f7d3 commit 777e3aa
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 67 deletions.
2 changes: 1 addition & 1 deletion data-serving/reusable-data-service/data_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def add_field_to_case_schema():
req["description"],
req.get("required"),
req.get("default"),
req.get("values")
req.get("values"),
)
return "", 201
except WebApplicationError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ def validate(self):
getter(self).validate()
if field.values is not None:
if value is not None and value not in field.values:
raise ValidationError(f"{field.key} value {value} not in permissible values {field.values}")

raise ValidationError(
f"{field.key} value {value} not in permissible values {field.values}"
)

def _internal_set_value(self, key, value):
self._internal_ensure_containers_exist(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def from_dict(cls, dictionary):
dictionary.get("data_dictionary_text"),
dictionary.get("required"),
dictionary.get("default", None),
dictionary.get("values", None)
dictionary.get("values", None),
)

def python_type(self) -> type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def excluded_cases(self, source_id: str, filter: Filter):
return [
c
for c in self.cases.values()
if c.caseReference.sourceId == source_id
and c.caseStatus == "omit_error"
if c.caseReference.sourceId == source_id and c.caseStatus == "omit_error"
]

def delete_case(self, case_id: str):
Expand Down
96 changes: 42 additions & 54 deletions data-serving/reusable-data-service/tests/test_case_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ def test_get_case_with_known_id(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as case_file:
case_doc = json.load(case_file)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
case_id = (
db["outbreak"]["cases"]
.insert_one(case_doc)
.inserted_id
)
case_id = db["outbreak"]["cases"].insert_one(case_doc).inserted_id
response = client_with_patched_mongo.get(f"/api/cases/{str(case_id)}")
result = response.get_json()
assert response.status_code == 200
Expand Down Expand Up @@ -45,9 +41,7 @@ def test_list_cases_with_pagination_query(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
with open("./tests/data/case.minimal.json") as case_file:
case_doc = json.load(case_file)
db["outbreak"]["cases"].insert_many(
[dict(case_doc) for i in range(25)]
)
db["outbreak"]["cases"].insert_many([dict(case_doc) for i in range(25)])
response = client_with_patched_mongo.get(f"/api/cases?page=2&limit=10")
assert response.status_code == 200
assert len(response.json["cases"]) == 10
Expand All @@ -71,7 +65,7 @@ def test_list_cases_filter_confirmation_date_before(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 32)]
for i in range(1, 32):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
response = client_with_patched_mongo.get(
f"/api/cases?q=dateconfirmedbefore%3a2022-05-10"
Expand All @@ -91,7 +85,7 @@ def test_list_cases_filter_confirmation_date_after(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 32)]
for i in range(1, 32):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
response = client_with_patched_mongo.get(
f"/api/cases?q=dateconfirmedafter%3a2022-05-10"
Expand All @@ -113,7 +107,7 @@ def test_list_cases_filter_confirmation_date_before_and_after(
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 32)]
for i in range(1, 32):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
response = client_with_patched_mongo.get(
f"/api/cases?q=dateconfirmedafter%3a2022-05-10%20dateconfirmedbefore%3a2022-05-13"
Expand All @@ -134,7 +128,7 @@ def test_list_cases_no_matching_results(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 32)]
for i in range(1, 32):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
response = client_with_patched_mongo.get(
f"/api/cases?q=dateconfirmedafter%3a2023-05-10"
Expand Down Expand Up @@ -209,9 +203,7 @@ def test_batch_upsert_case(client_with_patched_mongo):
case_doc = json.load(case_file)
post_response = client_with_patched_mongo.post(
"/api/cases/batchUpsert",
json={
"cases": [case_doc]
},
json={"cases": [case_doc]},
)
assert post_response.status_code == 200
assert post_response.json["errors"] == {}
Expand All @@ -227,7 +219,7 @@ def test_download_all_cases_csv(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 4)]
for i in range(1, 4):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
post_response = client_with_patched_mongo.post(
"/api/cases/download", json={"format": "csv"}
Expand All @@ -243,7 +235,7 @@ def test_download_selected_cases_tsv(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 4)]
for i in range(1, 4):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
db["outbreak"]["cases"].insert_many(cases)
post_response = client_with_patched_mongo.post(
"/api/cases/download",
Expand All @@ -262,7 +254,7 @@ def test_download_selected_cases_tsv(client_with_patched_mongo):
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
cases = [dict(case_doc) for i in range(1, 4)]
for i in range(1, 4):
cases[i-1]["confirmationDate"] = datetime(2022,5,i)
cases[i - 1]["confirmationDate"] = datetime(2022, 5, i)
inserted = db["outbreak"]["cases"].insert_many(cases)
ids = [str(anId) for anId in inserted.inserted_ids]
post_response = client_with_patched_mongo.post(
Expand All @@ -280,11 +272,7 @@ def test_exclude_selected_cases(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as case_file:
case_doc = json.load(case_file)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = (
db["outbreak"]["cases"]
.insert_one(case_doc)
.inserted_id
)
inserted = db["outbreak"]["cases"].insert_one(case_doc).inserted_id
post_response = client_with_patched_mongo.post(
"/api/cases/batchStatusChange",
json={"status": "omit_error", "caseIds": [str(inserted)], "note": "Duplicate"},
Expand All @@ -300,13 +288,11 @@ def test_exclude_selected_cases(client_with_patched_mongo):
def test_excluded_case_ids(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = (
db["outbreak"]["cases"]
.insert_one(case_doc)
.inserted_id
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_one(case_doc).inserted_id
post_response = client_with_patched_mongo.post(
"/api/cases/batchStatusChange",
json={"status": "omit_error", "caseIds": [str(inserted)], "note": "Duplicate"},
Expand All @@ -324,11 +310,13 @@ def test_excluded_case_ids(client_with_patched_mongo):
def test_filter_excluded_case_ids(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
cases = []
for i in range(1,4):
for i in range(1, 4):
this_case = dict(case_doc)
this_case['confirmationDate'] = datetime(2022,5,i)
this_case["confirmationDate"] = datetime(2022, 5, i)
cases.append(this_case)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_many(cases)
Expand All @@ -348,11 +336,7 @@ def test_update_case(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as case_file:
case_doc = json.load(case_file)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = (
db["outbreak"]["cases"]
.insert_one(case_doc)
.inserted_id
)
inserted = db["outbreak"]["cases"].insert_one(case_doc).inserted_id
put_response = client_with_patched_mongo.put(
f"/api/cases/{str(inserted)}", json={"confirmationDate": "2022-05-11"}
)
Expand All @@ -364,11 +348,7 @@ def test_update_object_id_on_case(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = (
db["outbreak"]["cases"]
.insert_one(case_doc)
.inserted_id
)
inserted = db["outbreak"]["cases"].insert_one(case_doc).inserted_id
put_response = client_with_patched_mongo.put(
f"/api/cases/{str(inserted)}",
json={"caseReference": {"sourceId": "fedc1234567890123456789a"}},
Expand All @@ -383,11 +363,13 @@ def test_update_object_id_on_case(client_with_patched_mongo):
def test_batch_update(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
cases = []
for i in range(1,4):
for i in range(1, 4):
this_case = dict(case_doc)
this_case['confirmationDate'] = datetime(2022,5,i)
this_case["confirmationDate"] = datetime(2022, 5, i)
cases.append(this_case)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_many(cases)
Expand All @@ -407,11 +389,13 @@ def test_batch_update(client_with_patched_mongo):
def test_batch_update_query(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
cases = []
for i in range(1,4):
for i in range(1, 4):
this_case = dict(case_doc)
this_case['confirmationDate'] = datetime(2022,5,i)
this_case["confirmationDate"] = datetime(2022, 5, i)
cases.append(this_case)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_many(cases)
Expand Down Expand Up @@ -445,11 +429,13 @@ def test_delete_case_404_on_wrong_id(client_with_patched_mongo):
def test_batch_delete_with_ids(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
cases = []
for i in range(1,4):
for i in range(1, 4):
this_case = dict(case_doc)
this_case['confirmationDate'] = datetime(2022,5,i)
this_case["confirmationDate"] = datetime(2022, 5, i)
cases.append(this_case)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_many(cases)
Expand All @@ -466,11 +452,13 @@ def test_batch_delete_with_ids(client_with_patched_mongo):
def test_batch_delete_with_query(client_with_patched_mongo):
with open("./tests/data/case.excluded.json") as case_file:
case_doc = json.load(case_file)
case_doc['caseReference']['sourceId'] = bson.ObjectId(case_doc['caseReference']['sourceId'])
case_doc["caseReference"]["sourceId"] = bson.ObjectId(
case_doc["caseReference"]["sourceId"]
)
cases = []
for i in range(1,4):
for i in range(1, 4):
this_case = dict(case_doc)
this_case['confirmationDate'] = datetime(2022,5,i)
this_case["confirmationDate"] = datetime(2022, 5, i)
cases.append(this_case)
db = pymongo.MongoClient("mongodb://localhost:27017/outbreak")
inserted = db["outbreak"]["cases"].insert_many(cases)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,16 @@ def test_required_field_becomes_required_in_validation(client_with_patched_mongo
assert response.status_code == 422


def test_field_enumerating_allowed_values_forbids_other_value(client_with_patched_mongo):
def test_field_enumerating_allowed_values_forbids_other_value(
client_with_patched_mongo,
):
response = client_with_patched_mongo.post(
"/api/schema",
json={
"name": "customPathogenStatus",
"type": "string",
"description": "Whether the infection is associated with an endemic or emerging incidence",
"values": [
"Endemic",
"Emerging",
"Unknown"
],
"values": ["Endemic", "Emerging", "Unknown"],
"required": False,
},
)
Expand All @@ -155,7 +153,7 @@ def test_field_enumerating_allowed_values_forbids_other_value(client_with_patche
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
"customPathogenStatus": "Something Else"
"customPathogenStatus": "Something Else",
},
)
assert response.status_code == 422

0 comments on commit 777e3aa

Please sign in to comment.