diff --git a/requirements.txt b/requirements.txt index 8bf6bb46..24697c90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ ua-parser==0.8.0 user-agents==1.1.0 sorl-thumbnail==12.4a1 https://github.com/selwin/django-user_agents/archive/master.zip -https://github.com/fidals/refarm-site/archive/0.2.0.zip +https://github.com/fidals/refarm-site/archive/0.2.1.zip diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py index 06d821f7..84a44b42 100644 --- a/shopelectro/tests/tests_views.py +++ b/shopelectro/tests/tests_views.py @@ -211,6 +211,18 @@ def test_product_tag_linking(self): for link in property_links: self.assertContains(response, link) + def test_non_existing_tags_404(self): + """Product should contain links on CategoryTagPage for it's every tag.""" + product = Product.objects.first() + self.assertGreater(product.tags.count(), 0) + + bad_tag_url = reverse('category', kwargs={ + 'slug': product.category.page.slug, + 'tags': 'non-existent-tag', + }) + response = self.client.get(bad_tag_url) + self.assertEqual(response.status_code, 404) + class CatalogPagination(BaseCatalogTestCase): diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py index ed136800..b5efcae3 100644 --- a/shopelectro/views/catalog.py +++ b/shopelectro/views/catalog.py @@ -242,6 +242,9 @@ def get_context_data(self, **kwargs): slugs = models.Tag.parse_url_tags(tags) tags = models.Tag.objects.filter(slug__in=slugs) + if not tags: + raise http.Http404('No such tag.') + all_products = ( all_products .filter(tags__in=tags)