Permalink
Browse files

Used the override_settings decorator in the tests of auth, flatpages,…

… and formtools.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17851 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 6d9227b commit 98e9d1c6aba3670712887b0b20317dcb0e25f249 @aaugustin aaugustin committed Mar 31, 2012
@@ -3,6 +3,7 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
+from django.test.utils import override_settings
class BackendTest(TestCase):
@@ -230,20 +231,14 @@ def test_get_all_permissions(self):
self.assertEqual(self.user1.get_all_permissions(TestObj()), set(['anon']))
-
-
+@override_settings(AUTHENTICATION_BACKENDS=[])
class NoBackendsTest(TestCase):
"""
Tests that an appropriate error is raised if no auth backends are provided.
"""
def setUp(self):
- self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS
- settings.AUTHENTICATION_BACKENDS = []
self.user = User.objects.create_user('test', 'test@example.com', 'test')
- def tearDown(self):
- settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS
-
def test_raises_exception(self):
self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', TestObj(),))
@@ -18,29 +18,23 @@
SetPasswordForm, PasswordResetForm)
-@override_settings(USE_TZ=False)
+@override_settings(
+ LANGUAGES=(
+ ('en', 'English'),
+ ),
+ LANGUAGE_CODE='en',
+ TEMPLATE_DIRS = (
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+ USE_TZ=False,
+)
class AuthViewsTestCase(TestCase):
"""
Helper base class for all the follow test cases.
"""
fixtures = ['authtestdata.json']
urls = 'django.contrib.auth.tests.urls'
- def setUp(self):
- self.old_LANGUAGES = settings.LANGUAGES
- self.old_LANGUAGE_CODE = settings.LANGUAGE_CODE
- settings.LANGUAGES = (('en', 'English'),)
- settings.LANGUAGE_CODE = 'en'
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(os.path.dirname(__file__), 'templates'),
- )
-
- def tearDown(self):
- settings.LANGUAGES = self.old_LANGUAGES
- settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
-
def login(self, password='password'):
response = self.client.post('/login/', {
'username': 'testclient',
@@ -2,34 +2,29 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase, Client
+from django.test.utils import override_settings
+
+@override_settings(
+ LOGIN_URL='/accounts/login/',
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageCSRFTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
def setUp(self):
self.client = Client(enforce_csrf_checks=True)
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- csrf_middleware_class = 'django.middleware.csrf.CsrfViewMiddleware'
- if csrf_middleware_class not in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES += (csrf_middleware_class,)
- if flatpage_middleware_class not in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES += (flatpage_middleware_class,)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
- self.old_LOGIN_URL = settings.LOGIN_URL
- settings.LOGIN_URL = '/accounts/login/'
-
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
- settings.LOGIN_URL = self.old_LOGIN_URL
def test_view_flatpage(self):
"A flatpage can be served through a view, even when the middleware is in use"
@@ -3,31 +3,27 @@
from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase
-
+from django.test.utils import override_settings
+
+
+@override_settings(
+ LOGIN_URL='/accounts/login/',
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageMiddlewareTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
- def setUp(self):
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- if flatpage_middleware_class not in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES += (flatpage_middleware_class,)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
- self.old_LOGIN_URL = settings.LOGIN_URL
- settings.LOGIN_URL = '/accounts/login/'
-
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
- settings.LOGIN_URL = self.old_LOGIN_URL
-
def test_view_flatpage(self):
"A flatpage can be served through a view, even when the middleware is in use"
response = self.client.get('/flatpage_root/flatpage/')
@@ -86,33 +82,25 @@ def test_fallback_flatpage_special_chars(self):
self.assertContains(response, "<p>Isn't it special!</p>")
+@override_settings(
+ APPEND_SLASH = True,
+ LOGIN_URL='/accounts/login/',
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageMiddlewareAppendSlashTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
- def setUp(self):
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- if flatpage_middleware_class not in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES += (flatpage_middleware_class,)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
- self.old_LOGIN_URL = settings.LOGIN_URL
- settings.LOGIN_URL = '/accounts/login/'
- self.old_APPEND_SLASH = settings.APPEND_SLASH
- settings.APPEND_SLASH = True
-
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
- settings.LOGIN_URL = self.old_LOGIN_URL
- settings.APPEND_SLASH = self.old_APPEND_SLASH
-
def test_redirect_view_flatpage(self):
"A flatpage can be served through a view and should add a slash"
response = self.client.get('/flatpage_root/flatpage')
@@ -3,29 +3,29 @@
from django.contrib.auth.models import AnonymousUser, User
from django.template import Template, Context, TemplateSyntaxError
from django.test import TestCase
+from django.test.utils import override_settings
+
+@override_settings(
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageTemplateTagTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
def setUp(self):
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- if flatpage_middleware_class not in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES += (flatpage_middleware_class,)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
self.me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
-
def test_get_flatpages_tag(self):
"The flatpage template tag retrives unregistered prefixed flatpages by default"
out = Template(
@@ -3,31 +3,27 @@
from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase
-
+from django.test.utils import override_settings
+
+
+@override_settings(
+ LOGIN_URL='/accounts/login/',
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageViewTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
- def setUp(self):
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- if flatpage_middleware_class in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES = tuple(m for m in settings.MIDDLEWARE_CLASSES if m != flatpage_middleware_class)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
- self.old_LOGIN_URL = settings.LOGIN_URL
- settings.LOGIN_URL = '/accounts/login/'
-
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
- settings.LOGIN_URL = self.old_LOGIN_URL
-
def test_view_flatpage(self):
"A flatpage can be served through a view"
response = self.client.get('/flatpage_root/flatpage/')
@@ -75,33 +71,25 @@ def test_view_flatpage_special_chars(self):
self.assertContains(response, "<p>Isn't it special!</p>")
+@override_settings(
+ APPEND_SLASH = True,
+ LOGIN_URL='/accounts/login/',
+ MIDDLEWARE_CLASSES=(
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
+ ),
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+)
class FlatpageViewAppendSlashTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
- def setUp(self):
- self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
- flatpage_middleware_class = 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware'
- if flatpage_middleware_class in settings.MIDDLEWARE_CLASSES:
- settings.MIDDLEWARE_CLASSES = tuple(m for m in settings.MIDDLEWARE_CLASSES if m != flatpage_middleware_class)
- self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
- settings.TEMPLATE_DIRS = (
- os.path.join(
- os.path.dirname(__file__),
- 'templates'
- ),
- )
- self.old_LOGIN_URL = settings.LOGIN_URL
- settings.LOGIN_URL = '/accounts/login/'
- self.old_APPEND_SLASH = settings.APPEND_SLASH
- settings.APPEND_SLASH = True
-
- def tearDown(self):
- settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
- settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
- settings.LOGIN_URL = self.old_LOGIN_URL
- settings.APPEND_SLASH = self.old_APPEND_SLASH
-
def test_redirect_view_flatpage(self):
"A flatpage can be served through a view and should add a slash"
response = self.client.get('/flatpage_root/flatpage')
@@ -0,0 +1 @@
+Not found.
Oops, something went wrong.

0 comments on commit 98e9d1c

Please sign in to comment.