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 25, 2022
1 parent 36beb6b commit 1f1e111
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ def create_case_if_valid(self, maybe_case: dict):
"""Attempts to create a case from an input dictionary and validate it against
the application rules. Raises ValidationError or PreconditionUnsatisfiedError on invalid input.
Raises DependencyFailedError if it has to geocode a case and the location service fails."""
if 'location' in maybe_case:
loc = maybe_case['location']
if 'query' in loc:
features = self.geocoder.locate_feature(loc['query'])
if "location" in maybe_case:
loc = maybe_case["location"]
if "query" in loc:
features = self.geocoder.locate_feature(loc["query"])
feature = features[0]
else:
# if you aren't asking for a query, you must be telling me what it is
Expand Down
6 changes: 5 additions & 1 deletion data-serving/reusable-data-service/data_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ def set_up_controllers():
location_service_base = os.environ.get("LOCATION_SERVICE")
if location_service_base is None:
raise ValueError("Define $LOCATION_SERVICE in the environment")
case_controller = CaseController(store, date.fromisoformat(outbreak_date), geocoder=Geocoder(location_service_base))
case_controller = CaseController(
store,
date.fromisoformat(outbreak_date),
geocoder=Geocoder(location_service_base),
)
schema_controller = SchemaController(store)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
def case_controller():
with app.app_context():
store = MemoryStore()
controller = CaseController(store, outbreak_date=date(2019, 11, 1), geocoder=None)
controller = CaseController(
store, outbreak_date=date(2019, 11, 1), geocoder=None
)
yield controller


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from data_service.model.geojson import Feature, Point
from data_service.stores.memory_store import MemoryStore


class FakeGeocoder:
def __init__(self, ignored_url: str):
self.returned_feature = None
Expand All @@ -20,8 +21,10 @@ def locate_feature(self, query: str) -> List[Feature]:
@pytest.fixture
def case_controller():
store = MemoryStore()
geocoder = FakeGeocoder('https://geocode.example')
controller = CaseController(store, outbreak_date=date(2019, 11, 1), geocoder=geocoder)
geocoder = FakeGeocoder("https://geocode.example")
controller = CaseController(
store, outbreak_date=date(2019, 11, 1), geocoder=geocoder
)
yield controller


Expand All @@ -30,12 +33,12 @@ def test_geocodes_a_case_with_location_query(case_controller):
point = Point()
point.coordinates = [1.234, 5.678]
feature.geometry = point
feature.properties = { "country": "ESP" }
feature.properties = {"country": "ESP"}
case_controller.geocoder.returned_feature = feature

with open("./tests/data/case.minimal.json", "r") as minimal_file:
case_dict = json.load(minimal_file)
case_dict['location'] = { "query": "some_feature" }
case_dict["location"] = {"query": "some_feature"}
case_controller.create_case(case_dict)

cases = case_controller.list_cases().cases
Expand Down

0 comments on commit 1f1e111

Please sign in to comment.