Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Test collection

Mira Szewczyk726c7c47df2b
diff --git a/tests/test_collection.py b/tests/test_collection.py
new file mode 100644
index 0000000000..ed601309aa
--- /dev/null
+++ b/tests/test_collection.py
@@ -0,0 +1,56 @@
+import pytest
+
+from django.core.urlresolvers import reverse
+
+from .utils import get_redirect_location
+from saleor.product.models import Collection
+from saleor.dashboard.collection.forms import CollectionForm
+
+
+def collection(db):
+ collection = Collection.objects.create(name="Collection")
+ return collection
+
+
+def test_list_view(admin_client, collection):
+ response = admin_client.get(reverse('dashboard:collection-list'))
+ assert response.status_code == 200
+ context = response.context
+ assert list(context['collections']) == [collection]
+
+
+def test_collection_form_name():
+ data = {'name': 'Test Collection'}
+ form = CollectionForm(data)
+ assert form.is_valid()
+
+ collection = form.save()
+ assert collection.slug == 'test-collection'
+
+ invalid_form = CollectionForm()
+ assert not invalid_form.is_valid()
+
+
+def test_collection_form_with_products(product_in_stock):
+ data = {'name': 'Test collection',
+ 'products': [product_in_stock.id]}
+ form = CollectionForm(data)
+ assert form.is_valid()
+
+ collection = form.save()
+ assert collection.products.count() == 1
+
+
+def test_collection_create_view(admin_client):
+ response = admin_client.get(reverse('dashboard:collection-add'))
+ assert response.status_code == 200
+
+ data = {'name': 'Test'}
+ response = admin_client.post(reverse('dashboard:collection-add'), data)
+ assert response.status_code == 302
+
+ redirected_url = get_redirect_location(response)
+ assert redirected_url == reverse('dashboard:collection-list')