Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/router/locations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import Request
from fastapi import HTTPException, Request

from ..enums.sources import Sources
from ..models.location import LocationResponse as Location
Expand Down Expand Up @@ -39,6 +39,8 @@ def get_locations(
locations = [location for location in locations if str(getattr(location, key)).lower() == str(value)]
except AttributeError:
pass
if not locations:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be moved outside of the loop?

raise HTTPException(404, detail=f"Source `{source}` does not have the desired location data.")

# Return final serialized data.
return {
Expand Down
21 changes: 12 additions & 9 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,23 @@ def tearDown(self):


@pytest.mark.parametrize(
"query_params",
"query_params,expected_status",
[
{"source": "csbs"},
{"source": "jhu"},
{"timelines": True},
{"timelines": "true"},
{"timelines": 1},
{"source": "jhu", "timelines": True},
({"source": "csbs"}, 200),
({"source": "jhu"}, 200),
({"timelines": True}, 200),
({"timelines": "true"}, 200),
({"timelines": 1}, 200),
({"source": "jhu", "timelines": True}, 200),
({"source": "csbs", "country_code": "US"}, 200),
({"source": "jhu", "country_code": "US"}, 404),
],
)
def test_locations_status_code(api_client, query_params):
def test_locations_status_code(api_client, query_params, expected_status):
response = api_client.get("/v2/locations", params=query_params)
print(f"GET {response.url}\n{response}")
assert response.status_code == 200
print(f"\tjson:\n{pf(response.json())[:1000]}\n\t...")
assert response.status_code == expected_status


@pytest.mark.parametrize(
Expand Down