Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move test with digital product and checkoutComplete to test_checkout_complete. Fix incorrect mock patchess
Maciej Korycinski58c872f365c1
diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.pyindex e9dda6aa64..bd1f448ab1 100644--- a/saleor/graphql/checkout/tests/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py@@ -536,7 +536,7 @@ def test_checkout_complete_insufficient_stock(assert orders_count == Order.objects.count()-@patch("saleor.graphql.checkout.mutations.gateway.refund")+@patch("saleor.checkout.complete_checkout.gateway.refund")def test_checkout_complete_insufficient_stock_payment_refunded(gateway_refund_mock,checkout_with_item,@@ -586,7 +586,7 @@ def test_checkout_complete_insufficient_stock_payment_refunded(gateway_refund_mock.assert_called_once_with(payment)-@patch("saleor.graphql.checkout.mutations.gateway.void")+@patch("saleor.checkout.complete_checkout.gateway.void")def test_checkout_complete_insufficient_stock_payment_voided(gateway_void_mock,checkout_with_item,@@ -701,7 +701,7 @@ def test_checkout_complete_without_redirect_url().exists(), "Checkout should have been deleted"-@patch("saleor.graphql.checkout.mutations.gateway.payment_refund_or_void")+@patch("saleor.checkout.complete_checkout.gateway.payment_refund_or_void")def test_checkout_complete_payment_payment_total_different_than_checkout(gateway_refund_or_void_mock,checkout_with_items,@@ -801,3 +801,39 @@ def test_create_order_raises_insufficient_stock(payment.refresh_from_db()assert payment.charge_status == ChargeStatus.FULLY_REFUNDED+++def test_checkout_complete_with_digital(+ api_client, checkout_with_digital_item, address, payment_dummy+):+ """Ensure it is possible to complete a digital checkout without shipping."""++ order_count = Order.objects.count()+ checkout = checkout_with_digital_item+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}++ # Set a billing address+ checkout.billing_address = address+ checkout.save(update_fields=["billing_address"])++ # Create a dummy payment to charge+ total = calculations.checkout_total(checkout=checkout, lines=list(checkout))+ payment = payment_dummy+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.checkout = checkout+ payment.save()+ assert not payment.transactions.exists()++ # Send the creation request+ response = api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)+ content = get_graphql_content(response)["data"]["checkoutComplete"]+ assert not content["checkoutErrors"]++ # Ensure the order was actually created+ assert (+ Order.objects.count() == order_count + 1+ ), "The order should have been created"diff --git a/saleor/graphql/checkout/tests/test_checkout_digital.py b/saleor/graphql/checkout/tests/test_checkout_digital.pyindex f76455f788..b4d58c9aeb 100644--- a/saleor/graphql/checkout/tests/test_checkout_digital.py+++ b/saleor/graphql/checkout/tests/test_checkout_digital.py@@ -3,15 +3,12 @@ import grapheneimport pytestfrom ....account.models import Address-from ....checkout import calculationsfrom ....checkout.error_codes import CheckoutErrorCodefrom ....checkout.models import Checkoutfrom ....checkout.utils import add_variant_to_checkout-from ....order.models import Orderfrom ...checkout.mutations import update_checkout_shipping_method_if_invalidfrom ...tests.utils import get_graphql_contentfrom .test_checkout import (- MUTATION_CHECKOUT_COMPLETE,MUTATION_CHECKOUT_CREATE,MUTATION_CHECKOUT_LINES_DELETE,MUTATION_CHECKOUT_LINES_UPDATE,@@ -20,22 +17,6 @@ from .test_checkout import ()-def checkout_with_digital_item(checkout, digital_content):- """Create a checkout with a digital line."""- variant = digital_content.product_variant- add_variant_to_checkout(checkout, variant, 1)- checkout.email = "[email protected]"- checkout.save()- return checkout--[email protected](autouse=True)-def enable_dummy_gateway(settings):- settings.PLUGINS = ["saleor.payment.gateways.dummy.plugin.DummyGatewayPlugin"]- return settings--@pytest.mark.parametrize("with_shipping_address", (True, False))def test_create_checkout(api_client, digital_content, graphql_address_data, with_shipping_address@@ -163,42 +144,6 @@ def test_checkout_update_shipping_method(assert checkout.shipping_method is None-def test_checkout_complete(- api_client, checkout_with_digital_item, address, payment_dummy-):- """Ensure it is possible to complete a digital checkout without shipping."""-- order_count = Order.objects.count()- checkout = checkout_with_digital_item- checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)- variables = {"checkoutId": checkout_id, "redirectUrl": "https://www.example.com"}-- # Set a billing address- checkout.billing_address = address- checkout.save(update_fields=["billing_address"])-- # Create a dummy payment to charge- total = calculations.checkout_total(checkout=checkout, lines=list(checkout))- payment = payment_dummy- payment.is_active = True- payment.order = None- payment.total = total.gross.amount- payment.currency = total.gross.currency- payment.checkout = checkout- payment.save()- assert not payment.transactions.exists()-- # Send the creation request- response = api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)- content = get_graphql_content(response)["data"]["checkoutComplete"]- assert not content["checkoutErrors"]-- # Ensure the order was actually created- assert (- Order.objects.count() == order_count + 1- ), "The order should have been created"--def test_remove_shipping_method_if_only_digital_in_checkout(checkout_with_digital_item, address, shipping_method):diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex d6b5d1aa4f..6ba3faf47b 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -259,6 +259,16 @@ def checkout_ready_to_complete(checkout_with_item, address, shipping_method, gifreturn checkout+def checkout_with_digital_item(checkout, digital_content):+ """Create a checkout with a digital line."""+ variant = digital_content.product_variant+ add_variant_to_checkout(checkout, variant, 1)+ checkout.email = "[email protected]"+ checkout.save()+ return checkout++@pytest.fixturedef checkout_with_shipping_required(checkout_with_item, product):checkout = checkout_with_item