Skip to content

Commit

Permalink
stb#250 Create initial tests for refarm_redirects app
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Jul 22, 2018
1 parent 3c50b7e commit f7507b1
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions tests/refarm_redirects/test_views.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# @todo #140:30m Move test case to custom redirects app
# You can find example at SE's tests_views.Redirects app
import unittest

from django.contrib.redirects.models import Redirect
from django.contrib.sites.models import Site
from django.test import TestCase


class Redirects(TestCase):

def test_redirect_from_existing_page(self):
"""`refarm-site.redirects` app should redirect from existing url too."""
# take some existing `url_from`
# @todo #360:30m Remove hardcoded fixture data.
# Replace `url_from` and `url_to` with urls, generated from db.
# It'll be much more short and clear.
url_from = '/catalog/categories/category-0/tags/6-v/'
# create redirect from `url_from` to another existing one - `url_to`
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)

# @todo #360:60m Add db constraint for looped redirect.
# Example of looped redirect:
# `/news/one-two/ --> /news/one-two/`
# `60m` because schema and data migrations are needed.
# And fix test.
@unittest.expectedFailure
def test_looped_redirect(self):
"""
Redirect like `/news/one-two/ --> /news/one-two/` should fail.
It should meet db constraint while adding.
"""
# hardcoded fixtures will be fixed with task in test ahead.
url_from, url_to = 2 * ['/catalog/categories/category-0/tags/6-v/']
# should raise exception, but not. Pdd task ahead will fix it.
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, 200)

0 comments on commit f7507b1

Please sign in to comment.