Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
E2E tests for sales (#13885)
Anna Szczęch2e06526a4e5d
diff --git a/saleor/tests/e2e/checkout/test_checkout_create_from_order.py b/saleor/tests/e2e/checkout/test_checkout_create_from_order.pyindex 7358154cd5..746d1233d8 100644--- a/saleor/tests/e2e/checkout/test_checkout_create_from_order.py+++ b/saleor/tests/e2e/checkout/test_checkout_create_from_order.py@@ -1,7 +1,6 @@import pytest-from ..orders.utils.draft_order_create import draft_order_create-from ..orders.utils.order_lines_create import order_lines_create+from ..orders.utils import draft_order_create, order_lines_createfrom ..product.utils.preparing_product import prepare_productfrom ..shop.utils.preparing_shop import prepare_shopfrom ..utils import assign_permissionsdiff --git a/saleor/tests/e2e/checkout/test_checkout_product_on_fixed_sale.py b/saleor/tests/e2e/checkout/test_checkout_product_on_fixed_sale.pynew file mode 100644index 0000000000..a7a98c9052--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_product_on_fixed_sale.py@@ -0,0 +1,127 @@+import pytest++from ..product.utils.preparing_product import prepare_product+from ..sales.utils import create_sale, create_sale_channel_listing, sale_catalogues_add+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+)+++def prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type,+ sale_discount_value,+):+ sale_name = "Sale"+ sale = create_sale(e2e_staff_api_client, sale_name, sale_discount_type)+ sale_id = sale["id"]+ sale_listing_input = [+ {+ "channelId": channel_id,+ "discountValue": sale_discount_value,+ }+ ]+ create_sale_channel_listing(+ e2e_staff_api_client, sale_id, add_channels=sale_listing_input+ )+ catalogue_input = {"products": [product_id]}+ sale_catalogues_add(e2e_staff_api_client, sale_id, catalogue_input)++ return sale_id, sale_discount_value+++def test_checkout_products_on_fixed_sale_core_1002(+ e2e_not_logged_api_client,+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ warehouse_id, channel_id, channel_slug, shipping_method_id = prepare_shop(+ e2e_staff_api_client+ )++ product_id, product_variant_id, product_variant_price = prepare_product(+ e2e_staff_api_client, warehouse_id, channel_id, variant_price="13.33"+ )++ sale_id, sale_discount_value = prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type="FIXED",+ sale_discount_value=3,+ )++ # Step 1 - checkoutCreate for product on sale+ lines = [+ {"variantId": product_variant_id, "quantity": 2},+ ]+ 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"]+ checkout_lines = checkout_data["lines"][0]+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]+ unit_price = float(product_variant_price) - sale_discount_value++ assert checkout_data["isShippingRequired"] is True+ assert checkout_lines["unitPrice"]["gross"]["amount"] == unit_price+ assert checkout_lines["undiscountedUnitPrice"]["amount"] == float(+ product_variant_price+ )++ # Step 2 - Set 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+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]+ subtotal_gross_amount = checkout_data["subtotalPrice"]["gross"]["amount"]++ # Step 3 - Create payment for checkout.+ checkout_dummy_payment_create(+ e2e_not_logged_api_client, checkout_id, total_gross_amount+ )++ # Step 5 - Complete checkout.+ order_data = checkout_complete(e2e_not_logged_api_client, checkout_id)+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["total"]["gross"]["amount"] == total_gross_amount+ assert order_data["subtotal"]["gross"]["amount"] == subtotal_gross_amount++ order_line = order_data["lines"][0]+ assert order_line["undiscountedUnitPrice"]["gross"]["amount"] == float(+ product_variant_price+ )+ assert order_line["unitDiscountType"] == "FIXED"+ assert order_line["unitPrice"]["gross"]["amount"] == unit_price+ assert order_line["unitDiscount"]["amount"] == float(sale_discount_value)+ assert order_line["unitDiscountReason"] == f"Sale: {sale_id}"diff --git a/saleor/tests/e2e/checkout/test_checkout_product_on_percentage_sale.py b/saleor/tests/e2e/checkout/test_checkout_product_on_percentage_sale.pynew file mode 100644index 0000000000..35a10cb50c--- /dev/null+++ b/saleor/tests/e2e/checkout/test_checkout_product_on_percentage_sale.py@@ -0,0 +1,128 @@+import pytest++from ..product.utils.preparing_product import prepare_product+from ..sales.utils import create_sale, create_sale_channel_listing, sale_catalogues_add+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_delivery_method_update,+ checkout_dummy_payment_create,+)+++def prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type,+ sale_discount_value,+):+ sale_name = "Sale"+ sale = create_sale(e2e_staff_api_client, sale_name, sale_discount_type)+ sale_id = sale["id"]+ sale_listing_input = [+ {+ "channelId": channel_id,+ "discountValue": sale_discount_value,+ }+ ]+ create_sale_channel_listing(+ e2e_staff_api_client, sale_id, add_channels=sale_listing_input+ )+ catalogue_input = {"products": [product_id]}+ sale_catalogues_add(e2e_staff_api_client, sale_id, catalogue_input)++ return sale_id, sale_discount_value+++def test_checkout_products_on_percentage_sale_core_1004(+ e2e_not_logged_api_client,+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ warehouse_id, channel_id, channel_slug, shipping_method_id = prepare_shop(+ e2e_staff_api_client+ )++ product_id, product_variant_id, product_variant_price = prepare_product(+ e2e_staff_api_client, warehouse_id, channel_id, variant_price="13.33"+ )++ sale_id, sale_discount_value = prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type="PERCENTAGE",+ sale_discount_value=3,+ )++ # Step 1 - checkoutCreate for product on sale+ lines = [+ {"variantId": product_variant_id, "quantity": 2},+ ]+ 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"]+ checkout_lines = checkout_data["lines"][0]+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]+ line_discount = round(float(product_variant_price) * sale_discount_value / 100, 2)+ unit_price = float(product_variant_price) - line_discount++ assert checkout_data["isShippingRequired"] is True+ assert checkout_lines["unitPrice"]["gross"]["amount"] == unit_price+ assert checkout_lines["undiscountedUnitPrice"]["amount"] == float(+ product_variant_price+ )++ # Step 2 - Set 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+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]+ subtotal_gross_amount = checkout_data["subtotalPrice"]["gross"]["amount"]++ # Step 3 - Create payment for checkout.+ checkout_dummy_payment_create(+ e2e_not_logged_api_client, checkout_id, total_gross_amount+ )++ # Step 5 - Complete checkout.+ order_data = checkout_complete(e2e_not_logged_api_client, checkout_id)+ assert order_data["status"] == "UNFULFILLED"+ assert order_data["total"]["gross"]["amount"] == total_gross_amount+ assert order_data["subtotal"]["gross"]["amount"] == subtotal_gross_amount++ order_line = order_data["lines"][0]+ assert order_line["undiscountedUnitPrice"]["gross"]["amount"] == float(+ product_variant_price+ )+ assert order_line["unitDiscountType"] == "FIXED"+ assert order_line["unitPrice"]["gross"]["amount"] == unit_price+ assert order_line["unitDiscount"]["amount"] == line_discount+ assert order_line["unitDiscountReason"] == f"Sale: {sale_id}"diff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.pyindex 7d7cc6345b..4882a56730 100644--- a/saleor/tests/e2e/checkout/utils/checkout_complete.py+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py@@ -11,6 +11,8 @@ mutation CheckoutComplete($checkoutId: ID!) {order {idstatus+ paymentStatus+ isPaiduser {}diff --git a/saleor/tests/e2e/orders/test_order_products_on_fixed_sale.py b/saleor/tests/e2e/orders/test_order_products_on_fixed_sale.pynew file mode 100644index 0000000000..e1cceead7d--- /dev/null+++ b/saleor/tests/e2e/orders/test_order_products_on_fixed_sale.py@@ -0,0 +1,121 @@+import pytest++from .. import DEFAULT_ADDRESS+from ..product.utils.preparing_product import prepare_product+from ..sales.utils import create_sale, create_sale_channel_listing, sale_catalogues_add+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+)+++def prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type,+ sale_discount_value,+):+ sale_name = "Sale"+ sale = create_sale(e2e_staff_api_client, sale_name, sale_discount_type)+ sale_id = sale["id"]+ sale_listing_input = [+ {+ "channelId": channel_id,+ "discountValue": sale_discount_value,+ }+ ]+ create_sale_channel_listing(+ e2e_staff_api_client, sale_id, add_channels=sale_listing_input+ )+ catalogue_input = {"products": [product_id]}+ sale_catalogues_add(e2e_staff_api_client, sale_id, catalogue_input)++ return sale_id, sale_discount_value+++def test_order_products_on_fixed_sale_CORE_1001(+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ permission_manage_orders,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ permission_manage_orders,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ warehouse_id, channel_id, _channel_slug, shipping_method_id = prepare_shop(+ e2e_staff_api_client+ )++ product_id, product_variant_id, product_variant_price = prepare_product(+ e2e_staff_api_client, warehouse_id, channel_id, variant_price="41.99"+ )++ sale_id, sale_discount_value = prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type="FIXED",+ sale_discount_value=30,+ )++ # Step 1 - Create a draft order+ input = {+ "channelId": channel_id,+ "billingAddress": DEFAULT_ADDRESS,+ "shippingAddress": DEFAULT_ADDRESS,+ }+ data = draft_order_create(e2e_staff_api_client, input)+ order_id = data["order"]["id"]+ assert data["order"]["billingAddress"] is not None+ assert data["order"]["shippingAddress"] is not None+ assert order_id is not None++ # Step 2 - Add product on sale to draft order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(e2e_staff_api_client, order_id, lines)++ draft_line = order_lines["order"]["lines"][0]+ assert draft_line["variant"]["id"] == product_variant_id+ unit_price = float(product_variant_price) - float(sale_discount_value)+ undiscounted_price = draft_line["undiscountedUnitPrice"]["gross"]["amount"]+ assert undiscounted_price == float(product_variant_price)+ assert draft_line["unitPrice"]["gross"]["amount"] == round(unit_price, 2)++ # Step 3 - Add a shipping method to the order+ input = {"shippingMethod": shipping_method_id}+ draft_update = draft_order_update(e2e_staff_api_client, order_id, input)++ order_shipping_id = draft_update["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None+ shipping_price = draft_update["order"]["shippingPrice"]["gross"]["amount"]++ # Step 4 - Complete the draft order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ assert order["order"]["status"] == "UNFULFILLED"+ total = order["order"]["total"]["gross"]["amount"]+ assert total == round(float(shipping_price + unit_price), 2)++ order_line = order["order"]["lines"][0]+ assert order_line["unitDiscount"]["amount"] == sale_discount_value+ assert order_line["unitDiscountValue"] == sale_discount_value+ assert order_line["unitDiscountType"] == "FIXED"+ assert draft_line["unitDiscountReason"] == f"Sale: {sale_id}"+ product_price = order_line["undiscountedUnitPrice"]["gross"]["amount"]+ assert product_price == undiscounted_pricediff --git a/saleor/tests/e2e/orders/test_order_products_on_percentage_sale.py b/saleor/tests/e2e/orders/test_order_products_on_percentage_sale.pynew file mode 100644index 0000000000..fae13ad1c8--- /dev/null+++ b/saleor/tests/e2e/orders/test_order_products_on_percentage_sale.py@@ -0,0 +1,122 @@+import pytest++from .. import DEFAULT_ADDRESS+from ..product.utils.preparing_product import prepare_product+from ..sales.utils import create_sale, create_sale_channel_listing, sale_catalogues_add+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+)+++def prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type,+ sale_discount_value,+):+ sale_name = "Sale"+ sale = create_sale(e2e_staff_api_client, sale_name, sale_discount_type)+ sale_id = sale["id"]+ sale_listing_input = [+ {+ "channelId": channel_id,+ "discountValue": sale_discount_value,+ }+ ]+ create_sale_channel_listing(+ e2e_staff_api_client, sale_id, add_channels=sale_listing_input+ )+ catalogue_input = {"products": [product_id]}+ sale_catalogues_add(e2e_staff_api_client, sale_id, catalogue_input)++ return sale_id, sale_discount_value+++def test_order_products_on_percentage_sale_CORE_1003(+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ permission_manage_orders,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ permission_manage_orders,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ warehouse_id, channel_id, _channel_slug, shipping_method_id = prepare_shop(+ e2e_staff_api_client+ )++ product_id, product_variant_id, product_variant_price = prepare_product(+ e2e_staff_api_client, warehouse_id, channel_id, variant_price="11.99"+ )++ sale_id, sale_discount_value = prepare_sale_for_product(+ e2e_staff_api_client,+ channel_id,+ product_id,+ sale_discount_type="PERCENTAGE",+ sale_discount_value=30,+ )++ # Step 1 - Create a draft order+ input = {+ "channelId": channel_id,+ "billingAddress": DEFAULT_ADDRESS,+ "shippingAddress": DEFAULT_ADDRESS,+ }+ data = draft_order_create(e2e_staff_api_client, input)+ order_id = data["order"]["id"]+ assert data["order"]["billingAddress"] is not None+ assert data["order"]["shippingAddress"] is not None+ assert order_id is not None++ # Step 2 - Add product on sale to draft order+ lines = [{"variantId": product_variant_id, "quantity": 1}]+ order_lines = order_lines_create(e2e_staff_api_client, order_id, lines)++ draft_line = order_lines["order"]["lines"][0]+ assert draft_line["variant"]["id"] == product_variant_id+ discount = round(float(product_variant_price) * sale_discount_value / 100, 2)+ unit_price = float(product_variant_price) - discount+ undiscounted_price = draft_line["undiscountedUnitPrice"]["gross"]["amount"]+ assert undiscounted_price == float(product_variant_price)+ assert draft_line["unitPrice"]["gross"]["amount"] == round(unit_price, 2)++ # Step 3 - Add a shipping method to the order+ input = {"shippingMethod": shipping_method_id}+ draft_update = draft_order_update(e2e_staff_api_client, order_id, input)++ order_shipping_id = draft_update["order"]["deliveryMethod"]["id"]+ shipping_price = draft_update["order"]["shippingPrice"]["gross"]["amount"]+ assert order_shipping_id is not None++ # Step 4 - Complete the draft order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ assert order["order"]["status"] == "UNFULFILLED"+ total = order["order"]["total"]["gross"]["amount"]+ assert total == round(float(shipping_price + unit_price), 2)++ order_line = order["order"]["lines"][0]+ assert order_line["unitDiscount"]["amount"] == discount+ assert order_line["unitDiscountValue"] == discount+ assert order_line["unitDiscountType"] == "FIXED"+ assert draft_line["unitDiscountReason"] == f"Sale: {sale_id}"+ product_price = order_line["undiscountedUnitPrice"]["gross"]["amount"]+ assert product_price == undiscounted_pricediff --git a/saleor/tests/e2e/orders/utils/__init_.py b/saleor/tests/e2e/orders/utils/__init_.pydeleted file mode 100644index 2876a8d865..0000000000--- a/saleor/tests/e2e/orders/utils/__init_.py+++ /dev/null@@ -1,14 +0,0 @@-from draft_order_complete import draft_order_complete, raw_draft_order_complete-from draft_order_create import draft_order_create-from draft_order_update import draft_order_update-from order_lines_create import order_lines_create-from order_query import order_query--__all__ = [- "raw_draft_order_complete",- "draft_order_create",- "order_lines_create",- "draft_order_complete",- "draft_order_update",- "order_query",-]diff --git a/saleor/tests/e2e/orders/utils/__init__.py b/saleor/tests/e2e/orders/utils/__init__.pynew file mode 100644index 0000000000..a696a1f338--- /dev/null+++ b/saleor/tests/e2e/orders/utils/__init__.py@@ -0,0 +1,14 @@+from .draft_order_complete import draft_order_complete, raw_draft_order_complete+from .draft_order_create import draft_order_create+from .draft_order_update import draft_order_update+from .order_lines_create import order_lines_create+from .order_query import order_query++__all__ = [+ "raw_draft_order_complete",+ "draft_order_create",+ "order_lines_create",+ "draft_order_complete",+ "draft_order_update",+ "order_query",+]diff --git a/saleor/tests/e2e/orders/utils/order_lines_create.py b/saleor/tests/e2e/orders/utils/order_lines_create.pyindex abb4400f37..fbf875c72e 100644--- a/saleor/tests/e2e/orders/utils/order_lines_create.py+++ b/saleor/tests/e2e/orders/utils/order_lines_create.py@@ -1,19 +1,31 @@from saleor.graphql.tests.utils import get_graphql_contentORDER_LINES_CREATE_MUTATION = """-mutation orderLinesCreate($id: ID!, $input: [OrderLineCreateInput!]! ){- orderLinesCreate(id: $id input: $input, ) {+mutation orderLinesCreate($id: ID!, $input: [OrderLineCreateInput!]!) {+ orderLinesCreate(id: $id, input: $input) {order {+ idlines {quantityvariant {id}+ totalPrice {+ gross {+ amount+ }+ }unitPrice {gross {amount}}+ unitDiscountReason+ undiscountedUnitPrice {+ gross {+ amount+ }+ }}}errors {