Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test for permissions using dedicated util helper
Pacu220387fbb7a91
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex ef3ed38321..b801fe59bf 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -28,16 +28,14 @@ def test_voucher_permissions("""# Query to ensure user with no permissions can't see vouchersresponse = staff_api_client.post(reverse('api'), {'query': query})- content = get_graphql_content(response)- message = 'You do not have permission to perform this action'- assert content['errors'][0]['message'] == message+ assert_no_permission(response)# Give staff user proper permissionsstaff_user.user_permissions.add(permission_manage_discounts)# Query againresponse = staff_api_client.post(reverse('api'), {'query': query})- content = get_graphql_content(response)+ get_graphql_content(response)def test_voucher_query(diff --git a/tests/api/utils.py b/tests/api/utils.pyindex 3009f6431e..9ea6e1b69d 100644--- a/tests/api/utils.py+++ b/tests/api/utils.py@@ -3,23 +3,25 @@ import jsonfrom saleor.graphql.core.utils import snake_to_camel_case-def get_graphql_content(response, check_for_errors=True):+def _get_graphql_content_from_response(response):+ return json.loads(response.content.decode('utf8'))+++def get_graphql_content(response):"""Get's GraphQL content from the response, and optionally checks if itcontains any operating-related errors, eg. schema errors or lack ofpermissions."""- content = json.loads(response.content.decode('utf8'))- # We should be always checking for errors, unless one want to test lack- # of permissions- if check_for_errors:- assert 'errors' not in content, content['errors']+ content = _get_graphql_content_from_response(response)+ assert 'errors' not in content, content['errors']return contentdef assert_no_permission(response):- content = get_graphql_content(response)+ content = _get_graphql_content_from_response(response)assert 'errors' in content- assert content['errors'][0]['message'] == 'You do not have permission to perform this action'+ assert content['errors'][0]['message'] == (+ 'You do not have permission to perform this action')def get_multipart_request_body(query, variables, file, file_name):