Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
test for deleting expired orders with some refactor for test for expired orders and creating order from checkout (#14021)
Renata36dc19fbcf09
diff --git a/saleor/tests/e2e/channel/utils/channel_update.py b/saleor/tests/e2e/channel/utils/channel_update.pyindex 97a3102528..1fef070818 100644--- a/saleor/tests/e2e/channel/utils/channel_update.py+++ b/saleor/tests/e2e/channel/utils/channel_update.py@@ -11,6 +11,7 @@ mutation ChannelUpdate($id: ID!, $input: ChannelUpdateInput!) {automaticallyFulfillNonShippableGiftCardautomaticallyConfirmAllNewOrdersexpireOrdersAfter+ deleteExpiredOrdersAfter}}errors {diff --git a/saleor/tests/e2e/orders/test_app_can_create_order_from_checkout.py b/saleor/tests/e2e/orders/test_app_can_create_order_from_checkout.pyindex 973226955a..5e8d3a84ae 100644--- a/saleor/tests/e2e/orders/test_app_can_create_order_from_checkout.py+++ b/saleor/tests/e2e/orders/test_app_can_create_order_from_checkout.py@@ -31,6 +31,8 @@ def test_app_can_create_order_from_checkout_CORE_0215(app_permissions = [permission_manage_payments,permission_handle_checkouts,+ permission_manage_orders,+ permission_manage_channels,]assign_permissions(e2e_app_api_client, app_permissions)diff --git a/saleor/tests/e2e/orders/test_expired_order_is_deleted_after_specified_time.py b/saleor/tests/e2e/orders/test_expired_order_is_deleted_after_specified_time.pynew file mode 100644index 0000000000..df9c7027dc--- /dev/null+++ b/saleor/tests/e2e/orders/test_expired_order_is_deleted_after_specified_time.py@@ -0,0 +1,144 @@+import datetime++import pytest+from django.utils import timezone+from freezegun import freeze_time++from ....order.tasks import delete_expired_orders_task, expire_orders_task+from ..channel.utils import update_channel+from ..checkout.utils import checkout_create, checkout_delivery_method_update+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import order_create_from_checkout, order_query+++def test_expired_order_is_deleted_after_specified_time_CORE_0216(+ e2e_staff_api_client,+ e2e_app_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_product_types_and_attributes,+ permission_manage_shipping,+ permission_manage_orders,+ permission_manage_payments,+ permission_handle_checkouts,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ ]+ assign_permissions(e2e_staff_api_client, permissions)+ app_permissions = [+ permission_manage_payments,+ permission_handle_checkouts,+ permission_manage_orders,+ permission_manage_channels,+ ]+ assign_permissions(e2e_app_api_client, app_permissions)++ price = 10++ (+ warehouse_id,+ channel_id,+ channel_slug,+ shipping_method_id,+ ) = prepare_shop(e2e_staff_api_client)++ expire_order_after_in_minutes = 1+ delete_expired_order_after_in_days = "1"+ channel_update_input = {+ "orderSettings": {+ "allowUnpaidOrders": True,+ "automaticallyFulfillNonShippableGiftCard": True,+ "automaticallyConfirmAllNewOrders": True,+ "expireOrdersAfter": expire_order_after_in_minutes,+ "deleteExpiredOrdersAfter": delete_expired_order_after_in_days,+ }+ }++ update_channel(+ e2e_staff_api_client,+ channel_id,+ channel_update_input,+ )++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ # Step 1 - Create checkout+ lines = [+ {+ "variantId": product_variant_id,+ "quantity": 1,+ },+ ]+ checkout_data = checkout_create(+ e2e_staff_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_id is not None+ assert checkout_data["isShippingRequired"] is True+ assert len(checkout_data["shippingMethods"]) == 1+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]++ # Step 2 - Assign shipping method+ checkout_data = checkout_delivery_method_update(+ e2e_staff_api_client,+ checkout_id,+ shipping_method_id,+ )+ assert checkout_data["deliveryMethod"]["id"] is not None++ # Step 3 - Create order from the checkout+ now = timezone.now()+ order_data = order_create_from_checkout(e2e_app_api_client, checkout_id)+ order_id = order_data["order"]["id"]+ assert order_id is not None+ assert order_data["order"]["status"] == "UNCONFIRMED"+ assert order_data["order"]["paymentStatus"] == "NOT_CHARGED"+ (order_data["order"]["created"]) = now+ assert order_data["order"]["created"] == now+ expired_orders_settings = order_data["order"]["channel"]["orderSettings"][+ "expireOrdersAfter"+ ]+ delete_expired_orders_settings = order_data["order"]["channel"]["orderSettings"][+ "deleteExpiredOrdersAfter"+ ]+ assert expired_orders_settings == expire_order_after_in_minutes+ assert delete_expired_orders_settings == int(delete_expired_order_after_in_days)++ # Step 4 - Check the order is expired+ time_of_expiration = now + datetime.timedelta(minutes=2)+ with freeze_time(time_of_expiration):+ expire_orders_task()+ data = order_query(e2e_staff_api_client, order_id)+ assert data["status"] == "EXPIRED"+ assert data["paymentStatus"] == "NOT_CHARGED"++ # Step 5 - Check the order has been deleted+ valid_deletion_time = time_of_expiration + datetime.timedelta(days=1)+ with freeze_time(valid_deletion_time):+ delete_expired_orders_task()+ data = order_query(e2e_staff_api_client, order_id)++ assert data is Nonediff --git a/saleor/tests/e2e/orders/test_order_is_expired_after_specific_time.py b/saleor/tests/e2e/orders/test_order_is_expired_after_specific_time.pyindex 8faba45284..77265e4353 100644--- a/saleor/tests/e2e/orders/test_order_is_expired_after_specific_time.py+++ b/saleor/tests/e2e/orders/test_order_is_expired_after_specific_time.py@@ -1,6 +1,8 @@-import time+import datetimeimport pytest+from django.utils import timezone+from freezegun import freeze_timefrom ....order.tasks import expire_orders_taskfrom ..channel.utils import update_channel@@ -35,6 +37,8 @@ def test_order_is_expired_after_specific_time_CORE_0214(app_permissions = [permission_manage_payments,permission_handle_checkouts,+ permission_manage_orders,+ permission_manage_channels,]assign_permissions(e2e_app_api_client, app_permissions)@@ -47,15 +51,21 @@ def test_order_is_expired_after_specific_time_CORE_0214(shipping_method_id,) = prepare_shop(e2e_staff_api_client)+ expire_order_after_in_minutes = 1channel_update_input = {"orderSettings": {"allowUnpaidOrders": True,"automaticallyFulfillNonShippableGiftCard": True,"automaticallyConfirmAllNewOrders": True,- "expireOrdersAfter": 1,+ "expireOrdersAfter": expire_order_after_in_minutes,}}- update_channel(e2e_staff_api_client, channel_id, channel_update_input)++ update_channel(+ e2e_staff_api_client,+ channel_id,+ channel_update_input,+ )(_product_id,@@ -98,15 +108,23 @@ def test_order_is_expired_after_specific_time_CORE_0214(assert checkout_data["deliveryMethod"]["id"] is not None# Step 3 - Create order from the checkout+ now = timezone.now()order_data = order_create_from_checkout(e2e_app_api_client, checkout_id)order_id = order_data["order"]["id"]assert order_id is not Noneassert order_data["order"]["status"] == "UNCONFIRMED"assert order_data["order"]["paymentStatus"] == "NOT_CHARGED"+ (order_data["order"]["created"]) = now+ assert order_data["order"]["created"] == now+ expired_orders_settings = order_data["order"]["channel"]["orderSettings"][+ "expireOrdersAfter"+ ]+ assert expired_orders_settings == expire_order_after_in_minutes- # Step 4 - Wait and check the order's status- time.sleep(80)- expire_orders_task()- data = order_query(e2e_staff_api_client, order_id)- assert data["status"] == "EXPIRED"- assert data["paymentStatus"] == "NOT_CHARGED"+ # Step 4 - Check the order is expired+ time_of_expiration = now + datetime.timedelta(minutes=2)+ with freeze_time(time_of_expiration):+ expire_orders_task()+ data = order_query(e2e_staff_api_client, order_id)+ assert data["status"] == "EXPIRED"+ assert data["paymentStatus"] == "NOT_CHARGED"diff --git a/saleor/tests/e2e/orders/utils/order_create_from_checkout.py b/saleor/tests/e2e/orders/utils/order_create_from_checkout.pyindex 620c9ba7e6..7d04f041d1 100644--- a/saleor/tests/e2e/orders/utils/order_create_from_checkout.py+++ b/saleor/tests/e2e/orders/utils/order_create_from_checkout.py@@ -19,6 +19,12 @@ mutation orderCreateFromCheckout($id: ID!) {amount}}+ channel {+ orderSettings {+ expireOrdersAfter+ deleteExpiredOrdersAfter+ }+ }billingAddress {streetAddress1}diff --git a/saleor/tests/e2e/orders/utils/order_query.py b/saleor/tests/e2e/orders/utils/order_query.pyindex acf9183282..2feb28173d 100644--- a/saleor/tests/e2e/orders/utils/order_query.py+++ b/saleor/tests/e2e/orders/utils/order_query.py@@ -13,6 +13,7 @@ query OrderDetails($id:ID!) {idname}+ updatedAtfulfillments {createdid