Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Set of minor fixes (#383)
Browse files Browse the repository at this point in the history
* stb#336  Move get_item to pages_extras to share it

* #fix  Minor fix default config

* #371  Move autocomplete test from selenium to views

* stb#314  Move doubled test code to refarm_test_utils

* #fix  Fix sorting strategy

* stb#314  Refactor test utils file location

* #fix  Grade refarm version to 0.4.22

* #314  Rm doubled code

* #fix  Review fix of test realization
  • Loading branch information
duker33 committed Dec 19, 2018
1 parent 8a1a670 commit e5af29e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ services:
ports:
- $VIRTUAL_HOST_STAGE_PORT:8000
volumes:
- ../stroyprombeton/settings/local.py:$SRC_DIR/stroyprombeton/settings/local.py
- ../stroyprombeton/settings/stage.py:$SRC_DIR/stroyprombeton/settings/stage.py
# contains refarm-site modules
- $DEPS_DIR
- /opt/media/stb_stage/:$SRC_DIR/media/
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Unidecode==1.0.22
ua-parser==0.8.0
user-agents==1.1.0
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.4.22.zip
https://github.com/fidals/refarm-site/archive/0.4.23.zip
2 changes: 1 addition & 1 deletion stroyprombeton/fixtures/dump.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stroyprombeton/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'test_stb',
'NAME': os.environ['POSTGRES_DB'],
'USER': os.environ['POSTGRES_USER'],
'PASSWORD': os.environ['POSTGRES_PASSWORD'],
'HOST': os.environ['POSTGRES_URL'],
Expand Down
6 changes: 0 additions & 6 deletions stroyprombeton/templatetags/stb_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,3 @@ def get_category_gent_name(category: Category, default=None) -> str:
return settings.CATEGORY_GENT_NAMES.get(
category.id, category.name if not default else default
)


# @todo #328:15m Move get_item filter to pages_extras. se2
@register.filter
def get_item(dictionary: dict, key: str):
return dictionary.get(key)
7 changes: 4 additions & 3 deletions stroyprombeton/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from seleniumrequests import Remote

from catalog.helpers import get_category_path
from catalog.helpers import reverse_catalog_url
from stroyprombeton import models as stb_models

disable_celery = override_settings(USE_CELERY=False)
Expand Down Expand Up @@ -88,6 +88,7 @@ def get_category_path(
query_string: dict=None,
):
category = category or self.category
return get_category_path(
category, route_name, tags, sorting, query_string
route_kwargs = {'category_id': category.id}
return reverse_catalog_url(
route_name, route_kwargs, tags, sorting, query_string
)
12 changes: 0 additions & 12 deletions stroyprombeton/tests/tests_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,18 +594,6 @@ def test_search_have_results(self):
self.assertTrue(self.browser.find_element_by_link_text('Category root #0'))
self.assertTrue(self.browser.find_element_by_link_text('Category #0 of #1'))

# @todo #347:15m Run test_inactive_product_not_in_search_autocomplete without selenium.
# The test only checks correctness of the backend's logic, but not of frontend.
def test_inactive_product_not_in_search_autocomplete(self):
test_product = stb_models.Product.objects.first()
test_product.page.is_active = False
test_product.page.save()
self.fill_input(query=test_product.name)

suggestions = self.autocomplete.find_elements_by_class_name('autocomplete-suggestion')
for suggestion in suggestions:
self.assertTrue(test_product.name not in suggestion.get_attribute('data-val'))

def test_search_results_empty(self):
"""Search results for wrong term should contain empty result set."""
self.search(query=self.wrong_query)
Expand Down
42 changes: 17 additions & 25 deletions stroyprombeton/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from datetime import datetime
from itertools import chain
from operator import attrgetter
from urllib.parse import urlencode

from django.conf import settings
from django.http import HttpResponse, QueryDict
from django.test import 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, FlatPage, ModelPage

from stroyprombeton import models
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_catalog_links(self):


@tag('fast')
class CategoryTile(TestCase, TestPageMixin, CategoryTestMixin):
class CategoryTile(TestCase, TestPageMixin):
"""
Test for CategoryPage view.
Expand Down Expand Up @@ -112,7 +112,7 @@ def setUp(self):

models.Category.objects.create(**self.child_data)

self.response = self.client.get('/gbi/categories/{}/'.format(self.root_category.id))
self.response = self.client.get(f'/gbi/categories/{self.root_category.id}/')

def test_children_categories_quantity(self):
self.assertEqual(
Expand Down Expand Up @@ -571,6 +571,20 @@ def test_admin_autocomplete_no_results(self):
self.assertFalse(json_to_dict(response))
self.assertNotContains(response, term)

def test_autocomplete_has_only_active(self):
"""Autocomplete items should contain only active products."""
test_product = models.Product.objects.first()
test_product.page.is_active = False
test_product.page.save()

url = f'{reverse("autocomplete")}?term={test_product.name}'
response = self.client.get(url)
results = json_to_dict(response)

self.assertTrue(all(
test_product.name not in result['name'] for result in results
))


@tag('fast')
class ProductPrice(TestCase):
Expand All @@ -586,28 +600,6 @@ def test_price_list(self):
self.assertTrue(len(self.response.context['products']) > 100)


# @todo #187:30m Rm code doubled method in tests
# SE contains this method too.
# Move it to refarm side.
def reverse_catalog_url(
url: str,
route_kwargs: dict,
tags: models.TagQuerySet=None,
sorting: int=None,
query_string: dict=None,
) -> str:
query_string = f'?{urlencode(query_string)}' if query_string else ''
if tags:
# PyCharm's option:
# noinspection PyTypeChecker
tags_slug = tags.as_url()
route_kwargs['tags'] = tags_slug
if sorting is not None:
route_kwargs['sorting'] = sorting

return f'{reverse(url, kwargs=route_kwargs)}{query_string}'


@tag('fast')
class CatalogTags(TestCase, CategoryTestMixin):

Expand Down
1 change: 1 addition & 0 deletions templates/catalog/category_products.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load pages_extras %}
{% load stb_extras %}

{% for product in products %}
Expand Down

3 comments on commit e5af29e

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on e5af29e Dec 19, 2018

Choose a reason for hiding this comment

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

Puzzle 187-5cc04a8d disappeared from stroyprombeton/tests/tests_views.py, that's why I closed #314. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on e5af29e Dec 19, 2018

Choose a reason for hiding this comment

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

Puzzle 328-3afa2059 disappeared from stroyprombeton/templatetags/stb_extras.py, that's why I closed #336. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on e5af29e Dec 19, 2018

Choose a reason for hiding this comment

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

Puzzle 347-0c474edb disappeared from stroyprombeton/tests/tests_selenium.py, that's why I closed #371. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.