From 2877085db8da5d4aab558c2f08443dbba4b50a0e Mon Sep 17 00:00:00 2001 From: duker33 Date: Wed, 18 Sep 2019 09:54:05 +0300 Subject: [PATCH] #952 Test category root crumb siblings (#957) * #952 Test root crumbs * #887 Prove category siblings failure with test --- shopelectro/tests/tests_views.py | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py index 8abcd441..6a17c0d6 100644 --- a/shopelectro/tests/tests_views.py +++ b/shopelectro/tests/tests_views.py @@ -6,6 +6,7 @@ """ import json import re +import unittest from functools import partial from itertools import chain from operator import attrgetter @@ -24,7 +25,8 @@ from pages import models as pages_models from pages.urls import reverse_custom_page from shopelectro import models, views -from shopelectro.views.service import generate_md5_for_ya_kassa, YANDEX_REQUEST_PARAM +from shopelectro.views.service import generate_md5_for_ya_kassa, \ + YANDEX_REQUEST_PARAM CANONICAL_HTML_TAG = '' @@ -541,8 +543,23 @@ def test_tags_pagination_has_canonical_links(self): ) ) + # @todo #887:60m Repair category siblings mech. + @unittest.expectedFailure + def test_crumb_siblings_presented(self): + """Category should contain it's crumb siblings.""" + roots = models.Category.objects.active().filter(parent=None) + self.assertGreater(roots.count(), 1) + soup = self.get_category_soup(roots.first()) + siblings = soup.select('.breadcrumbs-siblings-links a') + self.assertIn(roots.last().name, [s.text.strip() for s in siblings]) + def test_crumb_siblings_are_active(self): - parent = models.Category.objects.annotate(c=Count('children')).filter(c__gt=1).first() + """Category should have only active crumb siblings.""" + parent = ( + models.Category.objects + .annotate(c=Count('children')) + .filter(c__gt=1).first() + ) ( pages_models.Page.objects .filter(id=parent.children.first().page.id) @@ -558,6 +575,18 @@ def test_crumb_siblings_are_active(self): .exists() ) + def test_roots_crumb_siblings_are_active(self): + """Root category should have only active crumb siblings.""" + roots = models.Category.objects.active().filter(parent=None) + self.assertGreater(roots.count(), 1) + disabled, enabled = roots.first(), roots.last() + disabled.page.is_active = False + disabled.save() + + soup = self.get_category_soup(enabled) + siblings = soup.select('.breadcrumbs-siblings-links a') + self.assertNotIn(disabled.name, [s.text.strip() for s in siblings]) + @tag('fast', 'catalog') class CategoriesMatrix(ViewsTestCase):