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