Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
[TEST] Should be able to create partially paid order CORE_0112 (#13631)
Anna Szczęch2f0c3e52ca87
diff --git a/saleor/tests/e2e/checkout/test_checkout_create_partially_paid_order.py b/saleor/tests/e2e/checkout/test_checkout_create_partially_paid_order.pynew file mode 100644index 0000000000..981c1e7a45--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_create_partially_paid_order.py@@ -0,0 +1,180 @@+import pytest++from ..channel.utils import create_channel+from ..product.utils import (+ create_category,+ create_product,+ create_product_channel_listing,+ create_product_type,+ create_product_variant,+ create_product_variant_channel_listing,+)+from ..shipping_zone.utils import (+ create_shipping_method,+ create_shipping_method_channel_listing,+ create_shipping_zone,+)+from ..transactions.utils import create_transaction+from ..utils import assign_permissions+from ..warehouse.utils import create_warehouse+from .utils import (+ checkout_create,+ checkout_delivery_method_update,+ raw_checkout_complete,+)+++def prepare_product(+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ channel_slug,+):+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ warehouse_data = create_warehouse(e2e_staff_api_client)+ warehouse_id = warehouse_data["id"]++ warehouse_ids = [warehouse_id]+ channel_data = create_channel(+ e2e_staff_api_client,+ slug=channel_slug,+ warehouse_ids=warehouse_ids,+ allow_unpaid_orders=True,+ automatically_confirm_all_new_orders=True,+ )+ channel_id = channel_data["id"]++ channel_ids = [channel_id]+ shipping_zone_data = create_shipping_zone(+ e2e_staff_api_client,+ warehouse_ids=warehouse_ids,+ channel_ids=channel_ids,+ )+ shipping_zone_id = shipping_zone_data["id"]++ shipping_method_data = create_shipping_method(+ e2e_staff_api_client, shipping_zone_id+ )+ shipping_method_id = shipping_method_data["id"]++ create_shipping_method_channel_listing(+ e2e_staff_api_client, shipping_method_id, channel_id+ )++ product_type_data = create_product_type(+ e2e_staff_api_client,+ )+ product_type_id = product_type_data["id"]++ category_data = create_category(e2e_staff_api_client)+ category_id = category_data["id"]++ product_data = create_product(e2e_staff_api_client, product_type_id, category_id)+ product_id = product_data["id"]++ create_product_channel_listing(e2e_staff_api_client, product_id, channel_id)++ stocks = [+ {+ "warehouse": warehouse_id,+ "quantity": 5,+ }+ ]+ product_variant_data = create_product_variant(+ e2e_staff_api_client,+ product_id,+ stocks=stocks,+ )+ product_variant_id = product_variant_data["id"]++ create_product_variant_channel_listing(+ e2e_staff_api_client,+ product_variant_id,+ channel_id,+ )++ return product_variant_id+++def test_should_be_able_to_create_partially_paid_order_core_0112(+ e2e_staff_api_client,+ e2e_not_logged_api_client,+ e2e_app_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_payments,+):+ # Before+ channel_slug = "test-channel"+ product_variant_id = prepare_product(+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ channel_slug,+ )+ app_permissions = [permission_manage_payments]+ assign_permissions(e2e_app_api_client, app_permissions)++ # Step 1 - Create checkout.+ lines = [+ {"variantId": product_variant_id, "quantity": 1},+ ]+ checkout_data = checkout_create(+ e2e_not_logged_api_client,+ lines,+ channel_slug,+ email="[email protected]",+ set_default_billing_address=True,+ set_default_shipping_address=True,+ )+ checkout_id = checkout_data["id"]++ assert checkout_data["isShippingRequired"] is True+ assert checkout_data["deliveryMethod"] is None+ assert checkout_data["shippingMethod"] is None+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]++ # Step 2 - Set shipping address and DeliveryMethod for checkout+ checkout_data = checkout_delivery_method_update(+ e2e_not_logged_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id++ # Step 3 - Create transaction for part of amount+ create_transaction(+ e2e_app_api_client,+ checkout_id,+ transaction_name="CreditCard",+ message="Charged",+ psp_reference="PSP-ref123",+ available_actions=["REFUND", "CANCEL"],+ amount=1,+ )++ # Step 4 - Complete checkout and check created order+ data = raw_checkout_complete(e2e_not_logged_api_client, checkout_id)+ order_data = data["order"]+ assert order_data["id"] is not None+ assert order_data["isShippingRequired"] is True+ assert order_data["paymentStatus"] == "PARTIALLY_CHARGED"+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["isPaid"] is False++ errors = data["errors"]+ assert errors == []diff --git a/saleor/tests/e2e/conftest.py b/saleor/tests/e2e/conftest.pyindex 1efbc795fb..15a1ded664 100644--- a/saleor/tests/e2e/conftest.py+++ b/saleor/tests/e2e/conftest.py@@ -5,6 +5,7 @@ from django.core.serializers.json import DjangoJSONEncoderfrom django.test.client import MULTIPART_CONTENT, Clientfrom ...account.models import User+from ...app.models import Appfrom ...graphql.tests.fixtures import BaseApiClientfrom ..utils import flush_post_commit_hooks@@ -71,3 +72,13 @@ def e2e_logged_api_client():@pytest.fixturedef e2e_not_logged_api_client():return E2eApiClient()+++def e2e_app_api_client():+ e2e_app = App.objects.create(+ name="e2e app",+ is_active=True,+ identifier="saleor.e2e.app.test",+ )+ return E2eApiClient(app=e2e_app)diff --git a/saleor/tests/e2e/transactions/__init__.py b/saleor/tests/e2e/transactions/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/tests/e2e/transactions/utils.py b/saleor/tests/e2e/transactions/utils.pynew file mode 100644index 0000000000..edcf16cb19--- /dev/null+++ b/saleor/tests/e2e/transactions/utils.py@@ -0,0 +1,66 @@+from ..utils import get_graphql_content++TRANSACTION_CREATE_MUTATION = """+mutation TransactionCreate($id: ID!, $transactionCreateInput: TransactionCreateInput!) {+ transactionCreate(id: $id, transaction: $transactionCreateInput) {+ errors {+ field+ message+ code+ }+ transaction {+ id+ name+ message+ pspReference+ actions+ chargedAmount {+ currency+ amount+ }+ }+ }+}+"""+++def create_transaction(+ e2e_api_client,+ id,+ transaction_name="CreditCard",+ message="",+ psp_reference="PSP-ref123",+ available_actions=None,+ currency="USD",+ amount=1,+ external_url="https://saleor.io/payment-id/123",+):+ if not available_actions:+ available_actions = []+ variables = {+ "id": id,+ "transactionCreateInput": {+ "name": transaction_name,+ "message": message,+ "pspReference": psp_reference,+ "availableActions": available_actions,+ "amountCharged": {"currency": currency, "amount": amount},+ "externalUrl": external_url,+ },+ }++ response = e2e_api_client.post_graphql(TRANSACTION_CREATE_MUTATION, variables)+ content = get_graphql_content(response)++ assert content["data"]["transactionCreate"]["errors"] == []++ data = content["data"]["transactionCreate"]["transaction"]+ assert data["id"] is not None+ assert data["name"] == transaction_name+ assert data["message"] == message+ assert data["pspReference"] == psp_reference+ assert set(data["actions"]) == set(available_actions)+ assert data["chargedAmount"]["amount"] == amount+ assert data["chargedAmount"]["currency"] == currency++ return datadiff --git a/saleor/tests/e2e/utils.py b/saleor/tests/e2e/utils.pyindex 54c3309653..22df1fdab9 100644--- a/saleor/tests/e2e/utils.py+++ b/saleor/tests/e2e/utils.py@@ -12,3 +12,7 @@ def assign_permissions(api_client, permissions):)group.permissions.add(*permissions)user.groups.add(group)+ else:+ app = api_client.app+ if app:+ app.permissions.add(*permissions)