Skip to content

Commit

Permalink
#887 Exclude not active crumbs siblings (#892)
Browse files Browse the repository at this point in the history
* #887  Test if all category.get_siblings are active

* #887  Rm duplicated categories matrix test

* #887  Remove some code doubling for catalog pagination tests

* #887  Test if all crumb siblings are active

* #887  Subtask not solved bug investigation

* #887  Fix siblings test to identify bug

* #887  Fix siblings test to identify bug

* #887  Review#1 fixes. Rm redundant subtask, simplify test query and condition
  • Loading branch information
duker33 authored Jun 26, 2019
1 parent 8ed03ef commit 9360507
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion shopelectro/tests/tests_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from functools import partial
from itertools import chain

from django.conf import settings
from django.forms.models import model_to_dict
from django.test import TestCase, TransactionTestCase, tag
from itertools import chain

from shopelectro.models import Product, Tag, TagGroup

Expand Down
65 changes: 35 additions & 30 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from bs4 import BeautifulSoup
from django.conf import settings
from django.db.models import Q
from django.db.models import Count, Q
from django.http import HttpResponse
from django.test import override_settings, TestCase, tag
from django.urls import reverse
from django.utils.translation import ugettext as _

from catalog.helpers import reverse_catalog_url
from pages.models import CustomPage
from pages import models as pages_models
from pages.urls import reverse_custom_page
from shopelectro import models
from shopelectro import views
Expand Down Expand Up @@ -70,6 +70,13 @@ def get_category_page(self, *args, **kwargs):
"""See `self.get_category_url()` interface."""
return self.client.get(self.get_category_url(*args, **kwargs))

def get_category_soup(self, *args, **kwargs) -> BeautifulSoup:
category_page = self.get_category_page(*args, **kwargs)
return BeautifulSoup(
category_page.content.decode('utf-8'),
'html.parser'
)


@tag('fast', 'catalog')
class CatalogTags(BaseCatalogTestCase):
Expand Down Expand Up @@ -193,6 +200,13 @@ def test_category_tag_relation(self):
@tag('fast', 'catalog')
class CatalogPagination(BaseCatalogTestCase):

def get_pagination_links_soup(self, page_number: int):
return (
self.get_category_soup(query_string={'page': page_number})
.find(class_='js-catalog-pagination')
.find_all('a')
)

def test_pagination_numbering(self):
page_number = 1
response = self.get_category_page(query_string={'page': page_number})
Expand Down Expand Up @@ -226,39 +240,28 @@ def assert_pagination_link(self, link, page_number):
page_number,
)

def get_category_soup(self, page_number: int) -> BeautifulSoup:
category_page = self.get_category_page(query_string={'page': page_number})
return BeautifulSoup(
category_page.content.decode('utf-8'),
'html.parser'
)

def test_category_200(self):
category_page = self.get_category_page()
assert category_page.status_code == 200

def test_numbered_pagination_links(self):
"""Forward to numbered pagination pages."""
page_number = 3
_, *numbered, _ = self.get_category_soup(page_number).find(
class_='js-catalog-pagination').find_all('a')

_, *numbered, _ = self.get_pagination_links_soup(page_number)
for slice, link in zip([-2, -1, 1, 2], numbered):
self.assert_pagination_link(link, page_number + slice)

def test_arrow_pagination_links(self):
"""Each button forward to a previous and a next pagination pages."""
page_number = 3
prev, *_, next_ = self.get_category_soup(page_number).find(
class_='js-catalog-pagination').find_all('a')

prev, *_, next_ = self.get_pagination_links_soup(page_number)
self.assert_pagination_link(next_, page_number + 1)
self.assert_pagination_link(prev, page_number - 1)

def test_pagination_canonical(self):
"""Canonical links forward to a previous and a next pagination pages."""
page_number = 3
soup = self.get_category_soup(page_number)
soup = self.get_category_soup(query_string={'page': page_number})

self.assert_pagination_link(
soup.find('link', attrs={'rel': 'next'}),
Expand Down Expand Up @@ -527,20 +530,22 @@ def test_tags_pagination_has_canonical_links(self):
)
)

def test_category_matrix_page(self):
"""Matrix page should contain all second level categories."""
page = CustomPage.objects.get(slug='catalog')
response = self.client.get(page.url)
soup = BeautifulSoup(
response.content.decode('utf-8'),
'html.parser'
def test_crumb_siblings_are_active(self):
parent = models.Category.objects.annotate(c=Count('children')).filter(c__gt=1).first()
(
pages_models.Page.objects
.filter(id=parent.children.first().page.id)
.update(is_active=False)
)
category = parent.children.active().first()
soup = self.get_category_soup(category.children.active().first())
siblings = soup.select('.breadcrumbs-siblings-links a')
self.assertFalse(
models.Category.objects
.filter(name__in=[s.text.strip() for s in siblings])
.filter(page__is_active=False)
.exists()
)
self.assertEqual(200, response.status_code)

categories_db = models.Category.objects.active()
categories_app = soup.find_all(tag='a', class_='catalog-list-item')
for from_db, from_app in zip(categories_db, categories_app):
self.assertEqual(from_db.name, from_app.a.text)


@tag('fast', 'catalog')
Expand Down Expand Up @@ -598,7 +603,7 @@ class IndexPage(TestCase):

@property
def page(self):
return CustomPage.objects.get(slug='')
return pages_models.CustomPage.objects.get(slug='')

@override_settings(MAIN_PAGE_TILE=MAIN_PAGE_TILE)
def test_category_tile_links(self):
Expand Down

1 comment on commit 9360507

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 9360507 Jun 26, 2019

Choose a reason for hiding this comment

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

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20190626-4-1bgoxbp/fidals/shopelectro && git config --local core.autocrlf false && git reset origin/master --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --autostash...

Please, copy and paste this stack trace to GitHub:

Exec::Error
set -x && set -e && set -o pipefail && cd /tmp/0pdd20190626-4-1bgoxbp/fidals/shopelectro && git config --local core.autocrlf false && git reset origin/master --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --autostash --strategy-option=theirs origin/master [1]:
bash: warning: setlocale: LC_ALL: cannot change locale (UTF-8)
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20190626-4-1bgoxbp/fidals/shopelectro
+ git config --local core.autocrlf false
+ git reset origin/master --hard --quiet
+ git clean --force -d
+ git fetch --quiet
+ git checkout master
Previous HEAD position was 8ed03ef... #890  Styles for the new contacts page (#895)
Switched to branch 'master'
+ git rebase --abort
+ git rebase --autostash --strategy-option=theirs origin/master
fatal: Could not parse object 'bc1d3db1da1faa557d353c2ff9ac4dbfe9296c5c^'
Unknown exit code (128) from command: git-merge-recursive bc1d3db1da1faa557d353c2ff9ac4dbfe9296c5c^ -- HEAD bc1d3db1da1faa557d353c2ff9ac4dbfe9296c5c

Your branch and 'origin/master' have diverged,
and have 1 and 542 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
First, rewinding head to replay your work on top of it...

/app/objects/exec.rb:60:in `block (2 levels) in run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/open3.rb:219:in `popen_run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/open3.rb:101:in `popen3'
/app/objects/exec.rb:54:in `block in run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:93:in `block in timeout'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `block in catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/timeout.rb:108:in `timeout'
/app/objects/exec.rb:53:in `run'
/app/objects/git_repo.rb:110:in `pull'
/app/objects/git_repo.rb:75:in `push'
/app/objects/job.rb:36:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:358:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1635:in `block in compile!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1011:in `route_eval'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1040:in `block in process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1038:in `process_route'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:990:in `block in route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `each'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:989:in `route!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1097:in `block in dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1094:in `dispatch!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `block in call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `block in invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `catch'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1076:in `invoke'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:924:in `call!'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.4/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1957:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `block in call'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1729:in `synchronize'
/app/vendor/bundle/ruby/2.6.0/gems/sinatra-2.0.4/lib/sinatra/base.rb:1502:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.6/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.6.0/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'

Please sign in to comment.