def search(self, query): results = ResultList() codes = set() for cell in list(query.cell) + list(query.cell_area): codes.add(cell.mcc) countries = [] for code in codes: countries.extend(mobile_codes.mcc(str(code))) for country in countries: country_code = country.alpha2 results.add(self.result_type( country_code=country_code, country_name=country.name, accuracy=geoip_accuracy(country_code))) if len(results): query.emit_source_stats(self.source, results[0]) else: results.add(self.result_type()) return results
def test_unknown_city(self): accuracy = geoip_accuracy('XX', city=True) self.assertEqual(accuracy, GEOIP_CITY_ACCURACY)
def test_unknown_country(self): accuracy = geoip_accuracy('XX') self.assertEqual(accuracy, GEOIP_COUNTRY_ACCURACY)
def test_tiny_country(self): accuracy = geoip_accuracy('VA', city=True) self.assertEqual(accuracy, self.va_radius)
def test_small_country(self): accuracy = geoip_accuracy('LI', city=True) self.assertEqual(accuracy, self.li_radius)
def test_country(self): accuracy = geoip_accuracy('US') self.assertEqual(accuracy, self.us_radius)
def _geoip_result_accuracy(self, geoip): # calculate country based accuracy, ignoring city return geoip_accuracy(geoip['country_code'])