Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests for add 'is_published' validation in product mutations and fix typo in dashboard validation
IKarbowiak5ee85858fa34
diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex 1f5acdd5a0..f604cbeb6b 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -1177,6 +1177,40 @@ def test_product_create_without_product_type(assert errors[0]["message"] == "This field cannot be null."+def test_product_create_without_category_and_true_is_published_value(+ staff_api_client, permission_manage_products, product_type+):+ query = """+ mutation createProduct($productTypeId: ID!) {+ productCreate(input: {+ name: "Product",+ basePrice: "2.5",+ productType: $productTypeId,+ isPublished: true+ }) {+ product {+ id+ }+ errors {+ message+ field+ }+ }+ }+ """++ product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)+ response = staff_api_client.post_graphql(+ query,+ {"productTypeId": product_type_id},+ permissions=[permission_manage_products],+ )+ errors = get_graphql_content(response)["data"]["productCreate"]["errors"]++ assert errors[0]["field"] == "isPublished"+ assert errors[0]["message"] == "You must select a category to be able to publish"++def test_update_product(staff_api_client,category,@@ -1563,6 +1597,49 @@ def test_update_product_without_variants_sku_duplication(assert data["errors"][0]["message"] == "Product with this SKU already exists."+def test_update_product_withput_category_and_true_is_published_value(+ staff_api_client, permission_manage_products, product+):+ query = """+ mutation updateProduct(+ $productId: ID!,+ $isPublished: Boolean)+ {+ productUpdate(+ id: $productId,+ input: {+ isPublished: $isPublished+ })+ {+ product {+ id+ }+ errors {+ message+ field+ }+ }+ }"""++ product.category = None+ product.save()++ product_id = graphene.Node.to_global_id("Product", product.id)+ variables = {"productId": product_id, "isPublished": True}++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )++ data = get_graphql_content(response)["data"]["productUpdate"]+ assert data["errors"]+ assert data["errors"][0]["field"] == "isPublished"+ assert (+ data["errors"][0]["message"]+ == "You must select a category to be able to publish"+ )++def test_delete_product(staff_api_client, product, permission_manage_products):query = """mutation DeleteProduct($id: ID!) {diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.pyindex c4d56867d7..98e9e45771 100644--- a/tests/dashboard/test_product.py+++ b/tests/dashboard/test_product.py@@ -1358,4 +1358,6 @@ def test_product_form_publish_product_without_category(product_without_category)form = ProductForm(data, instance=product_without_category)assert not form.is_valid()- assert form.errors == {"is_published": ["You must add cateogry to publish product"]}+ assert form.errors == {+ "is_published": ["You must select a category to be able to publish"]+ }