Skip to content

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

Add tests

michal407b43ced0f8
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 2361855ec1..b79ec5cc5d 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -47,7 +47,7 @@ def category_create(request, root_pk=None):
pgettext_lazy(
'Dashboard message', 'Added category %s') % category)
if root_pk:
- return redirect('dashboard:category-list', root_pk=root_pk)
+ return redirect('dashboard:category-detail', pk=root_pk)
else:
return redirect('dashboard:category-list')
ctx = {'category': category, 'form': form}
@@ -68,7 +68,7 @@ def category_edit(request, root_pk=None):
pgettext_lazy(
'Dashboard message', 'Updated category %s') % category)
if root_pk:
- return redirect('dashboard:category-list', root_pk=root_pk)
+ return redirect('dashboard:category-detail', pk=root_pk)
else:
return redirect('dashboard:category-list')
elif form.errors:
@@ -107,9 +107,9 @@ def category_delete(request, pk):
if root_pk:
if request.is_ajax():
response = {'redirectUrl': reverse(
- 'dashboard:category-list', kwargs={'root_pk': root_pk})}
+ 'dashboard:category-detail', kwargs={'pk': root_pk})}
return JsonResponse(response)
- return redirect('dashboard:category-list', root_pk=root_pk)
+ return redirect('dashboard:category-detail', pk=root_pk)
else:
if request.is_ajax():
response = {'redirectUrl': reverse('dashboard:category-list')}
diff --git a/templates/dashboard/category/detail.html b/templates/dashboard/category/detail.html
index 0218815209..9107daa8d4 100644
--- a/templates/dashboard/category/detail.html
+++ b/templates/dashboard/category/detail.html
@@ -15,7 +15,7 @@
{% block header_menu %}
{% if root %}
{% if root.parent %}
- {% url 'dashboard:category-list' root_pk=root.parent.pk as url %}
+ {% url 'dashboard:category-detail' pk=root.parent.pk as url %}
{% else %}
{% url 'dashboard:category-list' as url %}
{% endif %}
@@ -57,7 +57,7 @@
{% else %}
<li class="hide-on-med-and-down">
<a title="{{ node.name }}"
- href="{% url 'dashboard:category-list' root_pk=node.pk %}"
+ href="{% url 'dashboard:category-detail' pk=node.pk %}"
class="breadcrumbs--ellipsed-item">
{{ node.name }}
</a>
diff --git a/templates/dashboard/category/form.html b/templates/dashboard/category/form.html
index 290aecc2cf..8bc8c3ba78 100644
--- a/templates/dashboard/category/form.html
+++ b/templates/dashboard/category/form.html
@@ -9,7 +9,7 @@
{{ category }}
{% else %}
{% trans "Add new category" context "Category detail page title" %}
- {% endif %}
+ {% endif %}
- {% trans "Categories" context "Dashboard categories list" %} - {{ block.super }}
{% endblock %}
@@ -28,12 +28,12 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--history">
<li>
- <a href="{% url 'dashboard:category-list'%}" class="breadcrumbs--ellipsed-item">
+ <a href="{% url 'dashboard:category-list' %}" class="breadcrumbs--ellipsed-item">
{% trans "Categories" context "Dashboard categories list" %}
</a>
</li>
<li class="back-mobile">
- <a href="{% url 'dashboard:category-list' %}" class="breadcrumbs--ellipsed-item">
+ <a href="{% url 'dashboard:category-list' %}" class="breadcrumbs--ellipsed-item">
<svg data-src="{% static "dashboard/images/arrow-left.svg" %}" fill="#fff" width="20px" height="20px" />
</a>
</li>
@@ -76,7 +76,7 @@
</div>
<div class="card-action right-align">
{% if category.parent %}
- <a href="{% url 'dashboard:category-list' root_pk=category.parent.pk %}" class="btn btn-flat">
+ <a href="{% url 'dashboard:category-detail' pk=category.parent.pk %}" class="btn btn-flat">
{% trans "Cancel" context "Dashboard cancel action" %}
</a>
{% else %}
diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.html
index ad7cb1eeda..c139cde6d8 100644
--- a/templates/dashboard/category/list.html
+++ b/templates/dashboard/category/list.html
@@ -16,7 +16,7 @@
{% block header_menu %}
{% if root %}
{% if root.parent %}
- {% url 'dashboard:category-list' root_pk=root.parent.pk as url %}
+ {% url 'dashboard:category-detail' pk=root.parent.pk as url %}
{% else %}
{% url 'dashboard:category-list' as url %}
{% endif %}
@@ -94,7 +94,7 @@
{% else %}
<li class="hide-on-med-and-down">
<a title="{{ node.name }}"
- href="{% url 'dashboard:category-list' root_pk=node.pk %}"
+ href="{% url 'dashboard:category-detail' pk=node.pk %}"
class="breadcrumbs--ellipsed-item">
{{ node.name }}
</a>
diff --git a/tests/dashboard/test_category.py b/tests/dashboard/test_category.py
new file mode 100644
index 0000000000..e4d17d0cf6
--- /dev/null
+++ b/tests/dashboard/test_category.py
@@ -0,0 +1,70 @@
+import pytest
+from django.urls import reverse
+
+from saleor.product.models import Category
+
+
+def test_category_list(admin_client, default_category):
+ url = reverse('dashboard:category-list')
+ response = admin_client.get(url)
+ assert response.status_code == 200
+
+
+def test_category_add(admin_client):
+ assert len(Category.objects.all()) == 0
+ url = reverse('dashboard:category-add')
+ data = {'name': 'Cars', 'description': 'Fastest cars'}
+ response = admin_client.post(url, data, follow=True)
+ assert response.status_code == 200
+ assert len(Category.objects.all()) == 1
+
+
+def test_category_add_not_valid(admin_client):
+ assert len(Category.objects.all()) == 0
+ url = reverse('dashboard:category-add')
+ data = {}
+ response = admin_client.post(url, data, follow=True)
+ assert response.status_code == 200
+ assert len(Category.objects.all()) == 0
+
+
+def test_category_add_subcategory(admin_client, default_category):
+ assert len(Category.objects.all()) == 1
+ url = reverse('dashboard:category-add',
+ kwargs={'root_pk': default_category.pk})
+ data = {'name': 'Cars', 'description': 'Fastest cars'}
+ response = admin_client.post(url, data, follow=True)
+ assert response.status_code == 200
+ assert len(Category.objects.all()) == 2
+ default_category.refresh_from_db()
+ subcategories = default_category.get_children()
+ assert len(subcategories) == 1
+ assert subcategories[0].name == 'Cars'
+
+
+def test_category_edit(admin_client, default_category):
+ assert len(Category.objects.all()) == 1
+ url = reverse('dashboard:category-edit',
+ kwargs={'root_pk': default_category.pk})
+ data = {'name': 'Cars', 'description': 'Super fast!'}
+ response = admin_client.post(url, data, follow=True)
+ assert response.status_code == 200
+ assert len(Category.objects.all()) == 1
+ assert Category.objects.all()[0].name == 'Cars'
+
+
+def test_category_detail(admin_client, default_category):
+ assert len(Category.objects.all()) == 1
+ url = reverse('dashboard:category-detail',
+ kwargs={'pk': default_category.pk})
+ response = admin_client.post(url, follow=True)
+ assert response.status_code == 200
+
+
+def test_category_delete(admin_client, default_category):
+ assert len(Category.objects.all()) == 1
+ url = reverse('dashboard:category-delete',
+ kwargs={'pk': default_category.pk})
+ response = admin_client.post(url, follow=True)
+ assert response.status_code == 200
+ assert len(Category.objects.all()) == 0