Beispiel #1
0
    def test_geoip__no_ip(self, mock_get_real_ip):
        mock_get_real_ip.return_value = None

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #2
0
    def test_geoip__no_ip(self, mock_get_real_ip):
        mock_get_real_ip.return_value = None

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #3
0
    def test_country_code_in_session(self):
        country = UKFactory()
        request = self.request_factory.get("/")
        request.user = UserFactory()
        request.session = {"shipping_country": country.iso2_code}

        self.assertEqual(country_for_request(request), country.iso2_code)
Beispiel #4
0
    def test_country_code_in_session(self):
        country = UKFactory()
        request = self.request_factory.get("/")
        request.user = UserFactory()
        request.session = {"shipping_country": country.iso2_code}

        self.assertEqual(country_for_request(request), country.iso2_code)
Beispiel #5
0
 def get(self, request, *args, **kwargs):
     """
     Return the country for the request.
     """
     country_code = country_for_request(request)
     country = Country.objects.get(active=True, iso2_code=country_code)
     serializer = CountrySerializer(country)
     return Response(serializer.data)
Beispiel #6
0
    def test_from_contact(self):
        contact = ContactFactory()
        address = contact.addressbook_set.all()[0]
        address.country = USFactory()
        address.is_default_shipping = True
        address.save()

        request = self.request_factory.get("/")
        request.user = contact.user
        request.session = {}

        self.assertEqual(country_for_request(request), "US")
Beispiel #7
0
    def test_from_contact(self):
        contact = ContactFactory()
        address = contact.addressbook_set.all()[0]
        address.country = USFactory()
        address.is_default_shipping = True
        address.save()

        request = self.request_factory.get("/")
        request.user = contact.user
        request.session = {}

        self.assertEqual(country_for_request(request), "US")
Beispiel #8
0
    def test_geoip__no_country(self, mock_get_real_ip, mock_geoip):
        mock_get_real_ip.return_value = "127.0.0.1"

        class MockGeoIP(object):
            def country(self, ip):
                return {"country_name": None, "country_code": None}

        mock_geoip.return_value = MockGeoIP()

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #9
0
    def test_geoip__no_country(self, mock_get_real_ip, mock_geoip):
        mock_get_real_ip.return_value = "127.0.0.1"

        class MockGeoIP(object):
            def country(self, ip):
                return {"country_name": None, "country_code": None}

        mock_geoip.return_value = MockGeoIP()

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #10
0
    def test_geoip__country_matches_active_country(self, mock_get_real_ip, mock_geoip):
        mock_get_real_ip.return_value = "88.97.34.8"
        uk = UKFactory()
        uk.active = True
        uk.save()

        class MockGeoIP(object):
            def country(self, ip):
                return {"country_name": "United Kingdom", "country_code": "GB"}

        mock_geoip.return_value = MockGeoIP()

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "GB")
Beispiel #11
0
    def test_geoip__country_matches_active_country(self, mock_get_real_ip,
                                                   mock_geoip):
        mock_get_real_ip.return_value = "88.97.34.8"
        uk = UKFactory()
        uk.active = True
        uk.save()

        class MockGeoIP(object):
            def country(self, ip):
                return {"country_name": "United Kingdom", "country_code": "GB"}

        mock_geoip.return_value = MockGeoIP()

        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "GB")
Beispiel #12
0
    def test_geoip__not_set_up(self):
        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #13
0
 def test_no_request(self):
     self.assertEqual(country_for_request(None), "CA")
Beispiel #14
0
 def test_no_request(self):
     self.assertEqual(country_for_request(None), "CA")
Beispiel #15
0
    def test_geoip__not_set_up(self):
        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #16
0
    def test_fallback_to_default(self):
        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")
Beispiel #17
0
    def test_fallback_to_default(self):
        request = self.request_factory.get("/")
        request.session = {}

        self.assertEqual(country_for_request(request), "CA")