Kaydet (Commit) 0c1355e9 authored tarafından Anton Samarchyan's avatar Anton Samarchyan Kaydeden (comit) Tim Graham

Completed test coverage for RedirectFallbackMiddleware.

üst 2b53c837
......@@ -8,7 +8,7 @@ from django.test import TestCase, modify_settings, override_settings
@modify_settings(MIDDLEWARE={'append': 'django.contrib.redirects.middleware.RedirectFallbackMiddleware'})
@override_settings(APPEND_SLASH=False, SITE_ID=1)
@override_settings(APPEND_SLASH=False, ROOT_URLCONF='redirects_tests.urls', SITE_ID=1)
class RedirectTests(TestCase):
def setUp(self):
......@@ -35,6 +35,20 @@ class RedirectTests(TestCase):
response = self.client.get('/initial?foo')
self.assertRedirects(response, '/new_target/', status_code=301, target_status_code=404)
@override_settings(APPEND_SLASH=True)
def test_redirect_not_found_with_append_slash(self):
"""
Exercise the second Redirect.DoesNotExist branch in
RedirectFallbackMiddleware.
"""
response = self.client.get('/test')
self.assertEqual(response.status_code, 404)
def test_redirect_shortcircuits_non_404_response(self):
"""RedirectFallbackMiddleware short-circuits on non-404 requests."""
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_response_gone(self):
"""When the redirect target is '', return a 410"""
Redirect.objects.create(site=self.site, old_path='/initial', new_path='')
......
from django.conf.urls import url
from django.http import HttpResponse
urlpatterns = [
url(r'^$', lambda req: HttpResponse('OK')),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment