Beispiel #1
0
class TestGeolocationTaskTestCase(unittest.TestCase):
    """Test GeolocationMixin.get_country_xxx() methods."""

    def setUp(self):
        self.task = GeolocationMixin()
        self.task.geoip = FakeGeoLocation()

    def test_country_name(self):
        name = self.task.get_country_name(FakeGeoLocation.ip_address_1)
        self.assertEquals(name, FakeGeoLocation.country_name_1)

    def test_country_code(self):
        code = self.task.get_country_code(FakeGeoLocation.ip_address_1)
        self.assertEquals(code, FakeGeoLocation.country_code_1)

    def test_country_name_exception(self):
        self.task.geoip.country_name_by_addr = Mock(side_effect=Exception)
        name = self.task.get_country_name(FakeGeoLocation.ip_address_1)
        self.assertEquals(name, UNKNOWN_COUNTRY)

    def test_country_code_exception(self):
        self.task.geoip.country_code_by_addr = Mock(side_effect=Exception)
        code = self.task.get_country_code(FakeGeoLocation.ip_address_1)
        self.assertEquals(code, UNKNOWN_CODE)

    def test_missing_country_name(self):
        self.task.geoip.country_name_by_addr = Mock(return_value=None)
        name = self.task.get_country_name(FakeGeoLocation.ip_address_1)
        self.assertEquals(name, UNKNOWN_COUNTRY)

    def test_missing_country_code(self):
        self.task.geoip.country_code_by_addr = Mock(return_value=None)
        code = self.task.get_country_code(FakeGeoLocation.ip_address_1)
        self.assertEquals(code, UNKNOWN_CODE)

    def test_empty_country_name(self):
        self.task.geoip.country_name_by_addr = Mock(return_value="  ")
        name = self.task.get_country_name(FakeGeoLocation.ip_address_1)
        self.assertEquals(name, UNKNOWN_COUNTRY)

    def test_empty_country_code(self):
        self.task.geoip.country_code_by_addr = Mock(return_value="  ")
        code = self.task.get_country_code(FakeGeoLocation.ip_address_1)
        self.assertEquals(code, UNKNOWN_CODE)
Beispiel #2
0
 def setUp(self):
     self.task = GeolocationMixin()
     self.task.geoip = FakeGeoLocation()