def test_best(self): us1 = Region(region_code='US', region_name='us', accuracy=200000.0, score=3.0, source=DataSource.geoip) us2 = Region(region_code='US', region_name='us', accuracy=200000.0, score=3.0, source=DataSource.geoip) gb1 = Region(region_code='GB', region_name='gb', accuracy=100000.0, score=5.0, source=DataSource.geoip) gb2 = Region(region_code='GB', region_name='gb', accuracy=100000.0, score=3.0, source=DataSource.geoip) # highest combined score wins assert RegionResultList([us1, gb1]).best().region_code == 'GB' assert RegionResultList([us1, gb1, us2]).best().region_code == 'US' # break tie by accuracy assert RegionResultList([us1, gb2]).best().region_code == 'US'
def test_best(self): us1 = Region( region_code="US", region_name="us", accuracy=200000.0, score=3.0, source=DataSource.geoip, ) us2 = Region( region_code="US", region_name="us", accuracy=200000.0, score=3.0, source=DataSource.geoip, ) gb1 = Region( region_code="GB", region_name="gb", accuracy=100000.0, score=5.0, source=DataSource.geoip, ) gb2 = Region( region_code="GB", region_name="gb", accuracy=100000.0, score=3.0, source=DataSource.geoip, ) # highest combined score wins assert RegionResultList([us1, gb1]).best().region_code == "GB" assert RegionResultList([us1, gb1, us2]).best().region_code == "US" # break tie by accuracy assert RegionResultList([us1, gb2]).best().region_code == "US"
def test_satisfies_fail(self): assert not RegionResultList().satisfies(Query())
def test_satisfies(self): regions = RegionResultList( Region(region_code='DE', region_name='Germany', accuracy=100000.0)) assert regions.satisfies(Query())
def test_best_empty(self): assert RegionResultList().best() is None
def test_repr(self): assert repr(RegionResultList()).startswith('RegionResultList:')
def test_satisfies_fail(self): regions = RegionResultList() self.assertFalse(regions.satisfies(Query()))
def test_satisfies(self): regions = RegionResultList(Region( region_code='DE', region_name='Germany', accuracy=100000.0)) self.assertTrue(regions.satisfies(Query()))
def test_best_empty(self): self.assertTrue(RegionResultList().best() is None)
def test_repr(self): results = RegionResultList() self.assertTrue(repr(results).startswith('RegionResultList:'))
def test_best_result(self): best_result = RegionResultList().best(DataAccuracy.low) self.assertTrue(best_result.empty()) self.assertEqual(type(best_result), Region)