Middleware regression test fixes:

* Added a models.py file so the tests run.
 * Reset `settings.DEBUG` to `False` at the end of the `test_append_slash_no_redirect_on_POST_in_DEBUG` test so it doesn't bleed over to other tests.
 * Removed unused import.
 * Minor docstring fixes.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6991 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-01-03 02:14:29 +00:00
parent 5496c50b62
commit d6d1188ed0
2 changed files with 13 additions and 14 deletions

View File

@ -0,0 +1 @@
# models.py file for tests to run.

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest
from django.test import TestCase from django.test import TestCase
from django.http import HttpRequest from django.http import HttpRequest
from django.middleware.common import CommonMiddleware from django.middleware.common import CommonMiddleware
@ -19,7 +17,7 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_have_slash(self): def test_append_slash_have_slash(self):
""" """
tests that urls with slashes go unmolested Tests that URLs with slashes go unmolested.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
request = self._get_request('slash/') request = self._get_request('slash/')
@ -27,7 +25,7 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_slashless_resource(self): def test_append_slash_slashless_resource(self):
""" """
tests that matches to explicit slashless urls go unmolested Tests that matches to explicit slashless URLs go unmolested.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
request = self._get_request('noslash') request = self._get_request('noslash')
@ -35,7 +33,7 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_slashless_unknown(self): def test_append_slash_slashless_unknown(self):
""" """
tests that APPEND_SLASH doesn't redirect to unknown resources Tests that APPEND_SLASH doesn't redirect to unknown resources.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
request = self._get_request('unknown') request = self._get_request('unknown')
@ -43,7 +41,7 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_redirect(self): def test_append_slash_redirect(self):
""" """
tests that APPEND_SLASH redirects slashless urls to a valid pattern Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
request = self._get_request('slash') request = self._get_request('slash')
@ -53,9 +51,9 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_no_redirect_on_POST_in_DEBUG(self): def test_append_slash_no_redirect_on_POST_in_DEBUG(self):
""" """
tests that while in debug mode, an exception is raised with a warning Tests that while in debug mode, an exception is raised with a warning
when a failed attempt is made to POST to an url which would normally be when a failed attempt is made to POST to an URL which would normally be
redirected to a slashed version redirected to a slashed version.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
settings.DEBUG = True settings.DEBUG = True
@ -69,10 +67,11 @@ class CommonMiddlewareTest(TestCase):
CommonMiddleware().process_request(request) CommonMiddleware().process_request(request)
except RuntimeError, e: except RuntimeError, e:
self.assertTrue('end in a slash' in str(e)) self.assertTrue('end in a slash' in str(e))
settings.DEBUG = False
def test_append_slash_disabled(self): def test_append_slash_disabled(self):
""" """
tests disabling append slash functionality Tests disabling append slash functionality.
""" """
settings.APPEND_SLASH = False settings.APPEND_SLASH = False
request = self._get_request('slash') request = self._get_request('slash')
@ -80,8 +79,8 @@ class CommonMiddlewareTest(TestCase):
def test_append_slash_quoted(self): def test_append_slash_quoted(self):
""" """
tests that urls which require quoting are redirected to their slash Tests that URLs which require quoting are redirected to their slash
version ok version ok.
""" """
settings.APPEND_SLASH = True settings.APPEND_SLASH = True
request = self._get_request('needsquoting#') request = self._get_request('needsquoting#')
@ -90,4 +89,3 @@ class CommonMiddlewareTest(TestCase):
self.assertEquals( self.assertEquals(
r['Location'], r['Location'],
'http://testserver/middleware/needsquoting%23/') 'http://testserver/middleware/needsquoting%23/')