Skip to content

Commit

Permalink
fix: handle short-hand output spatial reference parameter
Browse files Browse the repository at this point in the history
Fixes #153
  • Loading branch information
stdavis committed Aug 30, 2023
1 parent 599bec0 commit d40b7b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/masquerade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ def get_out_spatial_reference(incoming_request):
"""get the desired output spatial reference from the request"""
out_sr_param_name = "outSR"
if out_sr_param_name in incoming_request.args:
request_wkid = json.loads(incoming_request.args.get(out_sr_param_name))["wkid"]
out_sr_param = incoming_request.args.get(out_sr_param_name)
try:
request_wkid = int(out_sr_param)
except ValueError:
request_wkid = json.loads(out_sr_param)["wkid"]
else:
request_wkid = WGS84

Expand Down
10 changes: 10 additions & 0 deletions tests/test_masquerade.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ def test_batch_can_handle_missing_addresses(test_client):
assert len(response_json["locations"]) == 2
assert response_json["locations"][0]["address"] is None
assert response_json["locations"][1]["address"] is None


def test_can_handle_output_sr_in_numeric_form(test_client):
response = test_client.get(f"{GEOCODE_SERVER_ROUTE}/findAddressCandidates?outSR=4326&singleline:hello")

assert response.status_code == 200

response_json = json.loads(response.data)

assert response_json["spatialReference"]["latestWkid"] == 4326

0 comments on commit d40b7b9

Please sign in to comment.