Skip to content

Commit

Permalink
Merge pull request #47 from smartystreets/xan/fix-url-prefix-bug
Browse files Browse the repository at this point in the history
Fix url prefix bug from retries
  • Loading branch information
XanSmarty authored Mar 21, 2024
2 parents 6ce870e + 8aed3cd commit 76d401b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def build_request(self, lookup):
request = Request()

if lookup.address_id is not None:
request.url_prefix = "/" + lookup.address_id
request.url_components = "/" + lookup.address_id

self.add_parameter(request, 'country', lookup.country)
self.add_parameter(request, 'search', lookup.search)
Expand Down
1 change: 1 addition & 0 deletions smartystreets_python_sdk/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ def __init__(self):
self.parameters = OrderedDict()
self.payload = None
self.url_prefix = None
self.url_components = None
self.referer = None
self.content_type = 'application/json'
5 changes: 2 additions & 3 deletions smartystreets_python_sdk/url_prefix_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ def __init__(self, url_prefix, inner):
self.inner = inner

def send(self, request):
if request.url_prefix is not None:
request.url_prefix = self.url_prefix + request.url_prefix
if request.url_components:
request.url_prefix = self.url_prefix + request.url_components
else:
request.url_prefix = self.url_prefix

return self.inner.send(request)
2 changes: 1 addition & 1 deletion smartystreets_python_sdk/us_enrichment/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def send_lookup(client: Client, lookup):

def build_request(lookup):
request = Request()
request.url_prefix = lookup.smartykey + "/" + lookup.dataset + "/" + lookup.dataSubset
request.url_components = lookup.smartykey + "/" + lookup.dataset + "/" + lookup.dataSubset

return request
2 changes: 1 addition & 1 deletion test/international_autocomplete/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_sending_fully_populated_lookup(self):
self.assertEqual(7, sender.request.parameters['max_results'])
self.assertEqual('3', sender.request.parameters['include_only_locality'])
self.assertEqual('4', sender.request.parameters['include_only_postal_code'])
self.assertEqual('/5', sender.request.url_prefix)
self.assertEqual('/5', sender.request.url_components)

def test_deserialize_called_with_response_body(self):
response = Response('Hello, World!', 0)
Expand Down
12 changes: 11 additions & 1 deletion test/url_prefix_sender_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_request_url_present(self):
fakeSender = FakeSender()
prefix_sender = URLPrefixSender('https://mysite.com', fakeSender)
request = Request()
request.url_prefix = '/jimbo'
request.url_components = '/jimbo'

new_request = prefix_sender.send(request)
self.assertEqual('https://mysite.com/jimbo', new_request.url_prefix)
Expand All @@ -21,6 +21,16 @@ def test_request_url_not_present(self):
new_request = prefix_sender.send(request)
self.assertEqual('https://mysite.com', new_request.url_prefix)

def test_multiple_sends(self):
fakeSender = FakeSender()
prefix_sender = URLPrefixSender('https://mysite.com', fakeSender)
request = Request()
request.url_components = '/jimbo'

new_request = prefix_sender.send(request)
new_request = prefix_sender.send(request)
self.assertEqual('https://mysite.com/jimbo', new_request.url_prefix)

class FakeSender:
def send(self, request):
return request

0 comments on commit 76d401b

Please sign in to comment.