Skip to content

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

test for checkout with unpublished product - Conflicts fixes (#13387)

Renata7f09b3dccc25
diff --git a/saleor/tests/e2e/checkout/test_unlogged_customer_is_unable_to_buy_unpublished_product.py b/saleor/tests/e2e/checkout/test_unlogged_customer_is_unable_to_buy_unpublished_product.py
new file mode 100644
index 0000000000..626a3a0e30
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_unlogged_customer_is_unable_to_buy_unpublished_product.py
@@ -0,0 +1,116 @@
+import pytest
+
+from ..channel.utils import create_channel
+from ..product.utils import (
+ create_category,
+ create_product,
+ create_product_type,
+ create_product_variant,
+ create_product_variant_channel_listing,
+ raw_create_product_channel_listing,
+)
+from ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse
+from .utils import raw_checkout_create
+
+
+def prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ channel_slug,
+):
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ 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
+ )
+ channel_id = channel_data["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"]
+
+ raw_create_product_channel_listing(
+ e2e_staff_api_client,
+ product_id,
+ channel_id,
+ is_published=False,
+ is_available_for_purchase=True,
+ )
+
+ 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, channel_id, product_id, permissions
+
+
+def test_unlogged_customer_is_unable_to_buy_unpublished_product_core_0109(
+ e2e_staff_api_client,
+ e2e_not_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+):
+ # Before
+ channel_slug = "test-channel222"
+ product_variant_id, channel_id, product_id, permissions = prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ channel_slug,
+ )
+
+ # Step 1 - Create checkout with unpublished product variant
+
+ lines = [
+ {"variantId": product_variant_id, "quantity": 1},
+ ]
+ checkout_data = raw_checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ )
+
+ errors = checkout_data["errors"]
+
+ assert errors[0]["code"] == "PRODUCT_NOT_PUBLISHED"
+ assert errors[0]["field"] == "lines"
+ assert errors[0]["message"] == "Cannot add lines for unpublished variants."
diff --git a/saleor/tests/e2e/checkout/utils/__init__.py b/saleor/tests/e2e/checkout/utils/__init__.py
index 10fbcfea8a..bc19816ed3 100644
--- a/saleor/tests/e2e/checkout/utils/__init__.py
+++ b/saleor/tests/e2e/checkout/utils/__init__.py
@@ -1,3 +1,4 @@
+from ...product.utils.product_channel_listing import raw_create_product_channel_listing
from .checkout_billing_address_update import checkout_billing_address_update
from .checkout_complete import checkout_complete
from .checkout_create import checkout_create, raw_checkout_create
@@ -10,6 +11,7 @@ from .checkout_shipping_address_update import checkout_shipping_address_update
__all__ = [
"checkout_billing_address_update",
+ "raw_create_product_channel_listing",
"checkout_complete",
"checkout_create",
"raw_checkout_create",
diff --git a/saleor/tests/e2e/product/utils/__init__.py b/saleor/tests/e2e/product/utils/__init__.py
index f9a7daf5ed..10ddac6e08 100644
--- a/saleor/tests/e2e/product/utils/__init__.py
+++ b/saleor/tests/e2e/product/utils/__init__.py
@@ -12,6 +12,7 @@ from .product_variant_channel_listing import create_product_variant_channel_list
__all__ = [
"create_category",
"create_digital_content",
+ "raw_create_product_channel_listing",
"create_product_type",
"create_product_channel_listing",
"create_product_variant_channel_listing",
diff --git a/saleor/tests/e2e/product/utils/product_channel_listing.py b/saleor/tests/e2e/product/utils/product_channel_listing.py
index 800e08810c..ee50c459ad 100644
--- a/saleor/tests/e2e/product/utils/product_channel_listing.py
+++ b/saleor/tests/e2e/product/utils/product_channel_listing.py
@@ -41,7 +41,7 @@ def raw_create_product_channel_listing(
is_published=False,
visible_in_listings=False,
available_for_purchase_datetime=None,
- is_available_for_purchase=False,
+ is_available_for_purchase=None,
):
variables = {
"productId": product_id,
@@ -92,8 +92,8 @@ def create_product_channel_listing(
is_available_for_purchase,
)
- assert response["errors"] == []
data = response["product"]
+ assert response["errors"] == []
assert data["id"] == product_id
channel_listing_data = data["channelListings"][0]
assert channel_listing_data["channel"]["id"] == channel_id