Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tests for geolocalization

Pacu2ff71051f79d9
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
index ae1a8daf27..7471017b83 100644
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -41,7 +41,7 @@ class Domain(graphene.ObjectType):
class Geolocalization(graphene.ObjectType):
country = graphene.Field(
- CountryDisplay, required=True,
+ CountryDisplay,
description='Country of the user acquired by his IP address.')
class Meta:
diff --git a/tests/api/test_shop.py b/tests/api/test_shop.py
index d4c8da3110..86ae16e9f7 100644
--- a/tests/api/test_shop.py
+++ b/tests/api/test_shop.py
@@ -281,3 +281,31 @@ def test_query_default_country(user_api_client, settings):
data = content['data']['shop']['defaultCountry']
assert data['code'] == settings.DEFAULT_COUNTRY
assert data['country'] == 'United States of America'
+
+
+def test_query_geolocalization(user_api_client):
+ query = """
+ query {
+ shop {
+ geolocalization {
+ country {
+ code
+ }
+ }
+ }
+ }
+ """
+ GERMAN_IP = '79.222.222.22'
+ response = user_api_client.post(
+ reverse('api'), {'query': query}, HTTP_X_FORWARDED_FOR=GERMAN_IP)
+ content = get_graphql_content(response)
+ assert 'errors' not in content
+ data = content['data']['shop']['geolocalization']
+ assert data['country']['code'] == 'DE'
+
+ response = user_api_client.post(
+ reverse('api'), {'query': query})
+ content = get_graphql_content(response)
+ assert 'errors' not in content
+ data = content['data']['shop']['geolocalization']
+ assert data['country'] is None