Skip to content

Commit 1b79eba

Browse files
authored
Make enhanced the default for us_street_api (#78)
1 parent ee3a63d commit 1b79eba

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

smartystreets_python_sdk/us_street/client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ def remap_keys(obj):
5858
for lookup in obj:
5959
converted_lookup = {}
6060

61-
if (lookup.match == MatchType.ENHANCED or lookup.match == "enhanced") and lookup.candidates == 0:
62-
add_field(converted_lookup, 'candidates', 5)
63-
else:
61+
# Determine effective match strategy (default to ENHANCED if not specified)
62+
match_strategy = lookup.match
63+
if match_strategy is None:
64+
match_strategy = MatchType.ENHANCED
65+
66+
# Handle candidates
67+
if lookup.candidates > 0:
6468
add_field(converted_lookup, 'candidates', lookup.candidates)
69+
elif match_strategy == MatchType.ENHANCED or match_strategy == "enhanced":
70+
add_field(converted_lookup, 'candidates', 5)
6571

6672
add_field(converted_lookup, 'input_id', lookup.input_id)
6773
add_field(converted_lookup, 'street', lookup.street)
@@ -74,10 +80,13 @@ def remap_keys(obj):
7480
add_field(converted_lookup, 'addressee', lookup.addressee)
7581
add_field(converted_lookup, 'urbanization', lookup.urbanization)
7682
add_field(converted_lookup, 'county_source', lookup.county_source)
77-
if isinstance(lookup.match, MatchType):
78-
add_field(converted_lookup, 'match', lookup.match.value)
79-
else:
80-
add_field(converted_lookup, 'match', lookup.match)
83+
84+
# Only send match parameter if not STRICT
85+
if match_strategy != MatchType.STRICT and match_strategy != "strict":
86+
if isinstance(match_strategy, MatchType):
87+
add_field(converted_lookup, 'match', match_strategy.value)
88+
else:
89+
add_field(converted_lookup, 'match', match_strategy)
8190

8291
if isinstance(lookup.outputformat, OutputFormat):
8392
add_field(converted_lookup, 'format', lookup.outputformat.value)

smartystreets_python_sdk/us_street/lookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Lookup:
66
def __init__(self, street=None, street2=None, secondary=None, city=None, state=None, zipcode=None, lastline=None,
7-
addressee=None, urbanization=None, match=MatchType.STRICT, candidates=0, input_id=None,
7+
addressee=None, urbanization=None, match=None, candidates=0, input_id=None,
88
outputformat=OutputFormat.DEFAULT, county_source=None):
99
"""
1010
In addition to holding all input data for this lookup, this class also will contain the result

test/us_street/client_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,39 @@ def test_full_json_response_deserialization(self):
312312
self.assertEqual(actual_candidate.analysis.components.urbanization.status, "unconfirmed")
313313
self.assertIsNone(actual_candidate.analysis.components.urbanization.change)
314314

315+
def test_default_match_strategy_is_enhanced(self):
316+
sender = RequestCapturingSender()
317+
serializer = FakeDeserializer({})
318+
client = Client(sender, serializer)
319+
lookup = Lookup()
320+
321+
client.send_lookup(lookup)
322+
323+
self.assertEqual('enhanced', sender.request.parameters['match'])
324+
self.assertEqual(5, sender.request.parameters['candidates'])
325+
326+
def test_explicit_match_strict(self):
327+
sender = RequestCapturingSender()
328+
serializer = FakeDeserializer({})
329+
client = Client(sender, serializer)
330+
lookup = Lookup()
331+
lookup.match = MatchType.STRICT
332+
333+
client.send_lookup(lookup)
334+
335+
self.assertNotIn('match', sender.request.parameters)
336+
self.assertNotIn('candidates', sender.request.parameters)
337+
338+
def test_explicit_match_strict_with_candidates(self):
339+
sender = RequestCapturingSender()
340+
serializer = FakeDeserializer({})
341+
client = Client(sender, serializer)
342+
lookup = Lookup()
343+
lookup.match = MatchType.STRICT
344+
lookup.candidates = 3
345+
346+
client.send_lookup(lookup)
347+
348+
self.assertNotIn('match', sender.request.parameters)
349+
self.assertEqual(3, sender.request.parameters['candidates'])
350+

0 commit comments

Comments
 (0)