Skip to content

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

Add tests for CheckoutShippingMethodUpdate mutation

Pacu26703cefcbdd8
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 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 mutations
checkout = graphene.Field(Checkout, description='An updated checkout')
class Arguments:
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 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 future
payment = 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 future
payment = obj.get_last_payment()
if payment:
return payment.captured_amount
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 8cda6c9db0..21b25c89ee 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -16,6 +16,21 @@ from .models import PaymentMethod, Transaction
logger = 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.py
index 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 graphene
import pytest
+from tests.api.utils import get_graphql_content
-import graphene
from saleor.checkout.models import Cart
from saleor.order.models import Order
from saleor.payment import TransactionType
-from tests.api.utils import get_graphql_content
def 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)