def test_rejects_lookups_with_only_country_and_address1(self): sender = MockSender(None) client = Client(sender, None) lookup = Lookup(None, '0') lookup.address1 = '1' self.assertRaises(UnprocessableEntityError, client.send, lookup)
def run(): auth_id = "Your SmartyStreets Auth ID here" auth_token = "Your SmartyStreets Auth Token here" # We recommend storing your secret keys in environment variables instead---it's safer! # auth_id = os.environ['SMARTY_AUTH_ID'] # auth_token = os.environ['SMARTY_AUTH_TOKEN'] credentials = StaticCredentials(auth_id, auth_token) client = ClientBuilder(credentials).build_international_street_api_client() lookup = Lookup("Rua Padre Antonio D'Angelo 121 Casa Verde, Sao Paulo", 'Brazil') lookup.geocode = True # Must be expressly set to get latitude and longitude. candidates = client.send(lookup) # The candidates are also stored in the lookup's 'result' field. first_candidate = candidates[0] print("Address is {}".format(first_candidate.analysis.verification_status)) print("Address precision: {}\n".format(first_candidate.analysis.address_precision)) print(u"First Line: {}".format(first_candidate.address1)) print(u"Second Line: {}".format(first_candidate.address2)) print(u"Third Line: {}".format(first_candidate.address3)) print(u"Fourth Line: {}".format(first_candidate.address4)) print("Latitude: {}".format(first_candidate.metadata.latitude)) print("Longitude: {}".format(first_candidate.metadata.longitude))
def run(): # auth_id = "Your SmartyStreets Auth ID here" # auth_token = "Your SmartyStreets Auth Token here" # We recommend storing your secret keys in environment variables instead---it's safer! auth_id = os.environ['SMARTY_AUTH_ID'] auth_token = os.environ['SMARTY_AUTH_TOKEN'] credentials = StaticCredentials(auth_id, auth_token) # The appropriate license values to be used for your subscriptions # can be found on the Subscription page of the account dashboard. # https://www.smartystreets.com/docs/cloud/licensing client = ClientBuilder(credentials).with_licenses(['international-fake'])\ .build_international_street_api_client() # Documentation for input fields can be found at: # https://smartystreets.com/docs/cloud/international-street-api#http-input-fields lookup = InternationalLookup() lookup.input_id = "ID-8675309" lookup.geocode = True # Must be expressly set to get latitude and longitude. lookup.organization = "John Doe" lookup.address1 = "Rua Padre Antonio D'Angelo 121" lookup.address2 = "Casa Verde" lookup.locality = "Sao Paulo" lookup.administrative_area = "SP" lookup.country = "Brazil" lookup.postal_code = "02516-050" candidates = client.send( lookup ) # The candidates are also stored in the lookup's 'result' field. first_candidate = candidates[0] print("Address is {}".format(first_candidate.analysis.verification_status)) print("Address precision: {}\n".format( first_candidate.analysis.address_precision)) print(u"First Line: {}".format(first_candidate.address1)) print(u"Second Line: {}".format(first_candidate.address2)) print(u"Third Line: {}".format(first_candidate.address3)) print(u"Fourth Line: {}".format(first_candidate.address4)) print("Latitude: {}".format(first_candidate.metadata.latitude)) print("Longitude: {}".format(first_candidate.metadata.longitude))
def test_accepts_lookups_with_enough_info(self): sender = RequestCapturingSender() serializer = FakeSerializer(None) client = Client(sender, serializer) lookup = Lookup() lookup.country = '0' lookup.freeform = '1' client.send(lookup) lookup.freeform = None lookup.address1 = '1' lookup.postal_code = '2' client.send(lookup) lookup.postal_code = None lookup.locality = '3' lookup.administrative_area = '4' client.send(lookup)
def test_sending_freeform_lookup(self): sender = RequestCapturingSender() serializer = FakeDeserializer({}) client = Client(sender, serializer) lookup = Lookup('1', '2') client.send(lookup) self.assertEqual('1', sender.request.parameters['freeform']) self.assertEqual('2', sender.request.parameters['country'])
def test_deserialize_called_with_response_body(self): response = Response('Hello, World!', 0) sender = MockSender(response) deserializer = FakeDeserializer({}) client = Client(sender, deserializer) client.send(Lookup('1', '2')) self.assertEqual(response.payload, deserializer.input)
def test_candidates_correctly_assigned_to_lookup(self): raw_candidates = [{'address1': 'street 1'}, {'address1': 'street 2'}] expected_candidates = [ Candidate(raw_candidates[0]), Candidate(raw_candidates[1]) ] lookup = Lookup('1', '2') sender = MockSender(Response('[]', 0)) deserializer = FakeDeserializer(raw_candidates) client = Client(sender, deserializer) client.send(lookup) self.assertEqual(expected_candidates[0].address1, lookup.result[0].address1) self.assertEqual(expected_candidates[1].address1, lookup.result[1].address1)
def test_empty_lookup_rejected(self): sender = MockSender(None) client = Client(sender, None) self.assertRaises(UnprocessableEntityError, client.send, Lookup())
def test_sending_single_fully_populated_lookup(self): sender = RequestCapturingSender() serializer = FakeDeserializer({}) client = Client(sender, serializer) lookup = Lookup() lookup.country = '0' lookup.geocode = True lookup.language = language_mode.NATIVE lookup.freeform = '1' lookup.address1 = '2' lookup.address2 = '3' lookup.address3 = '4' lookup.address4 = '5' lookup.organization = '6' lookup.locality = '7' lookup.administrative_area = '8' lookup.postal_code = '9' client.send(lookup) self.assertEqual('0', sender.request.parameters['country']) self.assertEqual('true', sender.request.parameters['geocode']) self.assertEqual(language_mode.NATIVE, sender.request.parameters['language']) self.assertEqual('1', sender.request.parameters['freeform']) self.assertEqual('2', sender.request.parameters['address1']) self.assertEqual('3', sender.request.parameters['address2']) self.assertEqual('4', sender.request.parameters['address3']) self.assertEqual('5', sender.request.parameters['address4']) self.assertEqual('6', sender.request.parameters['organization']) self.assertEqual('7', sender.request.parameters['locality']) self.assertEqual('8', sender.request.parameters['administrative_area']) self.assertEqual('9', sender.request.parameters['postal_code'])