Beispiel #1
0
    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'])
Beispiel #2
0
    def test_rejects_lookups_with_only_country_and_address1_and_administrative_area(
            self):
        sender = MockSender(None)
        client = Client(sender, None)
        lookup = Lookup(None, '0')
        lookup.address1 = '1'
        lookup.administrative_area = '2'

        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)

    # 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))
Beispiel #4
0
    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)