Add a quick ReverseGeocode test to verify that we're getting proper Address objects back from the API.
Sample run output: tyler@grapefruit:~/source/github/pyvirtualearth> VE_USER=XXXXX VE_PASSWORD=XXXX python tests/ReverseGeocode.py [<Address at 0xc92990> confidence=Medium, entityType=Address, displayName=Infinite Loop, Cupertino, California 95014, United States, address={'AddressLine': 'Infinite Loop', 'District': '', 'Locality': 'Cupertino', 'PostalTown': '', 'FormattedAddress': 'Infinite Loop, Cupertino, California 95014, United States', 'PostalCode': '95014', 'AdminDistrict': 'California', 'CountryRegion': 'United States'} , <Address at 0xc929d0> confidence=Medium, entityType=Address, displayName=1 Infinite Loop, Cupertino, CA 95014-2084, address={'AddressLine': '1 Infinite Loop', 'District': '', 'Locality': 'Cupertino', 'PostalTown': '', 'FormattedAddress': '1 Infinite Loop, Cupertino, CA 95014-2084', 'PostalCode': '95014-2084', 'AdminDistrict': 'CA', 'CountryRegion': 'United States'} ] . ---------------------------------------------------------------------- Ran 1 test in 0.734s OK tyler@grapefruit:~/source/github/pyvirtualearth> Signed-off-by: R. Tyler Ballance <tyler@slide.com>
This commit is contained in:
parent
1cba45d540
commit
b1708e069d
11
Geocoder.py
11
Geocoder.py
|
@ -1,9 +1,11 @@
|
|||
|
||||
class Address(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Address, self).__init__(*args, **kwargs)
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s at %s> %s\n' % (self.__class__.__name__, hex(id(self)), ', '.join(['%s=%s' % (k, v) for k, v in self.__dict__.iteritems() if isinstance(self.__dict__[k], basestring) or k == 'address']))
|
||||
|
||||
@classmethod
|
||||
def addressFromSoapResponse(cls, holder):
|
||||
'''
|
||||
|
@ -23,17 +25,16 @@ class Address(object):
|
|||
|
||||
class Geocoder(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Geocoder, self).__init__(*args, **kwargs)
|
||||
self.token = kwargs['token']
|
||||
self.production = kwargs.get('production')
|
||||
|
||||
if kwargs.get('production'):
|
||||
def reverse(self, latitude, longitude, altitude=0):
|
||||
if not self.production:
|
||||
from staging import GeocodeService_client
|
||||
from staging import GeocodeService_types
|
||||
else:
|
||||
from production import GeocodeService_client
|
||||
from production import GeocodeService_types
|
||||
|
||||
def reverse(self, latitude, longitude, altitude=0):
|
||||
locator = GeocodeService_client.GeocodeServiceLocator()
|
||||
service = locator.getBasicHttpBinding_IGeocodeService()
|
||||
request = GeocodeService_client.IGeocodeService_ReverseGeocode_InputMessage()
|
||||
|
|
|
@ -17,6 +17,10 @@ except ImportError:
|
|||
class GetTokenError(Exception):
|
||||
pass
|
||||
|
||||
class OptionsProxy(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def getToken(opts, password):
|
||||
if not opts.production:
|
||||
from staging import CommonService_client
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import unittest
|
||||
|
||||
USER = os.getenv('VE_USER')
|
||||
PASSWORD = os.getenv('VE_PASSWORD')
|
||||
|
||||
import GetToken
|
||||
import Geocoder
|
||||
|
||||
class ReverseGeocodeAppleInc(unittest.TestCase):
|
||||
def setUp(self):
|
||||
opts = GetToken.OptionsProxy(user=USER, clientip='0.0.0.0', tokenvalidity=15, production=False)
|
||||
self.token = GetToken.getToken(opts, PASSWORD)
|
||||
|
||||
def runTest(self):
|
||||
geo = Geocoder.Geocoder(token=self.token)
|
||||
results = geo.reverse(37.3317, -122.031)
|
||||
assert len(results) == 2, (results, 'Expected two entries for Apple, Inc from ReverseGeocode')
|
||||
print results
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue