Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb#250 Create initial tests for refarm_redirects app #153

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions tests/refarm_redirects/test_views.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# @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.db.utils import IntegrityError
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 = '/catalog/categories/category-0/tags/6-v/'
# should raise exception, but not. Pdd task ahead will fix it.
with self.assertRaises(IntegrityError):
Redirect.objects.create(
site=Site.objects.first(),
old_path=url_from,
new_path=url_to
)