Skip to content
Open
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
2 changes: 1 addition & 1 deletion googlemaps/addressvalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def addressvalidation(client, addressLines, regionCode=None , locality=None, ena
if locality is not None:
params["address"]["locality"] = locality

if enableUspsCass is not False or enableUspsCass is not None:
if enableUspsCass is not None:
params["enableUspsCass"] = enableUspsCass

return client._request("/v1:validateAddress", {}, # No GET params
Expand Down
56 changes: 39 additions & 17 deletions tests/test_addressvalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

"""Tests for the addressvalidation module."""

import json

import responses

import googlemaps
Expand All @@ -29,20 +31,40 @@ def setUp(self):
self.key = "AIzaSyD_sJl0qMA65CYHMBokVfMNA7AKyt5ERYs"
self.client = googlemaps.Client(self.key)

@responses.activate
def test_simple_addressvalidation(self):
responses.add(
responses.POST,
"https://addressvalidation.googleapis.com/v1:validateAddress",
body='{"address": {"regionCode": "US","locality": "Mountain View","addressLines": "1600 Amphitheatre Pkwy"},"enableUspsCass":true}',
status=200,
content_type="application/json",
)

results = self.client.addressvalidation('1600 Amphitheatre Pk', regionCode='US', locality='Mountain View', enableUspsCass=True)

self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://addressvalidation.googleapis.com/v1:validateAddress?" "key=%s" % self.key,
responses.calls[0].request.url,
)
def test_enable_usps_cass_serialization(self):
endpoint = "https://addressvalidation.googleapis.com/v1:validateAddress"
address = {
"addressLines": ["1600 Amphitheatre Parkway"],
"regionCode": "US",
"locality": "Mountain View",
}
cases = [
({}, {"address": address}),
({"enableUspsCass": True}, {
"address": address, "enableUspsCass": True,
}),
({"enableUspsCass": False}, {
"address": address, "enableUspsCass": False,
}),
]
for kwargs, expected in cases:
with self.subTest(kwargs=kwargs):
with responses.RequestsMock() as http:
http.add(
responses.POST,
endpoint,
json={"result": {}},
status=200,
)

self.client.addressvalidation(
address["addressLines"],
regionCode=address["regionCode"],
locality=address["locality"],
**kwargs
)

request = http.calls[0].request
self.assertURLEqual("%s?key=%s" % (endpoint, self.key), request.url)
body = json.loads(request.body)
self.assertEqual(expected, body)
Loading