Skip to content

Commit

Permalink
insanity
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Oct 13, 2024
1 parent 0a58c5e commit 1e9c1e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/meshapi/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TestValidationNYCAddressInfo(TestCase):
def test_invalid_state(self):
with self.assertRaises(ValueError):
NYCAddressInfo("151 Broome St", "New York", "ny", 10002)
NYCAddressInfo("151 Broome St", "New York", "ny", "10002")

@patch("meshapi.validation.requests.get")
def test_validate_address_geosearch_unexpected_responses(self, mock_requests):
Expand All @@ -29,12 +29,12 @@ def test_validate_address_geosearch_unexpected_responses(self, mock_requests):
for test_case in test_cases:
with self.assertRaises(test_case["exception"]):
mock_requests.return_value = test_case["mock"]
NYCAddressInfo("151 Broome St", "New York", "NY", 10002)
NYCAddressInfo("151 Broome St", "New York", "NY", "10002")

@patch("meshapi.validation.requests.get", side_effect=Exception("Pretend this is a network issue"))
def test_validate_address_geosearch_network(self, mock_requests):
with self.assertRaises(AddressAPIError):
NYCAddressInfo("151 Broome St", "New York", "NY", 10002)
NYCAddressInfo("151 Broome St", "New York", "NY", "10002")

@patch("meshapi.validation.requests.get")
def test_validate_address_good(self, mock_requests):
Expand All @@ -49,13 +49,13 @@ def test_validate_address_good(self, mock_requests):

mock_requests.side_effect = [mock_1, mock_2, mock_3]

nyc_addr_info = NYCAddressInfo("151 Broome St", "New York", "NY", 10002)
nyc_addr_info = NYCAddressInfo("151 Broome St", "New York", "NY", "10002")

assert nyc_addr_info is not None
assert nyc_addr_info.street_address == "151 Broome St"
assert nyc_addr_info.city == "New York"
assert nyc_addr_info.state == "NY"
assert nyc_addr_info.zip == 10002
assert nyc_addr_info.zip == "10002"
assert nyc_addr_info.longitude == -73.98492
assert nyc_addr_info.latitude == 40.716245
assert nyc_addr_info.altitude == 61.0
Expand Down Expand Up @@ -96,13 +96,13 @@ def test_validate_address_open_data_invalid_response(self, mock_requests):

mock_requests.side_effect = [mock_1, mock_2, mock_test_case]

nyc_addr_info = NYCAddressInfo("151 Broome St", "New York", "NY", 10002)
nyc_addr_info = NYCAddressInfo("151 Broome St", "New York", "NY", "10002")

assert nyc_addr_info is not None
assert nyc_addr_info.street_address == "151 Broome St"
assert nyc_addr_info.city == "New York"
assert nyc_addr_info.state == "NY"
assert nyc_addr_info.zip == 10002
assert nyc_addr_info.zip == "10002"
assert nyc_addr_info.longitude == -73.98492
assert nyc_addr_info.latitude == 40.716245
assert nyc_addr_info.altitude is None
Expand Down
5 changes: 3 additions & 2 deletions src/meshapi/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def __init__(self, street_address: str, city: str, state: str, zip_code: str):
# the closest matching street address it can find, so check that
# the ZIP of what we entered matches what we got.

found_zip = nyc_planning_resp["features"][0]["properties"]["postalcode"]
# For some insane reason this is an integer, so we have to cast it to a string
found_zip = str(nyc_planning_resp["features"][0]["properties"]["postalcode"])
if found_zip != zip_code:
raise AddressError(
f"(NYC) Could not find address '{street_address}, {city}, {state} {zip_code}'. "
Expand All @@ -110,7 +111,7 @@ def __init__(self, street_address: str, city: str, state: str, zip_code: str):

self.city = addr_props["borough"].replace("Manhattan", "New York")
self.state = addr_props["region_a"]
self.zip = addr_props["postalcode"]
self.zip = str(addr_props["postalcode"])

if (
not addr_props.get("addendum", {}).get("pad", {}).get("bin")
Expand Down
4 changes: 4 additions & 0 deletions test-results/.last-run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "failed",
"failedTests": []
}

0 comments on commit 1e9c1e3

Please sign in to comment.