Skip to content

Commit 0368880

Browse files
committed
404 for missing location data
1 parent 4db0ae5 commit 0368880

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

app/router/locations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def get_locations(
3939
locations = [location for location in locations if str(getattr(location, key)).lower() == str(value)]
4040
except AttributeError:
4141
pass
42+
if not locations:
43+
raise HTTPException(404, detail=f"Source `{source}` does not have the desired location data.")
4244

4345
# Return final serialized data.
4446
return {

tests/test_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def tearDown(self):
129129
({"timelines": 1}, 200),
130130
({"source": "jhu", "timelines": True}, 200),
131131
({"source": "csbs", "country_code": "US"}, 200),
132-
({"source": "jhu", "country_code": "US"}, 404)
132+
({"source": "jhu", "country_code": "US"}, 404),
133133
],
134134
)
135135
def test_locations_status_code(api_client, query_params, expected_status):
@@ -138,6 +138,7 @@ def test_locations_status_code(api_client, query_params, expected_status):
138138
print(f"\tjson:\n{pf(response.json())[:1000]}\n\t...")
139139
assert response.status_code == expected_status
140140

141+
141142
@pytest.mark.parametrize(
142143
"query_params",
143144
[

0 commit comments

Comments
 (0)