def test_geocode_nonmock(self): obs = geocode('9500 Gilman Dr, La Jolla, CA') exp = Location('9500 Gilman Dr, La Jolla, CA', 32.8794239, -117.2369135, 105, 'San Diego', 'California', '92093', 'USA') self.assertEqual(obs.input, exp.input) if not config.attempt_geocode: # if we're not attempting to geocode then skip this return self.assertAlmostEqual(obs.lat, exp.lat, delta=0.1) self.assertAlmostEqual(obs.long, exp.long, delta=0.1) # self.assertIsInstance(obs.elev, int) self.assertEqual(obs.city, exp.city) self.assertEqual(obs.state, exp.state) self.assertEqual(obs.postcode, exp.postcode) self.assertEqual(obs.country, exp.country) # Test for unicode obs = geocode('Erlangengatan 12, Sweden') exp = Location('Erlangengatan 12, Sweden', 59.36121550000001, 16.4908829, 38.21769714355469, 'Eskilstuna', u'S\xf6dermanland County', '63227', 'Sweden') self.assertAlmostEqual(obs.lat, exp.lat, delta=0.1) self.assertAlmostEqual(obs.long, exp.long, delta=0.1) self.assertEqual(obs.city, exp.city) self.assertEqual(obs.state, exp.state) self.assertEqual(obs.postcode, exp.postcode) self.assertEqual(obs.country, exp.country)
def test_geocode_bad_address(self): # google always tried to find something, thus make sure this is really # not a word or something that can be matched somehow. loc_name = 'SomeRdfkcmolzscrmilxsrhi,luxrg,zshandomPlace' obs = geocode(loc_name) exp = Location(loc_name, None, None, None, None, None, None, None) self.assertEqual(obs, exp)
def test_geocode_bad_address(self): # do something random to avoid a timeout loc_name = ''.join( [random.choice(string.ascii_letters + " ,") for i in range(50)]) obs = geocode(loc_name) exp = Location(loc_name, None, None, None, None, None, None, None) self.assertEqual(obs, exp)
def test_geocode_nonmock(self): obs = geocode('9500 Gilman Dr, La Jolla, CA') exp = Location('9500 Gilman Dr, La Jolla, CA', 32.8794239, -117.2369135, 114.7895736694336, 'San Diego', 'CA', '92037', 'United States') self.assertEqual(obs.input, exp.input) # almostEqual needed because googleAPI updates for accuracy occasionaly self.assertAlmostEqual(obs.lat, exp.lat, delta=0.1) self.assertAlmostEqual(obs.long, exp.long, delta=0.1) # Google constantly changing elevation, so hard to test # self.assertAlmostEqual(obs.elev, exp.elev, places=1) self.assertIsInstance(obs.elev, float) self.assertEqual(obs.city, exp.city) self.assertEqual(obs.state, exp.state) self.assertEqual(obs.postcode, exp.postcode) self.assertEqual(obs.country, exp.country) # Test for unicode obs = geocode('12 Erlangen') exp = Location('12 Erlangen', 59.36121550000001, 16.4908829, 38.21769714355469, 'Eskilstuna', u'S\xf6dermanlands l\xe4n', '632 30', 'Sweden') self.assertEqual(obs, exp)
def test_geocode_nonmock(self): obs = geocode('9500 Gilman Dr, La Jolla, CA') exp = Location('9500 Gilman Dr, La Jolla, CA', 32.8794239, -117.2369135, 114.7895736694336, 'San Diego', 'CA', '92093', 'United States') self.assertEqual(obs.input, exp.input) # almostEqual needed because googleAPI updates for accuracy occasionaly self.assertAlmostEqual(obs.lat, exp.lat, delta=0.1) self.assertAlmostEqual(obs.long, exp.long, delta=0.1) # Google constantly changing elevation, so hard to test # self.assertAlmostEqual(obs.elev, exp.elev, places=1) self.assertIsInstance(obs.elev, float) self.assertEqual(obs.city, exp.city) self.assertEqual(obs.state, exp.state) self.assertEqual(obs.postcode, exp.postcode) self.assertEqual(obs.country, exp.country) # Test for unicode obs = geocode('12 Erlangen') exp = Location('12 Erlangen', 59.36121550000001, 16.4908829, 38.21769714355469, 'Eskilstuna', u'S\xf6dermanlands l\xe4n', '632 30', 'Sweden') self.assertEqual(obs, exp)
def test_geocode_bad_address(self): obs = geocode('SomeRandomPlace') exp = Location('SomeRandomPlace', None, None, None, None, None, None, None) self.assertEqual(obs, exp)