Skip to content

Commit e4e7b4b

Browse files
authored
Merge pull request #192 from Kilo59/no-locations-data-404
No locations data 404
2 parents 573d45e + d464351 commit e4e7b4b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

app/router/locations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from fastapi import Request
1+
from fastapi import HTTPException, Request
22

33
from ..enums.sources import Sources
44
from ..models.location import LocationResponse as Location
@@ -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: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,23 @@ def tearDown(self):
120120

121121

122122
@pytest.mark.parametrize(
123-
"query_params",
123+
"query_params,expected_status",
124124
[
125-
{"source": "csbs"},
126-
{"source": "jhu"},
127-
{"timelines": True},
128-
{"timelines": "true"},
129-
{"timelines": 1},
130-
{"source": "jhu", "timelines": True},
125+
({"source": "csbs"}, 200),
126+
({"source": "jhu"}, 200),
127+
({"timelines": True}, 200),
128+
({"timelines": "true"}, 200),
129+
({"timelines": 1}, 200),
130+
({"source": "jhu", "timelines": True}, 200),
131+
({"source": "csbs", "country_code": "US"}, 200),
132+
({"source": "jhu", "country_code": "US"}, 404),
131133
],
132134
)
133-
def test_locations_status_code(api_client, query_params):
135+
def test_locations_status_code(api_client, query_params, expected_status):
134136
response = api_client.get("/v2/locations", params=query_params)
135137
print(f"GET {response.url}\n{response}")
136-
assert response.status_code == 200
138+
print(f"\tjson:\n{pf(response.json())[:1000]}\n\t...")
139+
assert response.status_code == expected_status
137140

138141

139142
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)