Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#836 Test categories matrix sorting #874

Merged
merged 3 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this to get_page and use reverse instead of reverse_lazy


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block items limiting

It seems you still haven't test this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y, did it intentionally. Updated PR body about it

def category_matrix(request, page: str):
assert page == 'catalog'
roots = (
Expand Down