Skip to content

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

Increase test coverage

Adam Janik6e16fab9bf25
diff --git a/tests/api/test_core.py b/tests/api/test_core.py
index 4e7bd768b1..b14dd232e1 100644
--- a/tests/api/test_core.py
+++ b/tests/api/test_core.py
@@ -1,5 +1,5 @@
import json
-from unittest.mock import Mock, patch
+from unittest.mock import Mock
import graphene
from django.conf import settings
@@ -12,6 +12,7 @@ from saleor.core.permissions import MODELS_PERMISSIONS
from saleor.graphql.core.utils import clean_seo_fields, snake_to_camel_case
from saleor.graphql.product import types as product_types
from saleor.graphql.utils import get_database_id
+
from .utils import assert_no_permission
@@ -251,3 +252,30 @@ def test_get_database_id(product):
def test_snake_to_camel_case():
assert snake_to_camel_case('test_camel_case') == 'testCamelCase'
assert snake_to_camel_case('testCamel_case') == 'testCamelCase'
+ assert snake_to_camel_case(123) == 123
+
+
+def test_mutation_returns_error_field_in_camel_case(admin_api_client, variant):
+ # costPrice is snake case variable (cost_price) in the backend
+ query = """
+ mutation testCamel($id: ID!, $cost: Decimal) {
+ productVariantUpdate(id: $id,
+ input: {costPrice: $cost, trackInventory: false}) {
+ errors {
+ field
+ message
+ }
+ productVariant {
+ id
+ }
+ }
+ }
+ """
+ variables = json.dumps({
+ 'id': graphene.Node.to_global_id('ProductVariant', variant.id),
+ 'cost': '12.1234'})
+ response = admin_api_client.post(
+ reverse('api'), {'query': query, 'variables': variables})
+ content = get_graphql_content(response)
+ error = content['data']['productVariantUpdate']['errors'][0]
+ assert error['field'] == 'costPrice'