Skip to content

Commit

Permalink
Add sexAtBirth field #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jul 27, 2022
1 parent 83e335d commit 208a551
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
"data_dictionary_text": "Age of the individual, specified as a range, either open-ended (<n, >n) or as a range delimited by a hyphen following 5-year age increments (m-n)",
"required": false
},
{
"key": "sexAtBirth",
"type": "string",
"data_dictionary_text": "Sex at birth of an individual.",
"required": true,
"values": [
"Male",
"Female",
"Unknown",
"other"
]
},
{
"key": "confirmationDate",
"type": "date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"note": "Excluded upon this day, for reasons"
},
"caseStatus": "omit_error",
"pathogenStatus": "endemic"
"pathogenStatus": "endemic",
"sexAtBirth": "Female"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"sourceId": "fedc09876543210987654321"
},
"caseStatus": "probable",
"pathogenStatus": "emerging"
"pathogenStatus": "emerging",
"sexAtBirth": "Female"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
}
},
"caseStatus": "probable",
"pathogenStatus": "unknown"
"pathogenStatus": "unknown",
"sexAtBirth": "Female"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import csv
import io
import json

from tests.end_to_end_fixture import client_with_patched_mongo


def test_adding_field_then_downloading_case(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/schema",
json={
Expand All @@ -14,17 +17,12 @@ def test_adding_field_then_downloading_case(client_with_patched_mongo):
},
)
assert response.status_code == 201

case_doc["mySymptoms"] = "coughs, sneezles"

response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
"mySymptoms": "coughs, sneezles",
},
json=case_doc,
)
assert response.status_code == 201
response = client_with_patched_mongo.get("/api/cases")
Expand All @@ -36,6 +34,8 @@ def test_adding_field_then_downloading_case(client_with_patched_mongo):


def test_adding_field_then_downloading_csv(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/schema",
json={
Expand All @@ -45,17 +45,11 @@ def test_adding_field_then_downloading_csv(client_with_patched_mongo):
},
)
assert response.status_code == 201

case_doc["someField"] = "well, what have we here"
response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
"someField": "well, what have we here",
},
json=case_doc,
)
assert response.status_code == 201
response = client_with_patched_mongo.post(
Expand All @@ -73,16 +67,11 @@ def test_adding_field_then_downloading_csv(client_with_patched_mongo):
def test_required_field_default_value_spread_to_existing_cases(
client_with_patched_mongo,
):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
},
json=case_doc,
)
assert response.status_code == 201
response = client_with_patched_mongo.post(
Expand All @@ -105,6 +94,8 @@ def test_required_field_default_value_spread_to_existing_cases(


def test_required_field_becomes_required_in_validation(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/schema",
json={
Expand All @@ -118,21 +109,16 @@ def test_required_field_becomes_required_in_validation(client_with_patched_mongo
assert response.status_code == 201
response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
},
json=case_doc,
)
assert response.status_code == 422


def test_field_enumerating_allowed_values_forbids_other_value(
client_with_patched_mongo,
):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/schema",
json={
Expand All @@ -144,22 +130,19 @@ def test_field_enumerating_allowed_values_forbids_other_value(
},
)
assert response.status_code == 201

case_doc["customPathogenStatus"] = "Something Else"

response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
"customPathogenStatus": "Something Else",
},
json=case_doc,
)
assert response.status_code == 422


def test_adding_enumerated_field_with_other_value(client_with_patched_mongo):
with open("./tests/data/case.minimal.json") as json_file:
case_doc = json.load(json_file)
response = client_with_patched_mongo.post(
"/api/schema",
json={
Expand All @@ -171,18 +154,12 @@ def test_adding_enumerated_field_with_other_value(client_with_patched_mongo):
},
)
assert response.status_code == 201

case_doc["customPathogenStatus"] = "other"
case_doc["customPathogenStatus_other"] = "Neopanspermia"
response = client_with_patched_mongo.post(
"/api/cases",
json={
"confirmationDate": "2022-06-01T00:00:00.000Z",
"caseReference": {
"status": "UNVERIFIED",
"sourceId": "24680135792468013579fedc",
},
"caseStatus": "probable",
"customPathogenStatus": "other",
"customPathogenStatus_other": "Neopanspermia",
},
json=case_doc,
)
assert response.status_code == 201
response = client_with_patched_mongo.post(
Expand Down

0 comments on commit 208a551

Please sign in to comment.