Skip to content

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

[POC] Core API tests (#13034)

Filip Owczarekd4d2f1e12b0e
diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml
index 6bbebf1618..272dc370b0 100644
--- a/.github/workflows/pytest.yml
+++ b/.github/workflows/pytest.yml
@@ -60,9 +60,18 @@ jobs:
python -m pip install wheel
python -m pip install -r requirements_dev.txt
- - name: Run tests
+ # Run linters and Django related checks
+ # `git config` command is a workaround for https://github.com/actions/runner-images/issues/6775
+ - name: Run Linters and Checks
+ run: |
+ git config --global --add safe.directory "$GITHUB_WORKSPACE"
+ pre-commit run --all
+ if: ${{ always() }}
+
+ - name: Run unit tests
run: |
pytest \
+ -m "not e2e" \
--cov \
--junitxml=junit/test-results.xml \
--django-db-bench=${{ env.BENCH_PATH }}
@@ -99,10 +108,7 @@ jobs:
upload_secret_key: ${{ secrets.QUERIES_UPLOAD_SECRET }}
if: github.event_name == 'push' && github.repository == 'saleor/saleor'
- # Run linters and Django related checks
- # `git config` command is a workaround for https://github.com/actions/runner-images/issues/6775
- - name: Run Linters and Checks
+ - name: Run E2E tests
run: |
- git config --global --add safe.directory "$GITHUB_WORKSPACE"
- pre-commit run --all
- if: ${{ always() }}
+ pytest \
+ -m "e2e"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60eead7435..1d4f37a4f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -72,6 +72,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Introduce `Saleor-Schema-Version` HTTP header in app manifest fetching and app installation handshake requests. - #13075 by @przlada
### Other changes
+- Add POC of Core API tests - #13034 by @fowczarek
- Expand metric units to support more types of products. - #13043 by @FremahA
- Remove unused `django-versatileimagefield` package - #13148 by @SzymJ
diff --git a/saleor/graphql/tests/fixtures.py b/saleor/graphql/tests/fixtures.py
index b394106796..6784912333 100644
--- a/saleor/graphql/tests/fixtures.py
+++ b/saleor/graphql/tests/fixtures.py
@@ -20,7 +20,7 @@ from .utils import assert_no_permission
API_PATH = reverse("api")
-class ApiClient(Client):
+class BaseApiClient(Client):
"""GraphQL API client."""
def __init__(self, *args, **kwargs):
@@ -72,6 +72,8 @@ class ApiClient(Client):
kwargs["content_type"] = "application/json"
return super().post(self.api_path, data, **kwargs)
+
+class ApiClient(BaseApiClient):
def post_graphql(
self,
query,
@@ -95,13 +97,13 @@ class ApiClient(Client):
if permissions:
if check_no_permissions:
with mock.patch("saleor.graphql.utils.handled_errors_logger"):
- response = super().post(self.api_path, data, **kwargs)
+ response = super(Client, self).post(self.api_path, data, **kwargs)
assert_no_permission(response)
if self.app:
self.app.permissions.add(*permissions)
else:
self.user.user_permissions.add(*permissions)
- result = super().post(self.api_path, data, **kwargs)
+ result = super(Client, self).post(self.api_path, data, **kwargs)
flush_post_commit_hooks()
return result
@@ -114,10 +116,10 @@ class ApiClient(Client):
kwargs["content_type"] = MULTIPART_CONTENT
if permissions:
- response = super().post(self.api_path, *args, **kwargs)
+ response = super(Client, self).post(self.api_path, *args, **kwargs)
assert_no_permission(response)
self.user.user_permissions.add(*permissions)
- result = super().post(self.api_path, *args, **kwargs)
+ result = super(Client, self).post(self.api_path, *args, **kwargs)
flush_post_commit_hooks()
return result
diff --git a/saleor/tests/__init__.py b/saleor/tests/__init__.py
index e69de29bb2..a24e756944 100644
--- a/saleor/tests/__init__.py
+++ b/saleor/tests/__init__.py
@@ -0,0 +1,4 @@
+import pytest
+
+# We want to have PyTest assert introspection in the API tests
+pytest.register_assert_rewrite("saleor.tests.e2e")
diff --git a/saleor/tests/e2e/__init__.py b/saleor/tests/e2e/__init__.py
new file mode 100644
index 0000000000..7f4ef2dabe
--- /dev/null
+++ b/saleor/tests/e2e/__init__.py
@@ -0,0 +1,12 @@
+DEFAULT_ADDRESS = {
+ "firstName": "John Saleor",
+ "lastName": "Doe Mirumee",
+ "companyName": "Saleor Commerce",
+ "streetAddress1": "14208 Hawthorne Blvd",
+ "streetAddress2": "",
+ "postalCode": "90250",
+ "country": "US",
+ "city": "Hawthorne",
+ "countryArea": "CA",
+ "phone": "+12025550163",
+}
diff --git a/saleor/tests/e2e/channel/__init__.py b/saleor/tests/e2e/channel/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/channel/utils.py b/saleor/tests/e2e/channel/utils.py
new file mode 100644
index 0000000000..acfbaa6cdf
--- /dev/null
+++ b/saleor/tests/e2e/channel/utils.py
@@ -0,0 +1,66 @@
+from ..utils import get_graphql_content
+
+CHANNEL_CREATE_MUTATION = """
+mutation ChannelCreate($input: ChannelCreateInput!) {
+ channelCreate(input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ channel {
+ id
+ name
+ slug
+ currencyCode
+ defaultCountry {
+ code
+ }
+ isActive
+ orderSettings {
+ automaticallyConfirmAllNewOrders
+ }
+ }
+ }
+}
+"""
+
+
+def create_channel(
+ staff_api_client,
+ warehouse_ids=None,
+ channel_name="Test channel",
+ slug="test-slug",
+ currency="USD",
+ country="US",
+ is_active=True,
+):
+ if not warehouse_ids:
+ warehouse_ids = []
+
+ variables = {
+ "input": {
+ "name": channel_name,
+ "slug": slug,
+ "currencyCode": currency,
+ "defaultCountry": country,
+ "isActive": is_active,
+ "addWarehouses": warehouse_ids,
+ }
+ }
+
+ response = staff_api_client.post_graphql(CHANNEL_CREATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["channelCreate"]["errors"] == []
+
+ data = content["data"]["channelCreate"]["channel"]
+ assert data["id"] is not None
+ assert data["name"] == channel_name
+ assert data["slug"] == slug
+ assert data["currencyCode"] == currency
+ assert data["defaultCountry"]["code"] == country
+ assert data["orderSettings"]["automaticallyConfirmAllNewOrders"] is True
+ assert data["isActive"] is is_active
+
+ return data
diff --git a/saleor/tests/e2e/checkout/__init__.py b/saleor/tests/e2e/checkout/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py b/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py
new file mode 100644
index 0000000000..a3a89cbcd4
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py
@@ -0,0 +1,170 @@
+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 ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse
+from .utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_dummy_payment_create,
+)
+
+
+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
+ )
+ 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_process_checkout_with_physical_product(
+ e2e_staff_api_client,
+ e2e_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+):
+ # 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,
+ )
+
+ # Step 1 - Login as existing customer.
+
+ # This step is implemented automatically by using a proper
+ # API client(eg. e2e_staff_api_client, e2e_not_logged_api_client,
+ # e2e_logged_api_client).
+
+ # Step 2 - Create checkout.
+ lines = [
+ {"variantId": product_variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_logged_api_client,
+ lines,
+ channel_slug,
+ email=None,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ expected_email = e2e_logged_api_client.user.email
+ assert checkout_data["email"] == expected_email
+ assert checkout_data["user"]["email"] == expected_email
+ assert checkout_data["isShippingRequired"] is True
+ assert checkout_data["shippingMethods"] != []
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+
+ # Step 3 - Set DeliveryMethod for checkout.
+ checkout_data = checkout_delivery_method_update(
+ e2e_logged_api_client,
+ checkout_id,
+ shipping_method_id,
+ )
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+
+ # Step 4 - Create payment for checkout.
+ checkout_dummy_payment_create(
+ e2e_logged_api_client, checkout_id, total_gross_amount
+ )
+
+ # Step 5 - Complete checkout.
+ order_data = checkout_complete(e2e_logged_api_client, checkout_id)
+ assert order_data["isShippingRequired"] is True
+ assert order_data["user"]["email"] == expected_email
+ assert order_data["status"] == "UNFULFILLED"
+ assert order_data["total"]["gross"]["amount"] == total_gross_amount
+ assert order_data["deliveryMethod"]["id"] == shipping_method_id
diff --git a/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_buy_by_click_and_collect.py b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_buy_by_click_and_collect.py
new file mode 100644
index 0000000000..fcaa0145ae
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_buy_by_click_and_collect.py
@@ -0,0 +1,137 @@
+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 ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse, update_warehouse
+from .utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_dummy_payment_create,
+)
+
+
+def prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+):
+ 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"]
+ update_warehouse(
+ e2e_staff_api_client,
+ warehouse_data["id"],
+ is_private=False,
+ click_and_collect_option="LOCAL",
+ )
+ channel_data = create_channel(e2e_staff_api_client, warehouse_data["id"])
+ channel_id = channel_data["id"]
+ channel_slug = channel_data["slug"]
+
+ 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_data["id"],
+ "quantity": 5,
+ }
+ ]
+ variant_data = create_product_variant(
+ e2e_staff_api_client, product_id, stocks=stocks
+ )
+ variant_id = variant_data["id"]
+
+ create_product_variant_channel_listing(
+ e2e_staff_api_client,
+ variant_id,
+ channel_id,
+ )
+
+ return variant_id, channel_slug, warehouse_id
+
+
+def test_unlogged_customer_buy_by_click_and_collect(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+):
+ # Before
+ variant_id, channel_slug, warehouse_id = prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ )
+
+ # Step 1 - Create checkout and check collection point
+ lines = [
+ {"variantId": variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ collection_point = checkout_data["availableCollectionPoints"][0]
+ assert collection_point["id"] == warehouse_id
+ assert collection_point["isPrivate"] is False
+ assert collection_point["clickAndCollectOption"] == "LOCAL"
+
+ # Step 2 - Assign delivery method
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client, checkout_id, collection_point["id"]
+ )
+ assert checkout_data["deliveryMethod"]["id"] == warehouse_id
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+
+ # Step 3 - Create dummy payment
+ checkout_dummy_payment_create(
+ e2e_not_logged_api_client, checkout_id, total_gross_amount
+ )
+
+ # Step 4 - Complete checkout and verify created order
+ 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["deliveryMethod"]["id"] == warehouse_id
diff --git a/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_digital_product.py b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_digital_product.py
new file mode 100644
index 0000000000..e9d1ec8605
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_digital_product.py
@@ -0,0 +1,141 @@
+import pytest
+
+from ..channel.utils import create_channel
+from ..product.utils import (
+ create_category,
+ create_digital_content,
+ create_product,
+ create_product_channel_listing,
+ create_product_type,
+ create_product_variant,
+ create_product_variant_channel_listing,
+)
+from ..shipping_zone.utils import create_shipping_zone
+from ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse
+from .utils import (
+ checkout_billing_address_update,
+ checkout_complete,
+ checkout_create,
+ checkout_dummy_payment_create,
+)
+
+
+def prepare_product(
+ e2e_staff_api_client,
+ permission_manage_product_types_and_attributes,
+ permission_manage_channels,
+ permission_manage_products,
+ permission_manage_shipping,
+ 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
+ )
+ channel_id = channel_data["id"]
+
+ channel_ids = [channel_id]
+ create_shipping_zone(
+ e2e_staff_api_client,
+ warehouse_ids=warehouse_ids,
+ channel_ids=channel_ids,
+ )
+
+ product_type_data = create_product_type(
+ e2e_staff_api_client,
+ is_shipping_required=False,
+ is_digital=True,
+ )
+ 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,
+ )
+
+ create_digital_content(e2e_staff_api_client, product_variant_id)
+ return product_variant_id
+
+
+def test_process_checkout_with_digital_product(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_product_types_and_attributes,
+ permission_manage_channels,
+ permission_manage_products,
+ permission_manage_shipping,
+ media_root,
+):
+ # 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,
+ )
+
+ # Step 1 - Create checkout.
+ lines = [
+ {"variantId": product_variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ )
+ checkout_id = checkout_data["id"]
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+ assert checkout_data["isShippingRequired"] is False
+
+ # Step 2 - Set billing address for checkout.
+ checkout_billing_address_update(e2e_not_logged_api_client, checkout_id)
+
+ # Step 3 - Create payment for checkout.
+ checkout_dummy_payment_create(
+ e2e_not_logged_api_client, checkout_id, total_gross_amount
+ )
+
+ # Step 4 - Complete checkout.
+ order_data = checkout_complete(e2e_not_logged_api_client, checkout_id)
+ assert order_data["isShippingRequired"] is False
+ assert order_data["status"] == "UNFULFILLED"
+ assert order_data["total"]["gross"]["amount"] == total_gross_amount
diff --git a/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_physical_product.py b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_physical_product.py
new file mode 100644
index 0000000000..8a988769e8
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_unlogged_customer_should_be_able_to_order_physical_product.py
@@ -0,0 +1,169 @@
+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 ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse
+from .utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_dummy_payment_create,
+ checkout_shipping_address_update,
+)
+
+
+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
+ )
+ 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_process_checkout_with_physical_product(
+ e2e_staff_api_client,
+ e2e_not_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+):
+ # 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,
+ )
+
+ # Step 1 - Create checkout.
+ lines = [
+ {"variantId": product_variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ assert checkout_data["isShippingRequired"] is True
+ assert checkout_data["shippingMethods"] == []
+ assert checkout_data["deliveryMethod"] is None
+ assert checkout_data["shippingMethod"] is None
+
+ # Step 2 - Set shipping address for checkout.
+ checkout_data = checkout_shipping_address_update(
+ e2e_not_logged_api_client, checkout_id
+ )
+ assert len(checkout_data["shippingMethods"]) == 1
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+
+ # Step 3 - 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"]
+
+ # Step 4 - 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["isShippingRequired"] is True
+ assert order_data["status"] == "UNFULFILLED"
+ assert order_data["total"]["gross"]["amount"] == total_gross_amount
+ assert order_data["deliveryMethod"]["id"] == shipping_method_id
diff --git a/saleor/tests/e2e/checkout/test_unlogged_customer_should_not_be_able_to_buy_product_without_shipping_option.py b/saleor/tests/e2e/checkout/test_unlogged_customer_should_not_be_able_to_buy_product_without_shipping_option.py
new file mode 100644
index 0000000000..22d3e395db
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_unlogged_customer_should_not_be_able_to_buy_product_without_shipping_option.py
@@ -0,0 +1,143 @@
+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_zone
+from ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse, update_warehouse
+from .utils import checkout_create, raw_checkout_dummy_payment_create
+
+
+def prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ permission_manage_shipping,
+):
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ permission_manage_shipping,
+ ]
+
+ assign_permissions(e2e_staff_api_client, permissions)
+ warehouse_data = create_warehouse(e2e_staff_api_client)
+ warehouse_id = warehouse_data["id"]
+ warehouse_ids = [warehouse_id]
+
+ update_warehouse(
+ e2e_staff_api_client,
+ warehouse_data["id"],
+ )
+
+ channel_data = create_channel(
+ e2e_staff_api_client, slug="test___0e00", warehouse_ids=warehouse_ids
+ )
+ channel_id = channel_data["id"]
+ channel_ids = [channel_id]
+ channel_slug = channel_data["slug"]
+
+ 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"]
+
+ product_type_data = create_product_type(
+ e2e_staff_api_client,
+ is_shipping_required=True,
+ )
+ 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_data["id"],
+ "quantity": 5,
+ }
+ ]
+ variant_data = create_product_variant(
+ e2e_staff_api_client, product_id, stocks=stocks
+ )
+ variant_id = variant_data["id"]
+
+ create_product_variant_channel_listing(
+ e2e_staff_api_client,
+ variant_id,
+ channel_id,
+ )
+
+ return variant_id, channel_slug, warehouse_id, shipping_zone_id
+
+
+def test_unlogged_customer_should_not_be_able_to_buy_product_without_shipping_option(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ permission_manage_shipping,
+):
+ # Before
+ variant_id, channel_slug, shipping_zone_id, warehouse_id = prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ permission_manage_shipping,
+ )
+
+ # Step 1 - Create checkout with no shipping method
+ lines = [
+ {"variantId": variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+ checkout_shipping_required = checkout_data["isShippingRequired"]
+ shipping_methods = checkout_data["shippingMethods"]
+
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+ assert checkout_shipping_required is True
+ assert shipping_methods == []
+ assert checkout_data["availableCollectionPoints"] == []
+
+ # Step 2 - Create dummy payment and verify no purchase was made
+ checkout_payment_data = raw_checkout_dummy_payment_create(
+ e2e_not_logged_api_client, checkout_id, total_gross_amount
+ )
+ errors = checkout_payment_data["errors"]
+
+ assert errors[0]["code"] == "SHIPPING_METHOD_NOT_SET"
+ assert errors[0]["field"] == "shippingMethod"
+ assert errors[0]["message"] == "Shipping method is not set"
diff --git a/saleor/tests/e2e/checkout/utils/__init__.py b/saleor/tests/e2e/checkout/utils/__init__.py
new file mode 100644
index 0000000000..52be9ce848
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/__init__.py
@@ -0,0 +1,19 @@
+from .checkout_billing_address_update import checkout_billing_address_update
+from .checkout_complete import checkout_complete
+from .checkout_create import checkout_create
+from .checkout_delivery_method_update import checkout_delivery_method_update
+from .checkout_payment_create import (
+ checkout_dummy_payment_create,
+ raw_checkout_dummy_payment_create,
+)
+from .checkout_shipping_address_update import checkout_shipping_address_update
+
+__all__ = [
+ "checkout_billing_address_update",
+ "checkout_complete",
+ "checkout_create",
+ "checkout_delivery_method_update",
+ "checkout_dummy_payment_create",
+ "checkout_shipping_address_update",
+ "raw_checkout_dummy_payment_create",
+]
diff --git a/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py b/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py
new file mode 100644
index 0000000000..b7201dc544
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_billing_address_update.py
@@ -0,0 +1,58 @@
+from ... import DEFAULT_ADDRESS
+from ...utils import get_graphql_content
+
+CHECKOUT_BILLING_ADDRESS_UPDATE_MUTATION = """
+mutation CheckoutBillingAddressUpdate(
+ $billingAddress: AddressInput!, $checkoutId: ID!
+) {
+ checkoutBillingAddressUpdate(billingAddress: $billingAddress, id: $checkoutId) {
+ errors {
+ field
+ code
+ message
+ }
+ checkout {
+ billingAddress {
+ firstName
+ lastName
+ companyName
+ streetAddress1
+ postalCode
+ country {
+ code
+ }
+ city
+ countryArea
+ phone
+ }
+ }
+ }
+}
+"""
+
+
+def checkout_billing_address_update(api_client, checkout_id, address=DEFAULT_ADDRESS):
+ variables = {
+ "checkoutId": checkout_id,
+ "billingAddress": address,
+ }
+ response = api_client.post_graphql(
+ CHECKOUT_BILLING_ADDRESS_UPDATE_MUTATION,
+ variables=variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["checkoutBillingAddressUpdate"]["errors"] == []
+
+ data = content["data"]["checkoutBillingAddressUpdate"]["checkout"]
+ assert data["billingAddress"]["firstName"] == address["firstName"]
+ assert data["billingAddress"]["lastName"] == address["lastName"]
+ assert data["billingAddress"]["companyName"] == address["companyName"]
+ assert data["billingAddress"]["streetAddress1"] == address["streetAddress1"]
+ assert data["billingAddress"]["postalCode"] == address["postalCode"]
+ assert data["billingAddress"]["country"]["code"] == address["country"]
+ assert data["billingAddress"]["city"] == address["city"].upper()
+ assert data["billingAddress"]["countryArea"] == address["countryArea"]
+ assert data["billingAddress"]["phone"] == address["phone"]
+
+ return data
diff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.py
new file mode 100644
index 0000000000..6a0aec910f
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py
@@ -0,0 +1,54 @@
+from ...utils import get_graphql_content
+
+CHECKOUT_COMPLETE_MUTATION = """
+mutation CheckoutComplete($checkoutId: ID!) {
+ checkoutComplete(id: $checkoutId) {
+ errors {
+ message
+ field
+ code
+ }
+ order {
+ id
+ status
+ user {
+ email
+ }
+ isShippingRequired
+ total {
+ gross {
+ amount
+ }
+ }
+ checkoutId
+ deliveryMethod {
+ ... on ShippingMethod {
+ id
+ }
+ ... on Warehouse {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def checkout_complete(api_client, checkout_id):
+ variables = {
+ "checkoutId": checkout_id,
+ }
+ response = api_client.post_graphql(
+ CHECKOUT_COMPLETE_MUTATION,
+ variables=variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["checkoutComplete"]["errors"] == []
+
+ data = content["data"]["checkoutComplete"]["order"]
+ assert data["id"] is not None
+ assert data["checkoutId"] == checkout_id
+
+ return data
diff --git a/saleor/tests/e2e/checkout/utils/checkout_create.py b/saleor/tests/e2e/checkout/utils/checkout_create.py
new file mode 100644
index 0000000000..9974af3411
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_create.py
@@ -0,0 +1,88 @@
+from ... import DEFAULT_ADDRESS
+from ...utils import get_graphql_content
+
+CHECKOUT_CREATE_MUTATION = """
+mutation CreateCheckout($input: CheckoutCreateInput!) {
+ checkoutCreate(input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ checkout {
+ id
+ email
+ user {
+ id
+ email
+ }
+ channel {
+ slug
+ }
+ isShippingRequired
+ totalPrice {
+ gross {
+ amount
+ }
+ }
+ isShippingRequired
+ shippingMethods {
+ id
+ }
+ deliveryMethod {
+ ... on ShippingMethod {
+ id
+ }
+ ... on Warehouse {
+ id
+ }
+ }
+ shippingMethod {
+ id
+ }
+ availableCollectionPoints {
+ id
+ isPrivate
+ clickAndCollectOption
+ }
+ }
+ }
+}
+"""
+
+
+def checkout_create(
+ api_client,
+ lines,
+ channel_slug,
+ email=None,
+ set_default_billing_address=False,
+ set_default_shipping_address=False,
+):
+ variables = {
+ "input": {
+ "channel": channel_slug,
+ "email": email,
+ "lines": lines,
+ }
+ }
+
+ if set_default_billing_address:
+ variables["input"]["billingAddress"] = DEFAULT_ADDRESS
+
+ if set_default_shipping_address:
+ variables["input"]["shippingAddress"] = DEFAULT_ADDRESS
+
+ response = api_client.post_graphql(
+ CHECKOUT_CREATE_MUTATION,
+ variables=variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["checkoutCreate"]["errors"] == []
+
+ data = content["data"]["checkoutCreate"]["checkout"]
+ assert data["id"] is not None
+ assert data["channel"]["slug"] == channel_slug
+
+ return data
diff --git a/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py
new file mode 100644
index 0000000000..4d3dcaf758
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py
@@ -0,0 +1,55 @@
+from ...utils import get_graphql_content
+
+CHECKOUT_DELIVERY_METHOD_UPDATE_MUTATION = """
+mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID!) {
+ checkoutDeliveryMethodUpdate(
+ id: $checkoutId
+ deliveryMethodId: $deliveryMethodId
+ ) {
+ errors {
+ field
+ code
+ message
+ }
+ checkout {
+ id
+ totalPrice {
+ gross {
+ amount
+ }
+ }
+ deliveryMethod {
+ ... on ShippingMethod {
+ id
+ }
+ ... on Warehouse {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def checkout_delivery_method_update(
+ staff_api_client,
+ checkout_id,
+ delivery_method_id,
+):
+ variables = {
+ "checkoutId": checkout_id,
+ "deliveryMethodId": delivery_method_id,
+ }
+
+ response = staff_api_client.post_graphql(
+ CHECKOUT_DELIVERY_METHOD_UPDATE_MUTATION, variables
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["checkoutDeliveryMethodUpdate"]["errors"] == []
+
+ data = content["data"]["checkoutDeliveryMethodUpdate"]["checkout"]
+ assert data["id"] is not None
+
+ return data
diff --git a/saleor/tests/e2e/checkout/utils/checkout_payment_create.py b/saleor/tests/e2e/checkout/utils/checkout_payment_create.py
new file mode 100644
index 0000000000..1cba50ab9c
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_payment_create.py
@@ -0,0 +1,55 @@
+from ...utils import get_graphql_content
+
+CHECKOUT_PAYMENT_CREATE_MUTATION = """
+mutation createPayment($checkoutId: ID, $input: PaymentInput!) {
+ checkoutPaymentCreate(id: $checkoutId, input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ checkout {
+ id
+ }
+ payment {
+ id
+ }
+ }
+}
+"""
+
+
+def raw_checkout_dummy_payment_create(api_client, checkout_id, total_gross_amount):
+ variables = {
+ "checkoutId": checkout_id,
+ "input": {
+ "amount": total_gross_amount,
+ "gateway": "mirumee.payments.dummy",
+ "token": "fully_charged",
+ },
+ }
+
+ response = api_client.post_graphql(
+ CHECKOUT_PAYMENT_CREATE_MUTATION,
+ variables=variables,
+ )
+ content = get_graphql_content(response)
+
+ checkout_data = content["data"]["checkoutPaymentCreate"]
+
+ return checkout_data
+
+
+def checkout_dummy_payment_create(api_client, checkout_id, total_gross_amount):
+ checkout_payment_create_response = raw_checkout_dummy_payment_create(
+ api_client, checkout_id, total_gross_amount
+ )
+
+ assert checkout_payment_create_response["errors"] == []
+
+ checkout_data = checkout_payment_create_response["checkout"]
+ assert checkout_data["id"] == checkout_id
+ payment_data = checkout_payment_create_response["payment"]
+ assert payment_data["id"] is not None
+
+ return payment_data
diff --git a/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py b/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py
new file mode 100644
index 0000000000..c21da7d080
--- /dev/null
+++ b/saleor/tests/e2e/checkout/utils/checkout_shipping_address_update.py
@@ -0,0 +1,65 @@
+from ... import DEFAULT_ADDRESS
+from ...utils import get_graphql_content
+
+CHECKOUT_SHIPPING_ADDRESS_UPDATE_MUTATION = """
+mutation CheckoutShippingAddressUpdate(
+ $shippingAddress: AddressInput!, $checkoutId: ID!
+) {
+ checkoutShippingAddressUpdate(
+ shippingAddress: $shippingAddress
+ id: $checkoutId
+ ) {
+ errors {
+ field
+ code
+ message
+ }
+ checkout {
+ shippingAddress {
+ firstName
+ lastName
+ companyName
+ streetAddress1
+ postalCode
+ country {
+ code
+ }
+ city
+ countryArea
+ phone
+ }
+ shippingMethods {
+ id
+ name
+ }
+ }
+ }
+}
+"""
+
+
+def checkout_shipping_address_update(api_client, checkout_id, address=DEFAULT_ADDRESS):
+ variables = {
+ "checkoutId": checkout_id,
+ "shippingAddress": address,
+ }
+ response = api_client.post_graphql(
+ CHECKOUT_SHIPPING_ADDRESS_UPDATE_MUTATION,
+ variables=variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["checkoutShippingAddressUpdate"]["errors"] == []
+
+ data = content["data"]["checkoutShippingAddressUpdate"]["checkout"]
+ assert data["shippingAddress"]["firstName"] == address["firstName"]
+ assert data["shippingAddress"]["lastName"] == address["lastName"]
+ assert data["shippingAddress"]["companyName"] == address["companyName"]
+ assert data["shippingAddress"]["streetAddress1"] == address["streetAddress1"]
+ assert data["shippingAddress"]["postalCode"] == address["postalCode"]
+ assert data["shippingAddress"]["country"]["code"] == address["country"]
+ assert data["shippingAddress"]["city"] == address["city"].upper()
+ assert data["shippingAddress"]["countryArea"] == address["countryArea"]
+ assert data["shippingAddress"]["phone"] == address["phone"]
+
+ return data
diff --git a/saleor/tests/e2e/conftest.py b/saleor/tests/e2e/conftest.py
new file mode 100644
index 0000000000..1efbc795fb
--- /dev/null
+++ b/saleor/tests/e2e/conftest.py
@@ -0,0 +1,73 @@
+import json
+
+import pytest
+from django.core.serializers.json import DjangoJSONEncoder
+from django.test.client import MULTIPART_CONTENT, Client
+
+from ...account.models import User
+from ...graphql.tests.fixtures import BaseApiClient
+from ..utils import flush_post_commit_hooks
+
+
+class E2eApiClient(BaseApiClient):
+ def post_graphql(
+ self,
+ query,
+ variables=None,
+ **kwargs,
+ ):
+ """Dedicated helper for posting GraphQL queries.
+
+ Sets the `application/json` content type and json.dumps the variables
+ if present.
+ """
+ data = {"query": query}
+ if variables is not None:
+ data["variables"] = variables
+ data = json.dumps(data, cls=DjangoJSONEncoder)
+ kwargs["content_type"] = "application/json"
+
+ result = super(Client, self).post(self.api_path, data, **kwargs)
+ flush_post_commit_hooks()
+ return result
+
+ def post_multipart(self, *args, **kwargs):
+ """Send a multipart POST request.
+
+ This is used to send multipart requests to GraphQL API when e.g.
+ uploading files.
+ """
+ kwargs["content_type"] = MULTIPART_CONTENT
+
+ result = super(Client, self).post(self.api_path, *args, **kwargs)
+ flush_post_commit_hooks()
+ return result
+
+
+def e2e_staff_api_client():
+ e2e_staff_user = User.objects.create_user(
+ password="password",
+ is_staff=True,
+ is_active=True,
+ )
+ return E2eApiClient(user=e2e_staff_user)
+
+
+def e2e_logged_api_client():
+ e2e_customer = User.objects.create_user(
+ password="password",
+ first_name="Joe",
+ last_name="Saleor",
+ is_active=True,
+ is_staff=False,
+ )
+ return E2eApiClient(user=e2e_customer)
+
+
+def e2e_not_logged_api_client():
+ return E2eApiClient()
diff --git a/saleor/tests/e2e/product/__init__.py b/saleor/tests/e2e/product/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/product/utils/__init__.py b/saleor/tests/e2e/product/utils/__init__.py
new file mode 100644
index 0000000000..024227d0c5
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/__init__.py
@@ -0,0 +1,17 @@
+from .category import create_category
+from .digital_content import create_digital_content
+from .product import create_product
+from .product_channel_listing import create_product_channel_listing
+from .product_type import create_product_type
+from .product_variant import create_product_variant
+from .product_variant_channel_listing import create_product_variant_channel_listing
+
+__all__ = [
+ "create_category",
+ "create_digital_content",
+ "create_product_type",
+ "create_product_channel_listing",
+ "create_product_variant_channel_listing",
+ "create_product_variant",
+ "create_product",
+]
diff --git a/saleor/tests/e2e/product/utils/category.py b/saleor/tests/e2e/product/utils/category.py
new file mode 100644
index 0000000000..c060b48515
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/category.py
@@ -0,0 +1,43 @@
+from ...utils import get_graphql_content
+
+CATEGORY_CREATE_MUTATION = """
+mutation CreateCategory($input: CategoryInput!) {
+ categoryCreate(input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ category {
+ id
+ name
+ }
+ }
+}
+"""
+
+
+def create_category(
+ staff_api_client,
+ name="Test category",
+):
+ variables = {
+ "input": {
+ "name": name,
+ }
+ }
+
+ response = staff_api_client.post_graphql(
+ CATEGORY_CREATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["categoryCreate"]["errors"] == []
+
+ data = content["data"]["categoryCreate"]["category"]
+ assert data["id"] is not None
+ assert data["name"] == name
+
+ return data
diff --git a/saleor/tests/e2e/product/utils/digital_content.py b/saleor/tests/e2e/product/utils/digital_content.py
new file mode 100644
index 0000000000..46e9af419c
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/digital_content.py
@@ -0,0 +1,61 @@
+from io import BytesIO
+
+from django.core.files.uploadedfile import SimpleUploadedFile
+from PIL import Image
+
+from ...utils import get_graphql_content, get_multipart_request_body
+
+DIGITAL_CONTENT_CREATE_MUTATION = """
+mutation createDigitalContent($variantId: ID!, $input: DigitalContentUploadInput!) {
+ digitalContentCreate(input: $input, variantId: $variantId) {
+ errors {
+ field
+ message
+ code
+ }
+ variant {
+ id
+ }
+ content {
+ id
+ contentFile
+ }
+ }
+}
+"""
+
+
+def create_image(image_name):
+ img_data = BytesIO()
+ image = Image.new("RGB", size=(1, 1), color=(255, 0, 0, 0))
+ image.save(img_data, format="JPEG")
+ image = SimpleUploadedFile(image_name + ".jpg", img_data.getvalue(), "image/jpeg")
+ return image, image_name
+
+
+def create_digital_content(staff_api_client, product_variant_id):
+ image_file, image_name = create_image("sample_image_as_digital_content")
+ variables = {
+ "input": {
+ "useDefaultSettings": True,
+ "automaticFulfillment": True,
+ "contentFile": image_name,
+ },
+ "variantId": product_variant_id,
+ }
+
+ request_body = get_multipart_request_body(
+ DIGITAL_CONTENT_CREATE_MUTATION, variables, image_file, image_name
+ )
+ response = staff_api_client.post_multipart(request_body)
+ content = get_graphql_content(response)
+
+ assert content["data"]["digitalContentCreate"]["errors"] == []
+
+ variant_data = content["data"]["digitalContentCreate"]["variant"]
+ assert variant_data["id"] == product_variant_id
+ digital_content_data = content["data"]["digitalContentCreate"]["content"]
+ assert digital_content_data["id"] is not None
+ assert image_name in digital_content_data["contentFile"]
+
+ return digital_content_data
diff --git a/saleor/tests/e2e/product/utils/product.py b/saleor/tests/e2e/product/utils/product.py
new file mode 100644
index 0000000000..67aaaf6d82
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/product.py
@@ -0,0 +1,55 @@
+from ...utils import get_graphql_content
+
+PRODUCT_CREATE_MUTATION = """
+mutation createProduct($input: ProductCreateInput!) {
+ productCreate(input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ product {
+ id
+ name
+ productType {
+ id
+ }
+ category {
+ id
+ }
+ }
+ }
+}
+"""
+
+
+def create_product(
+ staff_api_client,
+ product_type_id,
+ category_id,
+ product_name="Test product",
+):
+ variables = {
+ "input": {
+ "name": product_name,
+ "productType": product_type_id,
+ "category": category_id,
+ }
+ }
+
+ response = staff_api_client.post_graphql(
+ PRODUCT_CREATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["productCreate"]["errors"] == []
+
+ data = content["data"]["productCreate"]["product"]
+ assert data["id"] is not None
+ assert data["name"] == product_name
+ assert data["productType"]["id"] == product_type_id
+ assert data["category"]["id"] == category_id
+
+ return data
diff --git a/saleor/tests/e2e/product/utils/product_channel_listing.py b/saleor/tests/e2e/product/utils/product_channel_listing.py
new file mode 100644
index 0000000000..9e0dbb4350
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/product_channel_listing.py
@@ -0,0 +1,84 @@
+import datetime
+
+import pytz
+
+from ...utils import get_graphql_content
+
+PRODUCT_CHANNEL_LISTING_UPDATE_MUTATION = """
+mutation UpdateProductChannelListing(
+ $productId: ID!, $input: ProductChannelListingUpdateInput!
+) {
+ productChannelListingUpdate(id: $productId, input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ product {
+ id
+ channelListings {
+ id
+ isPublished
+ publicationDate
+ visibleInListings
+ isAvailableForPurchase
+ availableForPurchaseAt
+ channel {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def create_product_channel_listing(
+ staff_api_client,
+ product_id,
+ channel_id,
+ publication_date=datetime.date(2007, 1, 1),
+ is_published=True,
+ visible_in_listings=True,
+ available_for_purchase_datetime=datetime.datetime(2007, 1, 1, tzinfo=pytz.utc),
+ is_available_for_purchase=True,
+):
+ variables = {
+ "productId": product_id,
+ "input": {
+ "updateChannels": [
+ {
+ "channelId": channel_id,
+ "isPublished": is_published,
+ "publicationDate": publication_date,
+ "visibleInListings": visible_in_listings,
+ "isAvailableForPurchase": is_available_for_purchase,
+ "availableForPurchaseAt": available_for_purchase_datetime,
+ }
+ ]
+ },
+ }
+
+ response = staff_api_client.post_graphql(
+ PRODUCT_CHANNEL_LISTING_UPDATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["productChannelListingUpdate"]["errors"] == []
+
+ data = content["data"]["productChannelListingUpdate"]["product"]
+ assert data["id"] == product_id
+ channel_listing_data = data["channelListings"][0]
+ assert channel_listing_data["channel"]["id"] == channel_id
+ assert channel_listing_data["isPublished"] is is_published
+ assert channel_listing_data["publicationDate"] == publication_date.isoformat()
+ assert channel_listing_data["visibleInListings"] is visible_in_listings
+ assert channel_listing_data["isAvailableForPurchase"] is is_available_for_purchase
+ assert (
+ channel_listing_data["availableForPurchaseAt"]
+ == available_for_purchase_datetime.isoformat()
+ )
+
+ return data
diff --git a/saleor/tests/e2e/product/utils/product_type.py b/saleor/tests/e2e/product/utils/product_type.py
new file mode 100644
index 0000000000..c982301009
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/product_type.py
@@ -0,0 +1,52 @@
+from ...utils import get_graphql_content
+
+PRODUCT_TYPE_CREATE_MUTATION = """
+mutation createProductType($input: ProductTypeInput!) {
+ productTypeCreate(input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ productType {
+ id
+ name
+ slug
+ kind
+ isShippingRequired
+ isDigital
+ }
+ }
+}
+"""
+
+
+def create_product_type(
+ staff_api_client,
+ product_type_name="Test type",
+ slug="test-type",
+ is_shipping_required=True,
+ is_digital=False,
+):
+ variables = {
+ "input": {
+ "name": product_type_name,
+ "slug": slug,
+ "isShippingRequired": is_shipping_required,
+ "isDigital": is_digital,
+ }
+ }
+
+ response = staff_api_client.post_graphql(PRODUCT_TYPE_CREATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["productTypeCreate"]["errors"] == []
+
+ data = content["data"]["productTypeCreate"]["productType"]
+ assert data["id"] is not None
+ assert data["name"] == product_type_name
+ assert data["slug"] == slug
+ assert data["isShippingRequired"] is is_shipping_required
+ assert data["isDigital"] is is_digital
+
+ return data
diff --git a/saleor/tests/e2e/product/utils/product_variant.py b/saleor/tests/e2e/product/utils/product_variant.py
new file mode 100644
index 0000000000..f898f7b0aa
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/product_variant.py
@@ -0,0 +1,55 @@
+from ...utils import get_graphql_content
+
+PRODUCT_VARIANT_CREATE_MUTATION = """
+mutation createVariant($input: ProductVariantCreateInput!) {
+ productVariantCreate(input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ productVariant {
+ id
+ name
+ product{
+ id
+ }
+ }
+ }
+}
+"""
+
+
+def create_product_variant(
+ staff_api_client,
+ product_id,
+ variant_name="Test product variant",
+ stocks=None,
+):
+ if not stocks:
+ stocks = []
+
+ variables = {
+ "input": {
+ "name": variant_name,
+ "product": product_id,
+ "attributes": [],
+ "stocks": stocks,
+ }
+ }
+
+ response = staff_api_client.post_graphql(
+ PRODUCT_VARIANT_CREATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["productVariantCreate"]["errors"] == []
+
+ data = content["data"]["productVariantCreate"]["productVariant"]
+ assert data["id"] is not None
+ assert data["name"] == variant_name
+ assert data["product"]["id"] == product_id
+
+ return data
diff --git a/saleor/tests/e2e/product/utils/product_variant_channel_listing.py b/saleor/tests/e2e/product/utils/product_variant_channel_listing.py
new file mode 100644
index 0000000000..0d6d032952
--- /dev/null
+++ b/saleor/tests/e2e/product/utils/product_variant_channel_listing.py
@@ -0,0 +1,61 @@
+from ...utils import get_graphql_content
+
+PRODUCT_CHANNEL_LISTING_UPDATE_MUTATION = """
+mutation UpdateProductVariantChannelListing(
+ $productVariantId: ID!, $input: [ProductVariantChannelListingAddInput!]!
+) {
+ productVariantChannelListingUpdate(id: $productVariantId, input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ variant {
+ id
+ channelListings {
+ id
+ price {
+ amount
+ }
+ channel {
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def create_product_variant_channel_listing(
+ staff_api_client,
+ product_variant_id,
+ channel_id,
+ price="9.99",
+):
+ variables = {
+ "productVariantId": product_variant_id,
+ "input": [
+ {
+ "channelId": channel_id,
+ "price": price,
+ },
+ ],
+ }
+
+ response = staff_api_client.post_graphql(
+ PRODUCT_CHANNEL_LISTING_UPDATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["productVariantChannelListingUpdate"]["errors"] == []
+
+ data = content["data"]["productVariantChannelListingUpdate"]["variant"]
+ assert data["id"] == product_variant_id
+ channel_listing_data = data["channelListings"][0]
+ assert channel_listing_data["channel"]["id"] == channel_id
+ assert channel_listing_data["price"]["amount"] == float(price)
+
+ return data
diff --git a/saleor/tests/e2e/shipping_zone/__init__.py b/saleor/tests/e2e/shipping_zone/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/shipping_zone/utils/__init__.py b/saleor/tests/e2e/shipping_zone/utils/__init__.py
new file mode 100644
index 0000000000..7dacd7f380
--- /dev/null
+++ b/saleor/tests/e2e/shipping_zone/utils/__init__.py
@@ -0,0 +1,9 @@
+from .shipping_method import create_shipping_method
+from .shipping_method_channel_listing import create_shipping_method_channel_listing
+from .shipping_zone import create_shipping_zone
+
+__all__ = [
+ "create_shipping_method",
+ "create_shipping_method_channel_listing",
+ "create_shipping_zone",
+]
diff --git a/saleor/tests/e2e/shipping_zone/utils/shipping_method.py b/saleor/tests/e2e/shipping_zone/utils/shipping_method.py
new file mode 100644
index 0000000000..89a936f598
--- /dev/null
+++ b/saleor/tests/e2e/shipping_zone/utils/shipping_method.py
@@ -0,0 +1,44 @@
+from ...utils import get_graphql_content
+
+SHIPPING_PRICE_CREATE_MUTATION = """
+mutation CreateShippingRate($input: ShippingPriceInput!) {
+ shippingPriceCreate(input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ shippingZone {
+ id
+ }
+ shippingMethod {
+ id
+ }
+ }
+}
+"""
+
+
+def create_shipping_method(
+ staff_api_client,
+ shipping_zone_id,
+ name="Test shipping method",
+ type="PRICE",
+):
+ variables = {
+ "input": {
+ "shippingZone": shipping_zone_id,
+ "name": name,
+ "type": type,
+ }
+ }
+
+ response = staff_api_client.post_graphql(SHIPPING_PRICE_CREATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["shippingPriceCreate"]["errors"] == []
+
+ data = content["data"]["shippingPriceCreate"]["shippingMethod"]
+ assert data["id"] is not None
+
+ return data
diff --git a/saleor/tests/e2e/shipping_zone/utils/shipping_method_channel_listing.py b/saleor/tests/e2e/shipping_zone/utils/shipping_method_channel_listing.py
new file mode 100644
index 0000000000..14ab0b02a7
--- /dev/null
+++ b/saleor/tests/e2e/shipping_zone/utils/shipping_method_channel_listing.py
@@ -0,0 +1,46 @@
+from ...utils import get_graphql_content
+
+SHIPPING_METHOD_CHANNEL_LISTING_MUTATION = """
+mutation ShippingMethodChannelListingUpdate(
+ $id: ID!, $input: ShippingMethodChannelListingInput!
+) {
+ shippingMethodChannelListingUpdate(id: $id, input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ shippingMethod {
+ id
+ }
+ }
+}
+"""
+
+
+def create_shipping_method_channel_listing(
+ staff_api_client, shipping_method_id, channel_id, price="10.00"
+):
+ variables = {
+ "id": shipping_method_id,
+ "input": {
+ "addChannels": [
+ {
+ "channelId": channel_id,
+ "price": price,
+ }
+ ]
+ },
+ }
+
+ response = staff_api_client.post_graphql(
+ SHIPPING_METHOD_CHANNEL_LISTING_MUTATION, variables
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["shippingMethodChannelListingUpdate"]["errors"] == []
+
+ data = content["data"]["shippingMethodChannelListingUpdate"]["shippingMethod"]
+ assert data["id"] is not None
+
+ return data
diff --git a/saleor/tests/e2e/shipping_zone/utils/shipping_zone.py b/saleor/tests/e2e/shipping_zone/utils/shipping_zone.py
new file mode 100644
index 0000000000..4b38129f0e
--- /dev/null
+++ b/saleor/tests/e2e/shipping_zone/utils/shipping_zone.py
@@ -0,0 +1,60 @@
+from ...utils import get_graphql_content
+
+SHIPPING_ZONE_CREATE_MUTATION = """
+mutation createShipping($input: ShippingZoneCreateInput!) {
+ shippingZoneCreate(input: $input) {
+ errors {
+ field
+ code
+ message
+ }
+ shippingZone {
+ id
+ name
+ description
+ warehouses {
+ name
+ }
+ channels {
+ id
+ }
+ }
+ }
+}
+"""
+
+
+def create_shipping_zone(
+ staff_api_client,
+ name="Test shipping zone",
+ warehouse_ids=None,
+ channel_ids=None,
+):
+ if not warehouse_ids:
+ warehouse_ids = []
+ if not channel_ids:
+ channel_ids = []
+
+ variables = {
+ "input": {
+ "name": name,
+ "countries": "US",
+ "addWarehouses": warehouse_ids,
+ "addChannels": channel_ids,
+ }
+ }
+
+ response = staff_api_client.post_graphql(
+ SHIPPING_ZONE_CREATE_MUTATION,
+ variables,
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["shippingZoneCreate"]["errors"] == []
+
+ data = content["data"]["shippingZoneCreate"]["shippingZone"]
+ assert data["id"] is not None
+ assert data["name"] == name
+
+ return data
diff --git a/saleor/tests/e2e/utils.py b/saleor/tests/e2e/utils.py
new file mode 100644
index 0000000000..80d5775301
--- /dev/null
+++ b/saleor/tests/e2e/utils.py
@@ -0,0 +1,8 @@
+from ...graphql.tests.utils import get_graphql_content # noqa: F401
+from ...graphql.tests.utils import get_multipart_request_body # noqa: F401
+
+
+def assign_permissions(api_client, permissions):
+ user = api_client.user
+ if user:
+ user.user_permissions.add(*permissions)
diff --git a/saleor/tests/e2e/warehouse/__init__.py b/saleor/tests/e2e/warehouse/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/warehouse/utils/__init__.py b/saleor/tests/e2e/warehouse/utils/__init__.py
new file mode 100644
index 0000000000..9a1093d4bf
--- /dev/null
+++ b/saleor/tests/e2e/warehouse/utils/__init__.py
@@ -0,0 +1,4 @@
+from .create_warehouse import create_warehouse
+from .update_warehouse import update_warehouse
+
+__all__ = ["create_warehouse", "update_warehouse"]
diff --git a/saleor/tests/e2e/warehouse/utils/create_warehouse.py b/saleor/tests/e2e/warehouse/utils/create_warehouse.py
new file mode 100644
index 0000000000..953a563463
--- /dev/null
+++ b/saleor/tests/e2e/warehouse/utils/create_warehouse.py
@@ -0,0 +1,46 @@
+from ... import DEFAULT_ADDRESS
+from ...utils import get_graphql_content
+
+WAREHOUSE_CREATE_MUTATION = """
+mutation createWarehouse($input: WarehouseCreateInput!) {
+ createWarehouse(input: $input) {
+ errors {
+ message
+ field
+ code
+ }
+ warehouse {
+ id
+ name
+ slug
+ }
+ }
+}
+"""
+
+
+def create_warehouse(
+ staff_api_client,
+ name="Test warehouse",
+ slug="test-slug",
+ address=DEFAULT_ADDRESS,
+):
+ variables = {
+ "input": {
+ "name": name,
+ "slug": slug,
+ "address": address,
+ }
+ }
+
+ response = staff_api_client.post_graphql(WAREHOUSE_CREATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["createWarehouse"]["errors"] == []
+
+ data = content["data"]["createWarehouse"]["warehouse"]
+ assert data["id"] is not None
+ assert data["name"] == name
+ assert data["slug"] == slug
+
+ return data
diff --git a/saleor/tests/e2e/warehouse/utils/update_warehouse.py b/saleor/tests/e2e/warehouse/utils/update_warehouse.py
new file mode 100644
index 0000000000..8351c12a63
--- /dev/null
+++ b/saleor/tests/e2e/warehouse/utils/update_warehouse.py
@@ -0,0 +1,44 @@
+from ...utils import get_graphql_content
+
+WAREHOUSE_UPDATE_MUTATION = """
+mutation updateWarehouse($id: ID! $input: WarehouseUpdateInput!) {
+ updateWarehouse(id: $id, input: $input) {
+ errors {
+ message
+ field
+ code
+ }
+ warehouse {
+ id
+ name
+ slug
+ clickAndCollectOption
+ isPrivate
+ }
+ }
+}
+"""
+
+
+def update_warehouse(
+ staff_api_client,
+ warehouse_id,
+ is_private=False,
+ click_and_collect_option="DISABLED",
+):
+ variables = {
+ "id": warehouse_id,
+ "input": {
+ "isPrivate": is_private,
+ "clickAndCollectOption": click_and_collect_option,
+ },
+ }
+ response = staff_api_client.post_graphql(WAREHOUSE_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["updateWarehouse"]["errors"] == []
+ data = content["data"]["updateWarehouse"]["warehouse"]
+ assert data["isPrivate"] == is_private
+ assert data["clickAndCollectOption"] == click_and_collect_option
+
+ return data
diff --git a/setup.cfg b/setup.cfg
index 3fc87422c0..4ec3ce9021 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -25,6 +25,7 @@ filterwarnings =
ignore::PendingDeprecationWarning
markers =
integration
+ e2e
[flake8]
exclude =