Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Raise ValidationError on assigning unpushlished collection as homepage collection
oldPadavan5294ebdf111d
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.pyindex 26cf0864cb..be0bf3da01 100644--- a/saleor/dashboard/collection/forms.py+++ b/saleor/dashboard/collection/forms.py@@ -45,3 +45,13 @@ class AssignHomepageCollectionForm(forms.ModelForm):class Meta:model = SiteSettingsfields = ('homepage_collection',)++ def clean(self):+ cleaned_data = super().clean()+ homepage_collection = cleaned_data['homepage_collection']+ if homepage_collection and not homepage_collection.is_published:+ raise forms.ValidationError(+ pgettext_lazy(+ 'Homepage collection assign form error',+ 'Selected collection is not published'))+ return cleaned_datadiff --git a/tests/dashboard/test_collection.py b/tests/dashboard/test_collection.pyindex f025adf968..732ff653d6 100644--- a/tests/dashboard/test_collection.py+++ b/tests/dashboard/test_collection.py@@ -25,6 +25,18 @@ def test_set_homepage_collection(admin_client, collection, site_settings):assert site_settings.homepage_collection == collection+def test_set_unpublished_homepage_collection(+ admin_client, collection, site_settings):+ collection.is_published = False+ collection.save()+ data = {'homepage_collection': collection.pk}+ response = admin_client.post(reverse('dashboard:collection-list'), data)+ assert response.status_code == 200+ site_settings.refresh_from_db()+ assert site_settings.homepage_collection is None+ assert not response.context['assign_homepage_col_form'].is_valid()++def test_collection_form_name():data = {'name': 'Test Collection', 'products': []}form = CollectionForm(data)