Skip to content

Commit

Permalink
#360 Create test with unexpected behaviour explaining
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Jun 22, 2018
1 parent 829350b commit f0e5567
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
They all should be using Django's TestClient.
"""
import json
import unittest
from functools import partial
from itertools import chain
from operator import attrgetter
Expand Down Expand Up @@ -516,3 +517,36 @@ def test_admin_autocomplete_has_no_model_pages(self):
f'?term={self.QUOTED_SIGNLE_RESULT_TERM}&pageType=category'
)
self.assertTrue(len(json_to_dict(response)) == 1)


class Redirects(TestCase):

fixtures = ['dump.json']

@unittest.expectedFailure('rf#140 task will resurrect it')
def test_redirect_on_existing_page(self):
"""DB based redirect from existing url should do, but should not avoid it."""
# take some existing `url_from`
url_from = '/catalog/categories/category-0/tags/6-v/'
response = self.client.get(url_from)
self.assertEqual(response.status_code, 200)

# create redirect from `url_from` to another existing one - `url_to`
from django.contrib.redirects.models import Redirect
from django.contrib.sites.models import Site

# Site.objects.create(domain='shopelectro.ru', name='shopelectro')

url_to = '/catalog/categories/category-0/'
Redirect.objects.create(
site=Site.objects.first(),
old_path=url_from,
new_path=url_to
)

# `url_from` should redirect to `url_to`
response = self.client.get(url_from)
self.assertEqual(response.status_code, 301)
response = self.client.get(url_from, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.url, url_from)

0 comments on commit f0e5567

Please sign in to comment.