Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test category, attribute and collection mutations for inputs with unicode
IKarbowiakb9a4eae7d3f3
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex ecb3a666b7..bf61681660 100644--- a/saleor/graphql/product/mutations/attributes.py+++ b/saleor/graphql/product/mutations/attributes.py@@ -4,7 +4,7 @@ import graphenefrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom django.db import transactionfrom django.db.models import Q-from django.template.defaultfilters import slugify+from django.utils.text import slugifyfrom ....core.permissions import ProductPermissionsfrom ....product import AttributeInputType, models@@ -111,7 +111,7 @@ class AttributeMixin:# Check values uniqueness in case of creating new attribute.existing_values = attribute.values.values_list("slug", flat=True)for value_data in values_input:- slug = slugify(value_data["name"])+ slug = slugify(value_data["name"], allow_unicode=True)if slug in existing_values:msg = ("Value %s already exists within this attribute."@@ -125,7 +125,10 @@ class AttributeMixin:})- new_slugs = [slugify(value_data["name"]) for value_data in values_input]+ new_slugs = [+ slugify(value_data["name"], allow_unicode=True)+ for value_data in values_input+ ]if len(set(new_slugs)) != len(new_slugs):raise ValidationError({@@ -149,7 +152,7 @@ class AttributeMixin:returnfor value_data in values_input:- value_data["slug"] = slugify(value_data["name"])+ value_data["slug"] = slugify(value_data["name"], allow_unicode=True)attribute_value = models.AttributeValue(**value_data, attribute=attribute)try:attribute_value.full_clean()@@ -589,7 +592,7 @@ class AttributeValueCreate(ModelMutation):@classmethoddef clean_input(cls, info, instance, data):cleaned_input = super().clean_input(info, instance, data)- cleaned_input["slug"] = slugify(cleaned_input["name"])+ cleaned_input["slug"] = slugify(cleaned_input["name"], allow_unicode=True)return cleaned_input@classmethod@@ -632,7 +635,7 @@ class AttributeValueUpdate(ModelMutation):def clean_input(cls, info, instance, data):cleaned_input = super().clean_input(info, instance, data)if "name" in cleaned_input:- cleaned_input["slug"] = slugify(cleaned_input["name"])+ cleaned_input["slug"] = slugify(cleaned_input["name"], allow_unicode=True)return cleaned_input@classmethoddiff --git a/saleor/graphql/product/tests/test_attributes.py b/saleor/graphql/product/tests/test_attributes.pyindex 2586cb039e..3851c35872 100644--- a/saleor/graphql/product/tests/test_attributes.py+++ b/saleor/graphql/product/tests/test_attributes.py@@ -5,7 +5,7 @@ import grapheneimport pytestfrom django.core.exceptions import ValidationErrorfrom django.db.models import Q-from django.template.defaultfilters import slugify+from django.utils.text import slugifyfrom graphene.utils.str_converters import to_camel_casefrom ....product import AttributeInputType@@ -434,8 +434,10 @@ def test_attributes_in_collection_query(CREATE_ATTRIBUTES_QUERY = """- mutation createAttribute($name: String!, $values: [AttributeValueCreateInput]) {- attributeCreate(input: {name: $name, values: $values}) {+ mutation createAttribute(+ $name: String!, $slug: String, $values: [AttributeValueCreateInput]+ ){+ attributeCreate(input: {name: $name, values: $values, slug: $slug}) {errors {fieldmessage@@ -497,7 +499,12 @@ def test_create_attribute_and_attribute_values(@pytest.mark.parametrize("input_slug, expected_slug",- (("my-slug", "my-slug"), (None, "my-name"), ("", "my-name"),),+ (+ ("my-slug", "my-slug"),+ (None, "my-name"),+ ("", "my-name"),+ ("わたし-わ-にっぽん-です", "わたし-わ-にっぽん-です"),+ ),)def test_create_attribute_with_given_slug(staff_api_client, permission_manage_products, input_slug, expected_slug,@@ -527,6 +534,23 @@ def test_create_attribute_with_given_slug(assert content["data"]["attributeCreate"]["attribute"]["slug"] == expected_slug+def test_create_attribute_value_name_and_slug_with_unicode(+ staff_api_client, permission_manage_products+):+ query = CREATE_ATTRIBUTES_QUERY+ name = "わたし わ にっぽん です"+ slug = "わたし-わ-にっぽん-で"+ variables = {"name": name, "slug": slug}+ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)+ data = content["data"]["attributeCreate"]+ assert not data["productErrors"]+ assert data["attribute"]["name"] == name+ assert data["attribute"]["slug"] == slug++@pytest.mark.parametrize("name_1, name_2, error_msg, error_code",(diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex 8d934ed5c1..39dccd6314 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -157,15 +157,12 @@ def test_collections_query(assert len(edges) == 2-def test_create_collection(- monkeypatch, staff_api_client, product_list, media_root, permission_manage_products-):- query = """+CREATE_COLLECTION_MUTATION = """mutation createCollection(- $name: String!, $slug: String!, $description: String,+ $name: String!, $slug: String, $description: String,$descriptionJson: JSONString, $products: [ID],- $backgroundImage: Upload!, $backgroundImageAlt: String,- $isPublished: Boolean!, $publicationDate: Date) {+ $backgroundImage: Upload, $backgroundImageAlt: String,+ $isPublished: Boolean, $publicationDate: Date) {collectionCreate(input: {name: $name,@@ -190,9 +187,20 @@ def test_create_collection(alt}}+ productErrors {+ field+ message+ code+ }}}- """+"""+++def test_create_collection(+ monkeypatch, staff_api_client, product_list, media_root, permission_manage_products+):+ query = CREATE_COLLECTION_MUTATIONmock_create_thumbnails = Mock(return_value=None)monkeypatch.setattr(@@ -243,20 +251,7 @@ def test_create_collection(def test_create_collection_without_background_image(monkeypatch, staff_api_client, product_list, permission_manage_products):- query = """- mutation createCollection(- $name: String!, $slug: String!, $products: [ID], $isPublished: Boolean!) {- collectionCreate(- input: {name: $name, slug: $slug, products: $products,- isPublished: $isPublished}) {-- errors {- field- message- }- }- }- """+ query = CREATE_COLLECTION_MUTATIONmock_create_thumbnails = Mock(return_value=None)monkeypatch.setattr(@@ -277,33 +272,17 @@ def test_create_collection_without_background_image(@pytest.mark.parametrize("input_slug, expected_slug",- (("test-slug", "test-slug"), (None, "test-collection"), ("", "test-collection"),),+ (+ ("test-slug", "test-slug"),+ (None, "test-collection"),+ ("", "test-collection"),+ ("わたし-わ-にっぽん-です", "わたし-わ-にっぽん-です"),+ ),)def test_create_collection_with_given_slug(staff_api_client, permission_manage_products, input_slug, expected_slug):- query = """- mutation(- $name: String, $slug: String) {- collectionCreate(- input: {- name: $name- slug: $slug- }- ) {- collection {- id- name- slug- }- productErrors {- field- message- code- }- }- }- """+ query = CREATE_COLLECTION_MUTATIONname = "Test collection"variables = {"name": name, "slug": input_slug}response = staff_api_client.post_graphql(@@ -315,6 +294,22 @@ def test_create_collection_with_given_slug(assert data["collection"]["slug"] == expected_slug+def test_create_collection_name_with_unicode(+ staff_api_client, permission_manage_products+):+ query = CREATE_COLLECTION_MUTATION+ name = "わたし わ にっぽん です"+ variables = {"name": name}+ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)+ data = content["data"]["collectionCreate"]+ assert not data["productErrors"]+ assert data["collection"]["name"] == name+ assert data["collection"]["slug"] == "わたし-わ-にっぽん-です"++def test_update_collection(monkeypatch, staff_api_client, collection, permission_manage_products):