Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for createProductType muatation with unicode in name and slug
IKarbowiak4dc3e42a47d9
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 086b83d4b9..eaf3d820e9 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -5,7 +5,7 @@ import graphenefrom django.core.exceptions import ObjectDoesNotExist, ValidationErrorfrom django.db import transactionfrom django.db.models import Q, QuerySet-from django.template.defaultfilters import slugify+from django.utils.text import slugifyfrom graphene.types import InputObjectTypefrom graphql_relay import from_global_id@@ -649,7 +649,9 @@ class AttributeAssignmentMixin:get_or_create = attribute.values.get_or_createreturn tuple(get_or_create(- attribute=attribute, slug=slugify(value), defaults={"name": value}+ attribute=attribute,+ slug=slugify(value, allow_unicode=True),+ defaults={"name": value},)[0]for value in values)@@ -1474,10 +1476,12 @@ class ProductTypeCreate(ModelMutation):@classmethoddef _save_m2m(cls, info, instance, cleaned_data):super()._save_m2m(info, instance, cleaned_data)- if "product_attributes" in cleaned_data:- instance.product_attributes.set(cleaned_data["product_attributes"])- if "variant_attributes" in cleaned_data:- instance.variant_attributes.set(cleaned_data["variant_attributes"])+ product_attributes = cleaned_data.get("product_attributes")+ variant_attributes = cleaned_data.get("variant_attributes")+ if product_attributes is not None:+ instance.product_attributes.set(product_attributes)+ if variant_attributes is not None:+ instance.variant_attributes.set(variant_attributes)class ProductTypeUpdate(ProductTypeCreate):diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex 2086c74c03..515eea30b4 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -2373,24 +2373,16 @@ def test_product_type_query(assert data["productType"]["taxType"]["description"] == "Standard Taxes"-def test_product_type_create_mutation(- staff_api_client,- product_type,- permission_manage_products,- monkeypatch,- setup_vatlayer,-):- manager = PluginsManager(plugins=setup_vatlayer.PLUGINS)-- query = """+PRODUCT_TYPE_CREATE_MUTATION = """mutation createProductType(- $name: String!,- $slug: String!,- $taxCode: String!,- $hasVariants: Boolean!,- $isShippingRequired: Boolean!,+ $name: String,+ $slug: String,+ $taxCode: String,+ $hasVariants: Boolean,+ $isShippingRequired: Boolean,$productAttributes: [ID],- $variantAttributes: [ID]) {+ $variantAttributes: [ID],+ $weight: WeightScalar) {productTypeCreate(input: {name: $name,@@ -2399,29 +2391,48 @@ def test_product_type_create_mutation(hasVariants: $hasVariants,isShippingRequired: $isShippingRequired,productAttributes: $productAttributes,- variantAttributes: $variantAttributes}) {+ variantAttributes: $variantAttributes,+ weight: $weight}) {productType {- name- slug- taxRate- isShippingRequired- hasVariants- variantAttributes {name- values {+ slug+ taxRate+ isShippingRequired+ hasVariants+ variantAttributes {name+ values {+ name+ }}- }- productAttributes {- name- values {+ productAttributes {name+ values {+ name+ }}}+ productErrors {+ field+ message+ code}}+}- """+"""+++def test_product_type_create_mutation(+ staff_api_client,+ product_type,+ permission_manage_products,+ monkeypatch,+ setup_vatlayer,+):+ manager = PluginsManager(plugins=setup_vatlayer.PLUGINS)++ query = PRODUCT_TYPE_CREATE_MUTATIONproduct_type_name = "test type"slug = "test-type"has_variants = True@@ -2481,33 +2492,13 @@ def test_product_type_create_mutation(("test-slug", "test-slug"),(None, "test-product-type"),("", "test-product-type"),+ ("わたし-わ-にっぽん-です", "わたし-わ-にっぽん-です"),),)def test_create_product_type_with_given_slug(staff_api_client, permission_manage_products, input_slug, expected_slug):- query = """- mutation(- $name: String, $slug: String) {- productTypeCreate(- input: {- name: $name- slug: $slug- }- ) {- productType {- id- name- slug- }- productErrors {- field- message- code- }- }- }- """+ query = PRODUCT_TYPE_CREATE_MUTATIONname = "Test product type"variables = {"name": name, "slug": input_slug}response = staff_api_client.post_graphql(@@ -2519,30 +2510,26 @@ def test_create_product_type_with_given_slug(assert data["productType"]["slug"] == expected_slug+def test_create_product_type_with_unicode_in_name(+ staff_api_client, permission_manage_products+):+ query = PRODUCT_TYPE_CREATE_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"]["productTypeCreate"]+ assert not data["productErrors"]+ assert data["productType"]["name"] == name+ assert data["productType"]["slug"] == "わたし-わ-にっぽん-です"++def test_create_product_type_create_with_negative_weight(staff_api_client, permission_manage_products):- query = """- mutation(- $name: String, $weight: WeightScalar) {- productTypeCreate(- input: {- name: $name- weight: $weight- }- ) {- productType {- id- name- }- productErrors {- field- message- code- }- }- }- """+ query = PRODUCT_TYPE_CREATE_MUTATIONname = "Test product type"variables = {"name": name, "weight": -1.1}response = staff_api_client.post_graphql(