Skip to content

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

Add tests

Michał Sipac10ab0aaa831
diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.py
index 570ae88314..fa0420c261 100644
--- a/saleor/graphql/core/scalars.py
+++ b/saleor/graphql/core/scalars.py
@@ -99,12 +99,12 @@ class UUID(graphene.UUID):
def parse_literal(node):
try:
return super(UUID, UUID).parse_literal(node)
- except ValueError:
- raise GraphQLError(f"Unsuported value: {node.value}")
+ except ValueError as e:
+ raise GraphQLError(str(e))
@staticmethod
def parse_value(value):
try:
return super(UUID, UUID).parse_value(value)
- except ValueError:
- raise GraphQLError(f"Unsuported value: {value}")
+ except ValueError as e:
+ raise GraphQLError(str(e))
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index b585787c30..9de22bb9c9 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -4446,7 +4446,7 @@ def test_create_product_with_weight_input(
query = f"""
mutation createProduct(
$productType: ID!,
- $category: ID!
+ $category: ID!,
$name: String!,
$sku: String,
$basePrice: Decimal!)
diff --git a/tests/api/test_scalars.py b/tests/api/test_scalars.py
new file mode 100644
index 0000000000..ca42400d37
--- /dev/null
+++ b/tests/api/test_scalars.py
@@ -0,0 +1,44 @@
+from tests.api.test_checkout import QUERY_CHECKOUT
+from tests.api.utils import get_graphql_content
+
+
+def test_uuid_scalar_value_passed_as_variable(api_client, checkout):
+ variables = {"token": str(checkout.token)}
+ response = api_client.post_graphql(QUERY_CHECKOUT, variables)
+ content = get_graphql_content(response)
+ assert content["data"]["checkout"]["token"] == str(checkout.token)
+
+
+def test_uuid_scalar_wrong_value_passed_as_variable(api_client, checkout):
+ variables = {"token": "wrong-token"}
+ response = api_client.post_graphql(QUERY_CHECKOUT, variables)
+ content = get_graphql_content(response, ignore_errors=True)
+ assert len(content["errors"]) == 1
+
+
+def test_uuid_scalar_value_passed_in_input(api_client, checkout):
+ token = checkout.token
+ query = f"""
+ query{{
+ checkout(token: "{token}") {{
+ token
+ }}
+ }}
+ """
+ response = api_client.post_graphql(query)
+ content = get_graphql_content(response)
+ assert content["data"]["checkout"]["token"] == str(checkout.token)
+
+
+def test_uuid_scalar_wrong_value_passed_in_input(api_client, checkout):
+ token = "wrong-token"
+ query = f"""
+ query{{
+ checkout(token: "{token}") {{
+ token
+ }}
+ }}
+ """
+ response = api_client.post_graphql(query)
+ content = get_graphql_content(response, ignore_errors=True)
+ assert len(content["errors"]) == 1