Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests
Piotr Grundas2546579e67de
diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.pyindex caf067f1a9..618e321c5d 100644--- a/saleor/graphql/attribute/utils.py+++ b/saleor/graphql/attribute/utils.py@@ -394,13 +394,13 @@ class AttributeAssignmentMixin:errors.append(ValidationError(str(e),- code="INVALID",+ code=ProductErrorCode.INVALID.value,params={"attributes": [attr_values.global_id]},))if errors:- raise ValidationError(errors)+ raise ValidationError({"attributes": errors})def get_variant_selection_attributes(qs: "QuerySet"):diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.pyindex 3a307d0ac8..942ddbd6f2 100644--- a/saleor/graphql/product/tests/test_variant.py+++ b/saleor/graphql/product/tests/test_variant.py@@ -1050,6 +1050,60 @@ def test_create_variant_invalid_variant_attributes(assert error in errors+def test_create_variant_attributes_save_error(+ permission_manage_products,+ product,+ product_type,+ staff_api_client,+ text_attribute,+ warehouse,+):+ query = CREATE_VARIANT_MUTATION+ product_id = graphene.Node.to_global_id("Product", product.pk)+ sku = "1"+ price = 1.32+ cost_price = 3.22+ weight = 10.22++ product_type.variant_attributes.add(text_attribute)+ attr_id = graphene.Node.to_global_id("Attribute", text_attribute.id)++ stocks = [+ {+ "warehouse": graphene.Node.to_global_id("Warehouse", warehouse.pk),+ "quantity": 20,+ }+ ]+ variables = {+ "productId": product_id,+ "sku": sku,+ "stocks": stocks,+ "costPrice": cost_price,+ "price": price,+ "weight": weight,+ "attributes": [+ {"id": attr_id, "values": ["long text" * 100]},+ ],+ "trackInventory": True,+ }+ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)++ data = content["data"]["productVariantCreate"]+ errors = data["productErrors"]++ assert not data["productVariant"]+ assert len(errors) == 1+ assert errors[0] == {+ "attributes": [attr_id],+ "code": ProductErrorCode.INVALID.name,+ "field": "attributes",+ "message": ANY,+ }++def test_create_product_variant_update_with_new_attributes(staff_api_client, permission_manage_products, product, size_attribute):diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex b15530fce0..2f7606b441 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -772,6 +772,22 @@ def color_attribute(db): # pylint: disable=W0613return attribute+def text_attribute(db): # pylint: disable=W0613+ attribute = Attribute.objects.create(+ slug="text",+ name="Text",+ type=AttributeInputType.TEXT,+ filterable_in_storefront=True,+ filterable_in_dashboard=True,+ available_in_grid=True,+ )+ AttributeValue.objects.create(+ attribute=attribute, name="Some cool text", slug="come-cool-text"+ )+ return attribute++@pytest.fixturedef color_attribute_without_values(db): # pylint: disable=W0613return Attribute.objects.create(