Esempio n. 1
0
    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
Esempio n. 2
0
 def test_unknown_city(self):
     accuracy = geoip_accuracy('XX', city=True)
     self.assertEqual(accuracy, GEOIP_CITY_ACCURACY)
Esempio n. 3
0
 def test_unknown_country(self):
     accuracy = geoip_accuracy('XX')
     self.assertEqual(accuracy, GEOIP_COUNTRY_ACCURACY)
Esempio n. 4
0
 def test_tiny_country(self):
     accuracy = geoip_accuracy('VA', city=True)
     self.assertEqual(accuracy, self.va_radius)
Esempio n. 5
0
 def test_small_country(self):
     accuracy = geoip_accuracy('LI', city=True)
     self.assertEqual(accuracy, self.li_radius)
Esempio n. 6
0
 def test_country(self):
     accuracy = geoip_accuracy('US')
     self.assertEqual(accuracy, self.us_radius)
Esempio n. 7
0
 def test_unknown_city(self):
     accuracy = geoip_accuracy('XX', city=True)
     self.assertEqual(accuracy, GEOIP_CITY_ACCURACY)
Esempio n. 8
0
 def test_unknown_country(self):
     accuracy = geoip_accuracy('XX')
     self.assertEqual(accuracy, GEOIP_COUNTRY_ACCURACY)
Esempio n. 9
0
 def test_tiny_country(self):
     accuracy = geoip_accuracy('VA', city=True)
     self.assertEqual(accuracy, self.va_radius)
Esempio n. 10
0
 def test_small_country(self):
     accuracy = geoip_accuracy('LI', city=True)
     self.assertEqual(accuracy, self.li_radius)
Esempio n. 11
0
 def test_country(self):
     accuracy = geoip_accuracy('US')
     self.assertEqual(accuracy, self.us_radius)
Esempio n. 12
0
 def _geoip_result_accuracy(self, geoip):
     # calculate country based accuracy, ignoring city
     return geoip_accuracy(geoip['country_code'])