From 0841eeeeed03c8de48aa0d9fe570097ce3eb56a0 Mon Sep 17 00:00:00 2001 From: duker33 Date: Tue, 11 Jun 2019 19:01:38 +0300 Subject: [PATCH 1/3] #836 Tests for the catalog matrix --- shopelectro/tests/tests_views.py | 41 +++++++++++++++++++++++++++++++- shopelectro/views/catalog.py | 5 ---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py index d5951e12..fac37c0b 100644 --- a/shopelectro/tests/tests_views.py +++ b/shopelectro/tests/tests_views.py @@ -16,7 +16,7 @@ from django.db.models import Q from django.http import HttpResponse from django.test import override_settings, TestCase, tag -from django.urls import reverse +from django.urls import reverse, reverse_lazy from django.utils.translation import ugettext as _ from catalog.helpers import reverse_catalog_url @@ -543,6 +543,45 @@ def test_category_matrix_page(self): self.assertEqual(from_db.name, from_app.a.text) +@tag('fast', 'catalog') +class CategoriesMatrix(BaseCatalogTestCase): + + fixtures = ['dump.json'] + URL = reverse_lazy('custom_page', kwargs={'page': 'catalog'}) + + def get_page(self): + return self.client.get(self.URL) + + def get_soup(self) -> BeautifulSoup: + return BeautifulSoup( + self.get_page().content.decode('utf-8'), + 'html.parser' + ) + + def test_roots_sorting(self): + soup = self.get_soup() + from_page = soup.find_all('h2') + from_db = ( + models.Category.objects.bind_fields().active() + .filter(level=0) + .order_by('page__position', 'name') + ).values_list('name', flat=True) + self.assertEqual([c.text for c in from_page], list(from_db)) + + def test_second_level_sorting(self): + soup = self.get_soup() + from_page = soup.select('.second-level-category > a') + from_db = ( + models.Category.objects.bind_fields().active() + .filter(level=1) + .order_by( + 'parent__page__position', 'parent__name', + 'page__position', 'name' + ) + ).values_list('name', flat=True) + self.assertEqual([c.text for c in from_page], list(from_db)) + + @tag('fast') class IndexPage(TestCase): diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py index f862bfc5..fca46578 100644 --- a/shopelectro/views/catalog.py +++ b/shopelectro/views/catalog.py @@ -18,16 +18,11 @@ from shopelectro.exception import Http400 from shopelectro.views.helpers import set_csrf_cookie - # block numeric indexes to limit MATRIX_BLOCKS_TO_LIMIT = [3, 5] MATRIX_BLOCK_SIZE = 7 -# @todo #822:60m Create tests for the catalog matrix. -# This cases are would be good to test: -# - Matrix sorting by page position -# - Block items limiting def category_matrix(request, page: str): assert page == 'catalog' roots = ( From 8c26fb4385a1bfdfa0b719f0312cd800392fb431 Mon Sep 17 00:00:00 2001 From: duker33 Date: Wed, 12 Jun 2019 15:19:25 +0300 Subject: [PATCH 2/3] #836 Review#1 fix. Drop reverse_lazy --- shopelectro/tests/tests_views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py index fac37c0b..20bdc1dc 100644 --- a/shopelectro/tests/tests_views.py +++ b/shopelectro/tests/tests_views.py @@ -16,7 +16,7 @@ from django.db.models import Q from django.http import HttpResponse from django.test import override_settings, TestCase, tag -from django.urls import reverse, reverse_lazy +from django.urls import reverse from django.utils.translation import ugettext as _ from catalog.helpers import reverse_catalog_url @@ -547,10 +547,11 @@ def test_category_matrix_page(self): class CategoriesMatrix(BaseCatalogTestCase): fixtures = ['dump.json'] - URL = reverse_lazy('custom_page', kwargs={'page': 'catalog'}) def get_page(self): - return self.client.get(self.URL) + return self.client.get( + url=reverse('custom_page', kwargs={'page': 'catalog'}) + ) def get_soup(self) -> BeautifulSoup: return BeautifulSoup( From 0ec8fc34d04e0062e3aa1793237fbd81370182b5 Mon Sep 17 00:00:00 2001 From: duker33 Date: Sat, 15 Jun 2019 12:06:18 +0300 Subject: [PATCH 3/3] #836 Minor fix for the new test --- shopelectro/tests/tests_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py index 20bdc1dc..924a3654 100644 --- a/shopelectro/tests/tests_views.py +++ b/shopelectro/tests/tests_views.py @@ -550,7 +550,7 @@ class CategoriesMatrix(BaseCatalogTestCase): def get_page(self): return self.client.get( - url=reverse('custom_page', kwargs={'page': 'catalog'}) + path=reverse('custom_page', kwargs={'page': 'catalog'}) ) def get_soup(self) -> BeautifulSoup: