Skip to content

Commit

Permalink
#952 Test category root crumb siblings (#957)
Browse files Browse the repository at this point in the history
* #952  Test root crumbs

* #887  Prove category siblings failure with test
  • Loading branch information
duker33 authored Sep 18, 2019
1 parent e9d48b7 commit 2877085
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import json
import re
import unittest
from functools import partial
from itertools import chain
from operator import attrgetter
Expand All @@ -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 = '<link rel="canonical" href="{base_url}{path}">'

Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down

1 comment on commit 2877085

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 2877085 Sep 18, 2019

Choose a reason for hiding this comment

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

Puzzle 887-c7e6a145 discovered in shopelectro/tests/tests_views.py and submitted as #961. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.