def test_city(self): self.assertTrue(City.exist(["san francisco"], self.redis)) self.assertFalse(City.exist(["ban hranbisco"], self.redis)) locs = City.getByName("san francisco", self.redis) self.assertEquals(1, len(locs)) city = locs[0] score1 = city.score(37.7833, -122.4167) self.assertGreater(score1, 0) # we need a second instance of the city to get a different score because scores are cached city2 = City.getByName("san francisco", self.redis)[0] score2 = city2.score(38.7833, -102.4167) self.assertGreater(score2, 0) self.assertGreater(score1, score2) # test converting to country only info city.toCountry() for k in City.__cityspec__: self.assertEquals(getattr(city, k), None) # test get by radius locs = City.getByRadius(37.7833, -122.4167, 4, self.redis, None, 5) self.assertEqual(5, len(locs)) self.assertEqual(locs[0].name, "San Francisco")
def test_city(self): self.assertTrue(City.exist(['san francisco'], self.redis)) self.assertFalse(City.exist(['ban hranbisco'], self.redis)) locs = City.getByName('san francisco', self.redis) self.assertEquals(1, len(locs)) city = locs[0] score1 = city.score(37.7833, -122.4167) self.assertGreater(score1, 0) # we need a second instance of the city to get a different score because scores are cached city2 = City.getByName('san francisco', self.redis)[0] score2 = city2.score(38.7833, -102.4167) self.assertGreater(score2, 0) self.assertGreater(score1, score2) #test converting to country only info city.toCountry() for k in City.__cityspec__: self.assertEquals(getattr(city,k), None) #test get by radius locs = City.getByRadius(37.7833, -122.4167, 4, self.redis, None, 5) self.assertEqual(5, len(locs)) self.assertEqual(locs[0].name, 'San Francisco')
def test5_resolve_by_textual_search(self): locs = City.getByName("san francisco", self.redis, 44.0462, -123.022, "united states") self.assertGreater(len(locs), 0) self.assertEqual(locs[0].country, "United States") self.assertEqual(locs[0].name, "San Francisco") self.assertEqual(locs[0].state, "California") locs = City.getByName("san francisco", self.redis) self.assertGreater(len(locs), 0) self.assertEqual(locs[0].country, "United States") self.assertEqual(locs[0].name, "San Francisco") self.assertEqual(locs[0].state, "California")
def test5_resolve_by_textual_search(self): locs = City.getByName('san francisco', self.redis, 44.0462, -123.022, 'united states') self.assertGreater(len(locs), 0) self.assertEqual(locs[0].country, 'United States') self.assertEqual(locs[0].name, 'San Francisco') self.assertEqual(locs[0].state, 'California') locs = City.getByName('san francisco', self.redis) self.assertGreater(len(locs), 0) self.assertEqual(locs[0].country, 'United States') self.assertEqual(locs[0].name, 'San Francisco') self.assertEqual(locs[0].state, 'California')
def test4_resolve_by_coords(self): loc = City.getByLatLon(34.05223, -118.24368, self.redis) self.assertIsNotNone(loc) self.assertEqual(loc.country, "United States") self.assertIn(loc.state, ("CA", "California"))
def test4_resolve_by_coords(self): loc = City.getByLatLon(34.05223, -118.24368, self.redis) self.assertIsNotNone(loc) self.assertEqual(loc.country, 'United States') self.assertIn(loc.state, ('CA', 'California'))
def benchResolveCoords(num): coords = [(-3.03333, 53.47778), (40.7226, -74.66544), (31.78199, 35.2196), (0, 0), (45, 45)] r = redis.Redis() ncoords = len(coords) for i in range(num): lat, lon = coords[i % ncoords] loc = City.getByLatLon(lat, lon, r) return num