Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for invalid country code
fowczarekedeb9a996cb2
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.pyindex fda9cf8e35..6492f03cbf 100644--- a/saleor/graphql/utils.py+++ b/saleor/graphql/utils.py@@ -30,14 +30,14 @@ def get_nodes(ids, graphene_type=None):"""pks = []types = []- wrong_ids = []+ invalid_ids = []error_msg = "Could not resolve to a nodes with the global id list of '%s'."for graphql_id in ids:if graphql_id:try:_type, _id = from_global_id(graphql_id)except Exception:- wrong_ids.append(graphql_id)+ invalid_ids.append(graphql_id)else:if graphene_type:assert str(graphene_type) == _type, (@@ -45,9 +45,9 @@ def get_nodes(ids, graphene_type=None):graphene_type._meta.name)pks.append(_id)types.append(_type)- if wrong_ids:+ if invalid_ids:raise GraphQLError(- error_msg % wrong_ids)+ error_msg % invalid_ids)# If `graphene_type` was not provided, check if all resolved types are# the same. This prevents from accidentally mismatching IDs of differentdiff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 6a884c2f82..169c225d24 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -238,23 +238,22 @@ def test_checkout_lines_add_check_lines_quantity(assert data['errors'][0]['field'] == 'quantity'-def test_checkout_lines_wrong_variant_id(+def test_checkout_lines_invalid_variant_id(user_api_client, cart, variant):variant_id = graphene.Node.to_global_id('ProductVariant', variant.pk)- wrong_variant_id = 'WrongId'+ invalid_variant_id = 'InvalidId'checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)variables = {'checkoutId': checkout_id,'lines': [{'variantId': variant_id, 'quantity': 1},- {'wrong_variant_id': variant_id, 'quantity': 3}]}+ {'variantId': invalid_variant_id, 'quantity': 3}]}response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)content = get_graphql_content(response)data = content['data']['checkoutLinesAdd']- error_msg = 'Could not resolve to a nodes with the global id list of {}}.'.format(- [wrong_variant_id])+ error_msg = "Could not resolve to a nodes with the global id list of '%s'." % [invalid_variant_id]assert data['errors'][0]['message'] == error_msgassert data['errors'][0]['field'] == 'variantId'@@ -457,13 +456,7 @@ def test_checkout_customer_detach_without_customer(assert data['errors'][0]['message'] == 'There\'s no customer assigned to this Checkout.'-def test_checkout_shipping_address_update(- user_api_client, cart_with_item, graphql_address_data):- cart = cart_with_item- assert cart.shipping_address is None- checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)-- query = """+MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """mutation checkoutShippingAddressUpdate($checkoutId: ID!, $shippingAddress: AddressInput!) {checkoutShippingAddressUpdate(checkoutId: $checkoutId, shippingAddress: $shippingAddress) {checkout {@@ -475,13 +468,21 @@ def test_checkout_shipping_address_update(message}}- }- """+ }"""+++def test_checkout_shipping_address_update(+ user_api_client, cart_with_item, graphql_address_data):+ cart = cart_with_item+ assert cart.shipping_address is None+ checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)+shipping_address = graphql_address_datavariables = {'checkoutId': checkout_id, 'shippingAddress': shipping_address}- response = user_api_client.post_graphql(query, variables)+ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)content = get_graphql_content(response)data = content['data']['checkoutShippingAddressUpdate']assert not data['errors']@@ -498,6 +499,25 @@ def test_checkout_shipping_address_update(assert cart.shipping_address.city == shipping_address['city']+def test_checkout_shipping_address_update_invalid_country_code(+ user_api_client, cart_with_item, graphql_address_data):+ cart = cart_with_item+ assert cart.shipping_address is None+ checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)++ shipping_address = graphql_address_data+ shipping_address['country'] = 'CODE'+ variables = {+ 'checkoutId': checkout_id, 'shippingAddress': shipping_address}++ response = user_api_client.post_graphql(+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)+ content = get_graphql_content(response)+ data = content['data']['checkoutShippingAddressUpdate']+ assert data['errors'][0]['message'] == 'Invalid country code.'+ assert data['errors'][0]['field'] == 'country'++def test_checkout_billing_address_update(user_api_client, cart_with_item, graphql_address_data):cart = cart_with_item@@ -538,6 +558,7 @@ def test_checkout_billing_address_update(assert cart.billing_address.country == billing_address['country']assert cart.billing_address.city == billing_address['city']+def test_checkout_email_update(user_api_client, cart_with_item):cart = cart_with_itemassert not cart.email