Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests for 'is_published' Product validation in dashboard forms
IKarbowiake2b0390e0bf0
diff --git a/tests/conftest.py b/tests/conftest.pyindex 26bcd52a6b..25ecbcefc6 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -483,6 +483,7 @@ def product(product_type, category):price=Money("10.00", "USD"),product_type=product_type,category=category,+ is_published=True,)associate_attribute_values_to_instance(product, product_attr, product_attr_value)@@ -610,6 +611,13 @@ def product_without_shipping(category):return product+def product_without_category(product):+ product.category = None+ product.save()+ return product++@pytest.fixturedef product_list(product_type, category):product_attr = product_type.product_attributes.first()@@ -753,6 +761,7 @@ def product_with_images(product_type, category, media_root):price=Money("10.00", "USD"),product_type=product_type,category=category,+ is_published=True,)file_mock_0 = MagicMock(spec=File, name="FileMock0")file_mock_0.name = "image0.jpg"diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.pyindex 96a305c201..e0b7536a61 100644--- a/tests/dashboard/test_product.py+++ b/tests/dashboard/test_product.py@@ -1297,3 +1297,43 @@ def test_product_form_seo_description_too_long(unavailable_product):"form sixth. Image moving earth without")assert new_seo_description.endswith("...") or new_seo_description[-1] == "…"+++def test_product_form_publish_product_with_category(product):+ data = model_to_dict(product)+ data["price_0"] = 20+ data["price_1"] = "USD"+ data["description"] = "Test description"++ form = ProductForm(data, instance=product)+ assert form.is_valid()+ assert form.errors == {}++ form.save()+ assert product.is_published+++def test_product_form_without_category(product_without_category):+ data = model_to_dict(product_without_category)+ data["price_0"] = 20+ data["price_1"] = "USD"+ data["description"] = "Test description"++ form = ProductForm(data, instance=product_without_category)+ assert form.is_valid()+ assert form.errors == {}++ form.save()+ assert not product_without_category.is_published+++def test_product_form_publish_product_without_category(product_without_category):+ product_without_category.is_published = True+ data = model_to_dict(product_without_category)+ data["price_0"] = 20+ data["price_1"] = "USD"+ data["description"] = "Test description"++ form = ProductForm(data, instance=product_without_category)+ assert not form.is_valid()+ assert form.errors == {"is_published": ["You must add cateogry to publish product"]}