Skip to content

Commit

Permalink
#836 Tests for the catalog matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Jun 12, 2019
1 parent 83c7c4a commit 0841eee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
41 changes: 40 additions & 1 deletion shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down
5 changes: 0 additions & 5 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 0841eee

Please sign in to comment.