Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
[Test] Should create a product with all attribute types created in bulk (#14609)
Anna Szczęch616b3211dfd7
diff --git a/saleor/tests/e2e/attributes/utils/__init__.py b/saleor/tests/e2e/attributes/utils/__init__.pyindex 7720dd248d..7d6d2fd28b 100644--- a/saleor/tests/e2e/attributes/utils/__init__.py+++ b/saleor/tests/e2e/attributes/utils/__init__.py@@ -1,4 +1,10 @@+from .attribute_bulk_create import bulk_create_attributesfrom .create_attribute import attribute_create-from .prepare_attributes import prepare_all_attributes+from .prepare_attributes import prepare_all_attributes, prepare_all_attributes_in_bulk-__all__ = ["attribute_create", "prepare_all_attributes"]+__all__ = [+ "attribute_create",+ "prepare_all_attributes",+ "bulk_create_attributes",+ "prepare_all_attributes_in_bulk",+]diff --git a/saleor/tests/e2e/attributes/utils/attribute_bulk_create.py b/saleor/tests/e2e/attributes/utils/attribute_bulk_create.pynew file mode 100644index 0000000000..63e63b8995--- /dev/null+++ b/saleor/tests/e2e/attributes/utils/attribute_bulk_create.py@@ -0,0 +1,61 @@+from ...utils import get_graphql_content++ATTRIBUTE_BULK_CREATE_MUTATION = """+mutation AttributeBulkCreate($attributes: [AttributeCreateInput!]!) {+ attributeBulkCreate(attributes: $attributes) {+ results {+ errors {+ path+ message+ code+ }+ attribute {+ id+ name+ slug+ choices(first: 10) {+ edges {+ node {+ id+ name+ slug+ value+ inputType+ reference+ file {+ url+ contentType+ }+ richText+ plainText+ boolean+ date+ dateTime+ }+ }+ }+ }+ }+ count+ }+}+"""+++def bulk_create_attributes(+ staff_api_client,+ attributes=None,+):+ variables = {"attributes": attributes}++ response = staff_api_client.post_graphql(+ ATTRIBUTE_BULK_CREATE_MUTATION,+ variables,+ )+ content = get_graphql_content(response)++ assert content["data"]["attributeBulkCreate"]["results"][0]["errors"] == []++ data = content["data"]["attributeBulkCreate"]++ return datadiff --git a/saleor/tests/e2e/attributes/utils/prepare_attributes.py b/saleor/tests/e2e/attributes/utils/prepare_attributes.pyindex caf79f6541..06ea59e32f 100644--- a/saleor/tests/e2e/attributes/utils/prepare_attributes.py+++ b/saleor/tests/e2e/attributes/utils/prepare_attributes.py@@ -1,7 +1,8 @@+from .attribute_bulk_create import bulk_create_attributesfrom .create_attribute import attribute_create-def prepare_all_attributes(e2e_staff_api_client, attribute_type):+def prepare_all_attributes(e2e_staff_api_client, attribute_type, entity_type):# Dropdownvalues = [{"name": "Freddy Torres"},@@ -13,7 +14,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="DROPDOWN",name="Author",slug="author",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,values=values,)@@ -33,7 +34,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="MULTISELECT",name="Department",slug="department",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,values=values,)@@ -46,7 +47,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="DATE",name="Date",slug="date",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,)@@ -58,7 +59,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="DATE_TIME",name="Date time",slug="date-time",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,)@@ -70,7 +71,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="PLAIN_TEXT",name="Plain text test",slug="plain-text-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,)@@ -82,7 +83,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="RICH_TEXT",name="Rich text test",slug="rich-text-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,)@@ -94,7 +95,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="NUMERIC",name="Numeric test",slug="numeric-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,unit="G",)@@ -107,7 +108,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="BOOLEAN",name="Bool test",slug="bool-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,)@@ -124,7 +125,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="SWATCH",name="Swatch test",slug="swatch-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,values=values,)@@ -137,9 +138,9 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="REFERENCE",name="Reference test",slug="reference-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=True,- entityType="PRODUCT",+ entityType=entity_type,)attr_reference_id = attr_reference["id"]@@ -150,7 +151,7 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):input_type="FILE",name="File test",slug="file-test",- type="PAGE_TYPE",+ type=attribute_type,value_required=False,)@@ -169,3 +170,128 @@ def prepare_all_attributes(e2e_staff_api_client, attribute_type):attr_reference_id,attr_file_id,)+++def prepare_all_attributes_in_bulk(e2e_staff_api_client, attribute_type, entity_type):+ attributes = [+ {+ "name": "Dropdown",+ "slug": "dropdown",+ "inputType": "DROPDOWN",+ "type": attribute_type,+ "valueRequired": True,+ "values": [+ {"name": "Freddy Torres"},+ {"name": "Isabella Smith"},+ {"name": "Hayden Blake"},+ ],+ },+ {+ "name": "Multiselect",+ "slug": "multiselect",+ "inputType": "MULTISELECT",+ "type": attribute_type,+ "valueRequired": True,+ "values": [+ {"name": "Security"},+ {"name": "Support"},+ {"name": "Medical"},+ {"name": "General"},+ ],+ },+ {+ "name": "Date",+ "slug": "date",+ "inputType": "DATE",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Date time",+ "slug": "date-time",+ "inputType": "DATE_TIME",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Plain text",+ "slug": "plain-text",+ "inputType": "PLAIN_TEXT",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Rich text",+ "slug": "rich-text",+ "inputType": "RICH_TEXT",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Numeric",+ "slug": "numeric",+ "inputType": "NUMERIC",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Boolean",+ "slug": "boolean",+ "inputType": "BOOLEAN",+ "type": attribute_type,+ "valueRequired": True,+ },+ {+ "name": "Swatch",+ "slug": "swatch",+ "inputType": "SWATCH",+ "type": attribute_type,+ "valueRequired": True,+ "values": [+ {"name": "black", "value": "#000000"},+ {"name": "blue", "value": "#4167E7"},+ ],+ },+ {+ "name": "Reference",+ "slug": "reference",+ "inputType": "REFERENCE",+ "type": attribute_type,+ "valueRequired": False,+ "entityType": entity_type,+ },+ {+ "name": "File",+ "slug": "file",+ "inputType": "FILE",+ "type": attribute_type,+ "valueRequired": False,+ },+ ]+ attributes_data = bulk_create_attributes(e2e_staff_api_client, attributes)++ attr_dropdown_id = attributes_data["results"][0]["attribute"]["id"]+ attr_multiselect_id = attributes_data["results"][1]["attribute"]["id"]+ attr_date_id = attributes_data["results"][2]["attribute"]["id"]+ attr_date_time_id = attributes_data["results"][3]["attribute"]["id"]+ attr_plain_text_id = attributes_data["results"][4]["attribute"]["id"]+ attr_rich_text_id = attributes_data["results"][5]["attribute"]["id"]+ attr_numeric_id = attributes_data["results"][6]["attribute"]["id"]+ attr_bool_id = attributes_data["results"][7]["attribute"]["id"]+ attr_swatch_id = attributes_data["results"][8]["attribute"]["id"]+ attr_reference_id = attributes_data["results"][9]["attribute"]["id"]+ attr_file_id = attributes_data["results"][10]["attribute"]["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/test_create_page_with_all_attributes_types.py b/saleor/tests/e2e/pages/test_create_page_with_all_attributes_types.pyindex 9628d0259a..3f3fa78d86 100644--- 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.py@@ -22,7 +22,6 @@ def test_create_page_with_each_of_attribute_types_core_0701(permission_manage_channels,permission_manage_shipping,permission_manage_product_types_and_attributes,- permission_manage_discounts,site_settings,):# Before@@ -33,7 +32,6 @@ def test_create_page_with_each_of_attribute_types_core_0701(permission_manage_channels,permission_manage_shipping,permission_manage_product_types_and_attributes,- permission_manage_discounts,]assign_permissions(e2e_staff_api_client, permissions)@@ -67,7 +65,11 @@ def test_create_page_with_each_of_attribute_types_core_0701(attr_swatch_id,attr_reference_id,attr_file_id,- ) = prepare_all_attributes(e2e_staff_api_client, attribute_type="PAGE_TYPE")+ ) = prepare_all_attributes(+ e2e_staff_api_client,+ attribute_type="PAGE_TYPE",+ entity_type="PRODUCT",+ )# Step 1 - Create page type with all attributesadd_attributes = [diff --git a/saleor/tests/e2e/product/test_create_product_with_all_attributes_types.py b/saleor/tests/e2e/product/test_create_product_with_all_attributes_types.pynew file mode 100644index 0000000000..ae2aa0f15f--- /dev/null+++ b/saleor/tests/e2e/product/test_create_product_with_all_attributes_types.py@@ -0,0 +1,113 @@+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_in_bulk+from ..pages.utils import create_page, create_page_type+from ..utils import assign_permissions+from .utils import (+ create_category,+ create_product,+ create_product_type,+)+++def test_create_product_with_attributes_created_in_bulk_core_0704(+ e2e_staff_api_client,+ permission_manage_page_types_and_attributes,+ permission_manage_pages,+ permission_manage_products,+ permission_manage_product_types_and_attributes,+ site_settings,+):+ # Before+ permissions = [+ permission_manage_page_types_and_attributes,+ permission_manage_pages,+ permission_manage_products,+ permission_manage_product_types_and_attributes,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ category_data = create_category(e2e_staff_api_client)+ category_id = category_data["id"]+ page_type_data = create_page_type(e2e_staff_api_client)+ page_type_id = page_type_data["id"]+ page_data = create_page(e2e_staff_api_client, page_type_id)+ page_id = page_data["id"]++ # Step 1 - Bulk create attributes for each input type+ (+ 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_in_bulk(+ e2e_staff_api_client, attribute_type="PRODUCT_TYPE", entity_type="PAGE"+ )++ # Step 2 - Create product 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,+ ]+ product_type_data = create_product_type(+ e2e_staff_api_client,+ slug="all-attributes-type",+ product_attributes=add_attributes,+ )+ product_type_id = product_type_data["id"]+ assert len(product_type_data["productAttributes"]) == 11++ # Step 3 - Create product 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, "dropdown": {"value": "Isabella Smith"}},+ {"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": [page_id]},+ {"id": attr_file_id, "file": file_url, "contentType": file_content_type},+ ]+ product_data = create_product(+ e2e_staff_api_client,+ product_type_id,+ category_id,+ attributes=attributes,+ )+ attributes = product_data["attributes"]+ assert len(product_data["attributes"]) == 11