Skip to content

Commit

Permalink
[Test] Should be able to create a page with each type of attribute (#…
Browse files Browse the repository at this point in the history
…14600)

* add create page with attributes draft test

* update test of next attributes

* add attr reference

* move creating all attributes to helper

* add file attrobute
  • Loading branch information
szczecha committed Nov 3, 2023
1 parent 1ef2e2a commit 0087ab3
Show file tree
Hide file tree
Showing 8 changed files with 436 additions and 3 deletions.
5 changes: 2 additions & 3 deletions saleor/tests/e2e/attributes/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions saleor/tests/e2e/attributes/utils/create_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -33,6 +36,9 @@ def attribute_create(
"type": type,
"valueRequired": value_required,
"isVariantOnly": is_variant_only,
"values": values,
"unit": unit,
"entityType": entityType,
}
}

Expand Down
171 changes: 171 additions & 0 deletions saleor/tests/e2e/attributes/utils/prepare_attributes.py
Original file line number Diff line number Diff line change
@@ -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,
)
Empty file.
126 changes: 126 additions & 0 deletions saleor/tests/e2e/pages/test_create_page_with_all_attributes_types.py
Original file line number Diff line number Diff line change
@@ -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


@pytest.mark.e2e
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) == 11
7 changes: 7 additions & 0 deletions saleor/tests/e2e/pages/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .page_create import create_page
from .page_type_create import create_page_type

__all__ = [
"create_page",
"create_page_type",
]
Loading

0 comments on commit 0087ab3

Please sign in to comment.