Beispiel #1
0
    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'
Beispiel #2
0
    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"
Beispiel #3
0
 def test_satisfies_fail(self):
     assert not RegionResultList().satisfies(Query())
Beispiel #4
0
 def test_satisfies(self):
     regions = RegionResultList(
         Region(region_code='DE', region_name='Germany', accuracy=100000.0))
     assert regions.satisfies(Query())
Beispiel #5
0
 def test_best_empty(self):
     assert RegionResultList().best() is None
Beispiel #6
0
 def test_repr(self):
     assert repr(RegionResultList()).startswith('RegionResultList:')
Beispiel #7
0
 def test_satisfies_fail(self):
     regions = RegionResultList()
     self.assertFalse(regions.satisfies(Query()))
Beispiel #8
0
 def test_satisfies(self):
     regions = RegionResultList(Region(
         region_code='DE', region_name='Germany', accuracy=100000.0))
     self.assertTrue(regions.satisfies(Query()))
Beispiel #9
0
 def test_satisfies_fail(self):
     regions = RegionResultList()
     self.assertFalse(regions.satisfies(Query()))
Beispiel #10
0
 def test_best_empty(self):
     self.assertTrue(RegionResultList().best() is None)
Beispiel #11
0
 def test_repr(self):
     results = RegionResultList()
     self.assertTrue(repr(results).startswith('RegionResultList:'))
Beispiel #12
0
 def test_best_result(self):
     best_result = RegionResultList().best(DataAccuracy.low)
     self.assertTrue(best_result.empty())
     self.assertEqual(type(best_result), Region)