def test_smallest_area(self): now = util.utcnow() area = CellAreaFactory(radius=25000, num_cells=8) area2 = CellAreaFactory(radius=30000, lat=area.lat + 0.2, num_cells=6) self.session.flush() query = self.model_query(cells=[area, area2]) results = self.source.search(query) self.check_model_results(results, [area]) self.assertAlmostEqual(results.best().score, area.score(now), 4)
def test_multiple_mcc(self): now = util.utcnow() region = GEOCODER.regions_for_mcc(235, metadata=True)[0] cell = CellAreaFactory(mcc=234, num_cells=6) cell2 = CellAreaFactory(mcc=235, num_cells=8) self.session.flush() query = self.model_query(cells=[cell, cell2]) results = self.source.search(query) self.assertTrue(len(results) > 2) best_result = results.best(query.expected_accuracy) self.assertEqual(best_result.region_code, region.code) self.assertAlmostEqual(best_result.score, 1.25 + cell.score(now), 4)
def test_multiple_mcc(self): now = util.utcnow() region = GEOCODER.regions_for_mcc(235, metadata=True)[0] cell = CellAreaFactory(mcc=234, num_cells=6) cell2 = CellAreaFactory(mcc=235, num_cells=8) self.session.flush() query = self.model_query(cells=[cell, cell2]) results = self.source.search(query) self.assertTrue(len(results) > 2) best_result = results.best() self.assertEqual(best_result.region_code, region.code) self.assertAlmostEqual(best_result.score, 1.25 + cell.score(now), 4)
def test_smallest_area(self, geoip_db, http_session, session, source, stats): now = util.utcnow() area = CellAreaFactory(radius=25000, num_cells=8) area2 = CellAreaFactory(radius=30000, lat=area.lat + 0.2, num_cells=6) session.flush() query = self.model_query( geoip_db, http_session, session, stats, cells=[area, area2]) results = source.search(query) self.check_model_results(results, [area]) assert results.best().score == area.score(now)
def test_ambiguous_mcc(self): now = util.utcnow() regions = GEOCODER.regions_for_mcc(234, metadata=True) cell = CellAreaFactory(mcc=234, num_cells=10) self.session.flush() query = self.model_query(cells=[cell]) results = self.source.search(query) self.check_model_results(results, regions) self.assertEqual(results.best().region_code, 'GB') for result in results: score = 0.25 if result.region_code == 'GB': score += cell.score(now) self.assertAlmostEqual(result.score, score, 4) self.check_stats(counter=[ (self.api_type + '.source', ['key:test', 'region:none', 'source:internal', 'accuracy:low', 'status:hit']), ])