Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests for CheckoutShippingMethodUpdate mutation
Pacu26703cefcbdd8
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 0baa1ffc5e..7bc009edd7 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -362,7 +362,6 @@ class CheckoutEmailUpdate(BaseMutation):class CheckoutShippingMethodUpdate(BaseMutation):- # FIXME test this mutationscheckout = graphene.Field(Checkout, description='An updated checkout')class Arguments:diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 3967e9e325..24f90ded56 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -208,7 +208,7 @@ class Order(CountableDjangoObjectType):@staticmethod@gql_optimizer.resolver_hints(prefetch_related='payments')def resolve_total_authorized(obj, info):- # FIXME adjust to multiple payments+ # FIXME adjust to multiple payments in the futurepayment = obj.get_last_payment()if payment:return payment.total.gross@@ -216,7 +216,7 @@ class Order(CountableDjangoObjectType):@staticmethod@gql_optimizer.resolver_hints(prefetch_related='payments')def resolve_total_captured(obj, info):- # FIXME adjust to multiple payments+ # FIXME adjust to multiple payments in the futurepayment = obj.get_last_payment()if payment:return payment.captured_amountdiff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 8cda6c9db0..21b25c89ee 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -16,6 +16,21 @@ from .models import PaymentMethod, Transactionlogger = logging.getLogger(__name__)+def get_billing_data(order):+ data = {}+ if order.billing_address:+ data = {+ 'billing_first_name': order.billing_address.first_name,+ 'billing_last_name': order.billing_address.last_name,+ 'billing_address_1': order.billing_address.street_address_1,+ 'billing_address_2': order.billing_address.street_address_2,+ 'billing_city': order.billing_address.city,+ 'billing_postal_code': order.billing_address.postal_code,+ 'billing_country_code': order.billing_address.country,+ 'billing_country_area': order.billing_address.country_area}+ return data++def handle_fully_paid_order(order):order.events.create(type=OrderEvents.ORDER_FULLY_PAID.value)if order.get_user_current_email():diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 75ea124202..fc82716f33 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -1,12 +1,13 @@import uuid+from unittest.mock import patch, ANY+import grapheneimport pytest+from tests.api.utils import get_graphql_content-import graphenefrom saleor.checkout.models import Cartfrom saleor.order.models import Orderfrom saleor.payment import TransactionType-from tests.api.utils import get_graphql_contentdef test_checkout_create(user_api_client, variant):@@ -512,3 +513,38 @@ def test_checkout_prices(user_api_client, cart_with_item):cart_with_item.get_total().gross.amount)assert data['subtotalPrice']['gross']['amount'] == (cart_with_item.get_subtotal().gross.amount)+++@patch('saleor.graphql.checkout.mutations.clean_shipping_method')+def test_checkout_shipping_method_update(+ mock_clean_shipping, staff_api_client, shipping_method,+ cart_with_item, sale, vatlayer):+ query = """+ mutation checkoutShippingMethodUpdate($checkoutId:ID!, $shippingMethodId:ID!){+ checkoutShippingMethodUpdate(+ checkoutId:$checkoutId, shippingMethodId:$shippingMethodId) {+ errors {+ field+ message+ }+ checkout {+ id+ }+ }+ }+ """+ checkout = cart_with_item+ checkout_id = graphene.Node.to_global_id('Checkout', checkout.pk)+ method_id = graphene.Node.to_global_id(+ 'ShippingMethod', shipping_method.id)+ variables = {'checkoutId': checkout_id, 'shippingMethodId': method_id}+ response = staff_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content['data']['checkoutShippingMethodUpdate']+ assert not data['errors']+ assert data['checkout']['id'] == checkout_id++ checkout.refresh_from_db()+ assert checkout.shipping_method == shipping_method+ mock_clean_shipping.assert_called_once_with(+ checkout, shipping_method, [], ANY, ANY)