Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve tests
Adam Janik189daa710a32
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 0b39717345..99cd6e17a1 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -22,7 +22,6 @@ from .discount.types import Sale, Voucherfrom .discount.mutations import (SaleCreate, SaleDelete, SaleUpdate, VoucherCreate, VoucherDelete,VoucherUpdate)-from ..page import models as page_modelsfrom .core.filters import DistinctFilterSetfrom .core.mutations import CreateToken, VerifyTokenfrom .core.resolvers import resolve_shopdiff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 3bd610cb27..c2570e74a7 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -5,6 +5,7 @@ import graphenefrom django.contrib.auth import get_user_modelfrom django.shortcuts import reversefrom tests.utils import get_graphql_content+from .utils import assert_no_permissionfrom saleor.graphql.account.mutations import SetPassword@@ -219,12 +220,6 @@ def test_who_can_see_user(assert content['data']['users']['totalCount'] == model.objects.count()-def assert_no_permission(response):- content = get_graphql_content(response)- assert 'errors' in content- assert content['errors'][0]['message'] == 'You do not have permission to perform this action'--def test_customer_create(admin_api_client, user_api_client):query = """mutation CreateCustomer($email: String, $note: String) {diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex c6a0ec7407..ffbaf2c1d4 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -4,6 +4,7 @@ import grapheneimport pytestfrom django.shortcuts import reversefrom tests.utils import get_graphql_content+from .utils import assert_no_permissionfrom saleor.discount import (DiscountValueType, VoucherApplyToProduct, VoucherType)@@ -135,6 +136,10 @@ def test_create_voucher(user_api_client, admin_api_client):'limit': "1.12"})+ response = user_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ assert_no_permission(response)+response = admin_api_client.post(reverse('api'), {'query': query, 'variables': variables})content = get_graphql_content(response)@@ -174,6 +179,11 @@ def test_update_voucher(user_api_client, admin_api_client, voucher):'id': graphene.Node.to_global_id('Voucher', voucher.id),'code': 'testcode123','discountValueType': DiscountValueType.PERCENTAGE})++ response = user_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ assert_no_permission(response)+response = admin_api_client.post(reverse('api'), {'query': query, 'variables': variables})content = get_graphql_content(response)@@ -183,7 +193,7 @@ def test_update_voucher(user_api_client, admin_api_client, voucher):assert data['discountValueType'] == DiscountValueType.PERCENTAGE.upper()-def test_voucher_delete_mutation(admin_api_client, voucher):+def test_voucher_delete_mutation(user_api_client, admin_api_client, voucher):query = """mutation DeleteVoucher($id: ID!) {voucherDelete(id: $id) {@@ -200,6 +210,11 @@ def test_voucher_delete_mutation(admin_api_client, voucher):"""variables = json.dumps({'id': graphene.Node.to_global_id('Voucher', voucher.id)})++ response = user_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ assert_no_permission(response)+response = admin_api_client.post(reverse('api'), {'query': query, 'variables': variables})content = get_graphql_content(response)diff --git a/tests/api/utils.py b/tests/api/utils.pyindex d21c2e7d03..40244b69bc 100644--- a/tests/api/utils.py+++ b/tests/api/utils.py@@ -1,4 +1,11 @@import json+from tests.utils import get_graphql_content+++def assert_no_permission(response):+ content = get_graphql_content(response)+ assert 'errors' in content+ assert content['errors'][0]['message'] == 'You do not have permission to perform this action'def get_multipart_request_body(query, variables, file, file_name):