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'])
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))