Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
[Test] Should be able to create a page with each type of attribute (#14600)
Anna Szczęch0087ab31fa80
diff --git a/saleor/tests/e2e/attributes/utils/__init__.py b/saleor/tests/e2e/attributes/utils/__init__.pyindex a68c92bde9..7720dd248d 100644--- a/saleor/tests/e2e/attributes/utils/__init__.py+++ b/saleor/tests/e2e/attributes/utils/__init__.py@@ -1,5 +1,4 @@from .create_attribute import attribute_create+from .prepare_attributes import prepare_all_attributes-__all__ = [- "attribute_create",-]+__all__ = ["attribute_create", "prepare_all_attributes"]diff --git a/saleor/tests/e2e/attributes/utils/create_attribute.py b/saleor/tests/e2e/attributes/utils/create_attribute.pyindex 0e7aa1c26d..b8681f0bb6 100644--- a/saleor/tests/e2e/attributes/utils/create_attribute.py+++ b/saleor/tests/e2e/attributes/utils/create_attribute.py@@ -24,6 +24,9 @@ def attribute_create(type="PRODUCT_TYPE",value_required=True,is_variant_only=False,+ values=None,+ unit=None,+ entityType=None,):variables = {"input": {@@ -33,6 +36,9 @@ def attribute_create("type": type,"valueRequired": value_required,"isVariantOnly": is_variant_only,+ "values": values,+ "unit": unit,+ "entityType": entityType,}}diff --git a/saleor/tests/e2e/attributes/utils/prepare_attributes.py b/saleor/tests/e2e/attributes/utils/prepare_attributes.pynew file mode 100644index 0000000000..caf79f6541--- /dev/null+++ b/saleor/tests/e2e/attributes/utils/prepare_attributes.py@@ -0,0 +1,171 @@+from .create_attribute import attribute_create+++def prepare_all_attributes(e2e_staff_api_client, attribute_type):+ # Dropdown+ values = [+ {"name": "Freddy Torres"},+ {"name": "Isabella Smith"},+ {"name": "Hayden Blake"},+ ]+ attr_dropdown = attribute_create(+ e2e_staff_api_client,+ input_type="DROPDOWN",+ name="Author",+ slug="author",+ type="PAGE_TYPE",+ value_required=True,+ values=values,+ )++ attr_dropdown_id = attr_dropdown["id"]++ # Multiselect+ values = [+ {"name": "Security"},+ {"name": "Support"},+ {"name": "Medical"},+ {"name": "General"},+ ]++ attr_multi = attribute_create(+ e2e_staff_api_client,+ input_type="MULTISELECT",+ name="Department",+ slug="department",+ type="PAGE_TYPE",+ value_required=True,+ values=values,+ )++ attr_multiselect_id = attr_multi["id"]++ # Date+ attr_date = attribute_create(+ e2e_staff_api_client,+ input_type="DATE",+ name="Date",+ slug="date",+ type="PAGE_TYPE",+ value_required=True,+ )++ attr_date_id = attr_date["id"]++ # Date time+ attr_date_time = attribute_create(+ e2e_staff_api_client,+ input_type="DATE_TIME",+ name="Date time",+ slug="date-time",+ type="PAGE_TYPE",+ value_required=True,+ )++ attr_date_time_id = attr_date_time["id"]++ # Plain text+ attr_plain_text = attribute_create(+ e2e_staff_api_client,+ input_type="PLAIN_TEXT",+ name="Plain text test",+ slug="plain-text-test",+ type="PAGE_TYPE",+ value_required=True,+ )++ attr_plain_text_id = attr_plain_text["id"]++ # Rich text+ attr_rich_text = attribute_create(+ e2e_staff_api_client,+ input_type="RICH_TEXT",+ name="Rich text test",+ slug="rich-text-test",+ type="PAGE_TYPE",+ value_required=True,+ )++ attr_rich_text_id = attr_rich_text["id"]++ # Numeric+ attr_numeric = attribute_create(+ e2e_staff_api_client,+ input_type="NUMERIC",+ name="Numeric test",+ slug="numeric-test",+ type="PAGE_TYPE",+ value_required=True,+ unit="G",+ )++ attr_numeric_id = attr_numeric["id"]++ # Boolean+ attr_bool = attribute_create(+ e2e_staff_api_client,+ input_type="BOOLEAN",+ name="Bool test",+ slug="bool-test",+ type="PAGE_TYPE",+ value_required=True,+ )++ attr_bool_id = attr_bool["id"]++ # Swatch+ values = [+ {"name": "black", "value": "#000000"},+ {"name": "blue", "value": "#4167E7"},+ ]++ attr_swatch = attribute_create(+ e2e_staff_api_client,+ input_type="SWATCH",+ name="Swatch test",+ slug="swatch-test",+ type="PAGE_TYPE",+ value_required=True,+ values=values,+ )++ attr_swatch_id = attr_swatch["id"]++ # Reference+ attr_reference = attribute_create(+ e2e_staff_api_client,+ input_type="REFERENCE",+ name="Reference test",+ slug="reference-test",+ type="PAGE_TYPE",+ value_required=True,+ entityType="PRODUCT",+ )++ attr_reference_id = attr_reference["id"]++ # File+ attr_file = attribute_create(+ e2e_staff_api_client,+ input_type="FILE",+ name="File test",+ slug="file-test",+ type="PAGE_TYPE",+ value_required=False,+ )++ attr_file_id = attr_file["id"]++ return (+ attr_dropdown_id,+ attr_multiselect_id,+ attr_date_id,+ attr_date_time_id,+ attr_plain_text_id,+ attr_rich_text_id,+ attr_numeric_id,+ attr_bool_id,+ attr_swatch_id,+ attr_reference_id,+ attr_file_id,+ )diff --git a/saleor/tests/e2e/pages/__init__.py b/saleor/tests/e2e/pages/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/tests/e2e/pages/test_create_page_with_all_attributes_types.py b/saleor/tests/e2e/pages/test_create_page_with_all_attributes_types.pynew file mode 100644index 0000000000..9628d0259a--- /dev/null+++ b/saleor/tests/e2e/pages/test_create_page_with_all_attributes_types.py@@ -0,0 +1,126 @@+import datetime+import json++import pytest+import pytz+from django.conf import settings++from ....tests.utils import dummy_editorjs+from ..attributes.utils import prepare_all_attributes+from ..pages.utils import create_page, create_page_type+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+++def test_create_page_with_each_of_attribute_types_core_0701(+ e2e_staff_api_client,+ permission_manage_page_types_and_attributes,+ permission_manage_pages,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_discounts,+ site_settings,+):+ # Before+ permissions = [+ permission_manage_page_types_and_attributes,+ permission_manage_pages,+ 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,+ 23,+ )++ (+ attr_dropdown_id,+ attr_multiselect_id,+ attr_date_id,+ attr_date_time_id,+ attr_plain_text_id,+ attr_rich_text_id,+ attr_numeric_id,+ attr_bool_id,+ attr_swatch_id,+ attr_reference_id,+ attr_file_id,+ ) = prepare_all_attributes(e2e_staff_api_client, attribute_type="PAGE_TYPE")++ # Step 1 - Create page type with all attributes+ add_attributes = [+ attr_dropdown_id,+ attr_multiselect_id,+ attr_date_id,+ attr_date_time_id,+ attr_plain_text_id,+ attr_rich_text_id,+ attr_numeric_id,+ attr_bool_id,+ attr_swatch_id,+ attr_reference_id,+ attr_file_id,+ ]+ page_type_data = create_page_type(e2e_staff_api_client, "Page Type", add_attributes)+ page_type_id = page_type_data["id"]+ assert page_type_data["name"] == "Page Type"+ assert len(page_type_data["attributes"]) == 11++ # Step 2 - Create page with all attributes+ expected_base_text = "Test rich attribute text"+ expected_rich_text = json.dumps(dummy_editorjs(expected_base_text))++ new_value = "new_test_value.txt"+ file_url = f"http://{site_settings.site.domain}{settings.MEDIA_URL}{new_value}"+ file_content_type = "text/plain"++ attributes = [+ {"id": attr_dropdown_id, "values": ["Freddy Torres"]},+ {"id": attr_multiselect_id, "values": ["security", "support"]},+ {"id": attr_date_id, "date": "2021-01-01"},+ {+ "id": attr_date_time_id,+ "dateTime": datetime.datetime(2023, 1, 1, tzinfo=pytz.utc),+ },+ {"id": attr_plain_text_id, "plainText": "test plain text"},+ {"id": attr_rich_text_id, "richText": expected_rich_text},+ {"id": attr_numeric_id, "numeric": 10},+ {"id": attr_bool_id, "boolean": True},+ {"id": attr_swatch_id, "values": ["blue"]},+ {"id": attr_reference_id, "references": [product_id]},+ {"id": attr_file_id, "file": file_url, "contentType": file_content_type},+ ]++ page = create_page(+ e2e_staff_api_client,+ page_type_id,+ title="test Page",+ is_published=True,+ attributes=attributes,+ )+ assert page["title"] == "test Page"+ assert page["isPublished"] is True+ attributes = page["attributes"]+ assert len(attributes) == 11diff --git a/saleor/tests/e2e/pages/utils/__init__.py b/saleor/tests/e2e/pages/utils/__init__.pynew file mode 100644index 0000000000..1cd32dd0a1--- /dev/null+++ b/saleor/tests/e2e/pages/utils/__init__.py@@ -0,0 +1,7 @@+from .page_create import create_page+from .page_type_create import create_page_type++__all__ = [+ "create_page",+ "create_page_type",+]diff --git a/saleor/tests/e2e/pages/utils/page_create.py b/saleor/tests/e2e/pages/utils/page_create.pynew file mode 100644index 0000000000..e023010a38--- /dev/null+++ b/saleor/tests/e2e/pages/utils/page_create.py@@ -0,0 +1,79 @@+from ...utils import get_graphql_content++PAGE_CREATE_MUTATION = """+mutation PageCreate($input: PageCreateInput!) {+ pageCreate(input: $input) {+ errors {+ field+ message+ code+ }+ page {+ id+ title+ slug+ isPublished+ publishedAt+ attributes{+ attribute{+ id+ }+ values{+ id+ name+ slug+ value+ inputType+ reference+ file{+ url+ contentType+ }+ richText+ plainText+ boolean+ date+ dateTime+ }+ }+ }+ }+}+"""+++def create_page(+ staff_api_client,+ page_type_id,+ title="test Page",+ is_published=True,+ publication_date=None,+ content=None,+ attributes=None,+):+ variables = {+ "input": {+ "pageType": page_type_id,+ "title": title,+ "content": content,+ "isPublished": is_published,+ "publicationDate": publication_date,+ "attributes": attributes,+ }+ }++ response = staff_api_client.post_graphql(+ PAGE_CREATE_MUTATION,+ variables,+ )++ content = get_graphql_content(response)++ data = content["data"]["pageCreate"]+ errors = data["errors"]+ assert errors == []++ page = data["page"]+ assert page["id"] is not None++ return pagediff --git a/saleor/tests/e2e/pages/utils/page_type_create.py b/saleor/tests/e2e/pages/utils/page_type_create.pynew file mode 100644index 0000000000..f6dfbe15ca--- /dev/null+++ b/saleor/tests/e2e/pages/utils/page_type_create.py@@ -0,0 +1,45 @@+from ...utils import get_graphql_content++PAGE_TYPE_CREATE_MUTATION = """+mutation PageTypeCreate($input: PageTypeCreateInput!) {+ pageTypeCreate(input: $input) {+ errors {+ field+ message+ code+ }+ pageType {+ id+ name+ slug+ attributes{+ id+ }+ }+ }+}+"""+++def create_page_type(+ staff_api_client,+ name="test Page Type",+ add_attributes=None,+):+ variables = {"input": {"name": name, "addAttributes": add_attributes}}++ response = staff_api_client.post_graphql(+ PAGE_TYPE_CREATE_MUTATION,+ variables,+ )++ content = get_graphql_content(response)++ data = content["data"]["pageTypeCreate"]+ errors = data["errors"]+ assert errors == []++ page = data["pageType"]+ assert page["id"] is not None++ return page