Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use the class decorator syntax available in Python >= 2.6. Refs #17965.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17829 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit eb163f37cb62268443d592f8ce08bd8a0ab9631d 1 parent 9383a27
Aymeric Augustin aaugustin authored
13 django/contrib/auth/tests/context_processors.py
View
@@ -8,6 +8,12 @@
from django.test.utils import override_settings
+@override_settings(
+ TEMPLATE_DIRS=(
+ os.path.join(os.path.dirname(__file__), 'templates'),
+ ),
+ USE_TZ=False, # required for loading the fixture
+)
class AuthContextProcessorTests(TestCase):
"""
Tests for the ``django.contrib.auth.context_processors.auth`` processor
@@ -95,10 +101,3 @@ def test_user_attrs(self):
# See bug #12060
self.assertEqual(response.context['user'], user)
self.assertEqual(user, response.context['user'])
-
-AuthContextProcessorTests = override_settings(
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(__file__), 'templates'),
- ),
- USE_TZ=False, # required for loading the fixture
-)(AuthContextProcessorTests)
19 django/contrib/auth/tests/forms.py
View
@@ -11,6 +11,7 @@
from django.utils.translation import ugettext as _
+@override_settings(USE_TZ=False)
class UserCreationFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -75,9 +76,8 @@ def test_success(self):
u = form.save()
self.assertEqual(repr(u), '<User: jsmith@example.com>')
-UserCreationFormTest = override_settings(USE_TZ=False)(UserCreationFormTest)
-
+@override_settings(USE_TZ=False)
class AuthenticationFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -128,9 +128,8 @@ def test_success(self):
self.assertTrue(form.is_valid())
self.assertEqual(form.non_field_errors(), [])
-AuthenticationFormTest = override_settings(USE_TZ=False)(AuthenticationFormTest)
-
+@override_settings(USE_TZ=False)
class SetPasswordFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -156,9 +155,8 @@ def test_success(self):
form = SetPasswordForm(user, data)
self.assertTrue(form.is_valid())
-SetPasswordFormTest = override_settings(USE_TZ=False)(SetPasswordFormTest)
-
+@override_settings(USE_TZ=False)
class PasswordChangeFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -205,9 +203,8 @@ def test_field_order(self):
self.assertEqual(PasswordChangeForm(user, {}).fields.keys(),
['old_password', 'new_password1', 'new_password2'])
-PasswordChangeFormTest = override_settings(USE_TZ=False)(PasswordChangeFormTest)
-
+@override_settings(USE_TZ=False)
class UserChangeFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -254,9 +251,7 @@ def test_bug_17944_unknown_password_algorithm(self):
form.as_table()
-UserChangeFormTest = override_settings(USE_TZ=False)(UserChangeFormTest)
-
-
+@override_settings(USE_TZ=False)
class PasswordResetFormTest(TestCase):
fixtures = ['authtestdata.json']
@@ -334,5 +329,3 @@ def test_unusable_password(self):
self.assertFalse(form.is_valid())
self.assertEqual(form["email"].errors,
[_(u"The user account associated with this e-mail address cannot reset the password.")])
-
-PasswordResetFormTest = override_settings(USE_TZ=False)(PasswordResetFormTest)
2  django/contrib/auth/tests/hashers.py
View
@@ -4,7 +4,6 @@
PBKDF2SHA1PasswordHasher, get_hasher, UNUSABLE_PASSWORD)
from django.utils import unittest
from django.utils.unittest import skipUnless
-from django.test.utils import override_settings
try:
@@ -19,6 +18,7 @@
class TestUtilsHashPass(unittest.TestCase):
+
def setUp(self):
load_hashers(password_hashers=default_hashers)
12 django/contrib/auth/tests/models.py
View
@@ -5,6 +5,7 @@
SiteProfileNotAvailable, UserManager)
+@override_settings(USE_TZ=False)
class ProfileTestCase(TestCase):
fixtures = ['authtestdata.json']
@@ -38,9 +39,8 @@ def test_site_profile_not_available(self):
settings.AUTH_PROFILE_MODULE = 'foo.bar'
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
-ProfileTestCase = override_settings(USE_TZ=False)(ProfileTestCase)
-
+@override_settings(USE_TZ=False)
class NaturalKeysTestCase(TestCase):
fixtures = ['authtestdata.json']
@@ -53,9 +53,8 @@ def test_group_natural_key(self):
users_group = Group.objects.create(name='users')
self.assertEquals(Group.objects.get_by_natural_key('users'), users_group)
-NaturalKeysTestCase = override_settings(USE_TZ=False)(NaturalKeysTestCase)
-
+@override_settings(USE_TZ=False)
class LoadDataWithoutNaturalKeysTestCase(TestCase):
fixtures = ['regular.json']
@@ -64,9 +63,8 @@ def test_user_is_created_and_added_to_group(self):
group = Group.objects.get(name='my_group')
self.assertEquals(group, user.groups.get())
-LoadDataWithoutNaturalKeysTestCase = override_settings(USE_TZ=False)(LoadDataWithoutNaturalKeysTestCase)
-
+@override_settings(USE_TZ=False)
class LoadDataWithNaturalKeysTestCase(TestCase):
fixtures = ['natural.json']
@@ -75,8 +73,6 @@ def test_user_is_created_and_added_to_group(self):
group = Group.objects.get(name='my_group')
self.assertEquals(group, user.groups.get())
-LoadDataWithNaturalKeysTestCase = override_settings(USE_TZ=False)(LoadDataWithNaturalKeysTestCase)
-
class UserManagerTestCase(TestCase):
3  django/contrib/auth/tests/signals.py
View
@@ -3,6 +3,7 @@
from django.contrib.auth import signals
+@override_settings(USE_TZ=False)
class SignalTestCase(TestCase):
urls = 'django.contrib.auth.tests.urls'
fixtures = ['authtestdata.json']
@@ -46,5 +47,3 @@ def test_logout(self):
self.client.get('/logout/next_page/')
self.assertEqual(len(self.logged_out), 1)
self.assertEqual(self.logged_out[0].username, 'testclient')
-
-SignalTestCase = override_settings(USE_TZ=False)(SignalTestCase)
3  django/contrib/auth/tests/views.py
View
@@ -18,6 +18,7 @@
SetPasswordForm, PasswordResetForm)
+@override_settings(USE_TZ=False)
class AuthViewsTestCase(TestCase):
"""
Helper base class for all the follow test cases.
@@ -52,8 +53,6 @@ def login(self, password='password'):
def assertContainsEscaped(self, response, text, **kwargs):
return self.assertContains(response, escape(force_unicode(text)), **kwargs)
-AuthViewsTestCase = override_settings(USE_TZ=False)(AuthViewsTestCase)
-
class AuthViewNamedURLTests(AuthViewsTestCase):
urls = 'django.contrib.auth.urls'
4 django/contrib/messages/tests/cookie.py
View
@@ -38,6 +38,7 @@ def stored_cookie_messages_count(storage, response):
return len(data)
+@override_settings(SESSION_COOKIE_DOMAIN='.lawrence.com')
class CookieTest(BaseTest):
storage_class = CookieStorage
@@ -130,6 +131,3 @@ def test_json_encoder_decoder(self):
value = encoder.encode(messages)
decoded_messages = json.loads(value, cls=MessageDecoder)
self.assertEqual(messages, decoded_messages)
-
-CookieTest = override_settings(
- SESSION_COOKIE_DOMAIN='.lawrence.com')(CookieTest)
8 django/contrib/sessions/tests.py
View
@@ -287,7 +287,9 @@ def test_sessionmanager_save(self):
self.assertEqual(self.session['y'], 2)
-DatabaseSessionWithTimeZoneTests = override_settings(USE_TZ=True)(DatabaseSessionTests)
+@override_settings(USE_TZ=True)
+class DatabaseSessionWithTimeZoneTests(DatabaseSessionTests):
+ pass
class CacheDBSessionTests(SessionTestsMixin, TestCase):
@@ -308,7 +310,9 @@ def test_load_overlong_key(self):
restore_warnings_state(warnings_state)
-CacheDBSessionWithTimeZoneTests = override_settings(USE_TZ=True)(CacheDBSessionTests)
+@override_settings(USE_TZ=True)
+class CacheDBSessionWithTimeZoneTests(CacheDBSessionTests):
+ pass
# Don't need DB flushing for these tests, so can use unittest.TestCase as base class
5 django/contrib/sitemaps/tests/https.py
View
@@ -26,7 +26,8 @@ def test_secure_sitemap_section(self):
</urlset>
""" % (self.base_url, date.today()))
-#@override_settings(SECURE_PROXY_SSL_HEADER=False)
+
+@override_settings(SECURE_PROXY_SSL_HEADER=False)
class HTTPSDetectionSitemapTests(SitemapTestsBase):
extra = {'wsgi.url_scheme': 'https'}
@@ -47,5 +48,3 @@ def test_sitemap_section_with_https_request(self):
<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
""" % (self.base_url.replace('http://', 'https://'), date.today()))
-
-HTTPSDetectionSitemapTests = override_settings(SECURE_PROXY_SSL_HEADER=False)(HTTPSDetectionSitemapTests)
16 docs/topics/testing.txt
View
@@ -1450,14 +1450,13 @@ The decorator can also be applied to test case classes::
from django.test import TestCase
from django.test.utils import override_settings
+ @override_settings(LOGIN_URL='/other/login/')
class LoginTestCase(TestCase):
def test_login(self):
response = self.client.get('/sekrit/')
self.assertRedirects(response, '/other/login/?next=/sekrit/')
- LoginTestCase = override_settings(LOGIN_URL='/other/login/')(LoginTestCase)
-
.. note::
When given a class, the decorator modifies the class directly and
@@ -1467,19 +1466,6 @@ The decorator can also be applied to test case classes::
the original ``LoginTestCase`` is still equally affected by the
decorator.
-On Python 2.6 and higher you can also use the well known decorator syntax to
-decorate the class::
-
- from django.test import TestCase
- from django.test.utils import override_settings
-
- @override_settings(LOGIN_URL='/other/login/')
- class LoginTestCase(TestCase):
-
- def test_login(self):
- response = self.client.get('/sekrit/')
- self.assertRedirects(response, '/other/login/?next=/sekrit/')
-
.. note::
When overriding settings, make sure to handle the cases in which your app's
4 tests/modeltests/proxy_model_inheritance/tests.py
View
@@ -18,7 +18,7 @@
from django.test.utils import override_settings
-# @override_settings(INSTALLED_APPS=('app1', 'app2'))
+@override_settings(INSTALLED_APPS=('app1', 'app2'))
class ProxyModelInheritanceTests(TransactionTestCase):
def setUp(self):
@@ -41,5 +41,3 @@ def test_table_exists(self):
from .app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0)
self.assertEqual(ProxyModel.objects.all().count(), 0)
-
-ProxyModelInheritanceTests = override_settings(INSTALLED_APPS=('app1', 'app2'))(ProxyModelInheritanceTests)
26 tests/modeltests/timezones/tests.py
View
@@ -74,7 +74,7 @@ def tearDownClass(self):
time.tzset()
-#@override_settings(USE_TZ=False)
+@override_settings(USE_TZ=False)
class LegacyDatabaseTests(BaseDateTimeTests):
def test_naive_datetime(self):
@@ -268,14 +268,11 @@ def test_raw_sql(self):
[event],
transform=lambda d: d)
-LegacyDatabaseTests = override_settings(USE_TZ=False)(LegacyDatabaseTests)
-
-#@override_settings(USE_TZ=True)
+@override_settings(USE_TZ=True)
class NewDatabaseTests(BaseDateTimeTests):
@requires_tz_support
- @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
def test_naive_datetime(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
with warnings.catch_warnings(record=True) as recorded:
@@ -289,7 +286,6 @@ def test_naive_datetime(self):
self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
@requires_tz_support
- @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
def test_datetime_from_date(self):
dt = datetime.date(2011, 9, 1)
with warnings.catch_warnings(record=True) as recorded:
@@ -302,7 +298,6 @@ def test_datetime_from_date(self):
self.assertEqual(event.dt, datetime.datetime(2011, 9, 1, tzinfo=EAT))
@requires_tz_support
- @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
@skipUnlessDBFeature('supports_microsecond_precision')
def test_naive_datetime_with_microsecond(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)
@@ -317,7 +312,6 @@ def test_naive_datetime_with_microsecond(self):
self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
@requires_tz_support
- @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
@skipIfDBFeature('supports_microsecond_precision')
def test_naive_datetime_with_microsecond_unsupported(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)
@@ -400,7 +394,6 @@ def test_query_filter_with_pytz_timezones(self):
self.assertEqual(Event.objects.filter(dt__range=(prev, next)).count(), 1)
@requires_tz_support
- @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
def test_query_filter_with_naive_datetime(self):
dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)
Event.objects.create(dt=dt)
@@ -492,8 +485,6 @@ def test_null_datetime(self):
e = MaybeEvent.objects.create()
self.assertEqual(e.dt, None)
-NewDatabaseTests = override_settings(USE_TZ=True)(NewDatabaseTests)
-
class SerializationTests(BaseDateTimeTests):
@@ -648,7 +639,7 @@ def test_aware_datetime_in_other_timezone(self):
obj = serializers.deserialize('yaml', data).next().object
self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
class TemplateTests(BaseDateTimeTests):
@requires_tz_support
@@ -887,9 +878,8 @@ def test_now_template_tag_uses_current_time_zone(self):
with timezone.override(ICT):
self.assertEqual(tpl.render(Context({})), "+0700")
-TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests)
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
class LegacyFormsTests(BaseDateTimeTests):
def test_form(self):
@@ -923,9 +913,8 @@ def test_model_form(self):
e = Event.objects.get()
self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 13, 20, 30))
-LegacyFormsTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)(LegacyFormsTests)
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
class NewFormsTests(BaseDateTimeTests):
@requires_tz_support
@@ -970,9 +959,8 @@ def test_model_form(self):
e = Event.objects.get()
self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
-NewFormsTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(NewFormsTests)
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
class AdminTests(BaseDateTimeTests):
urls = 'modeltests.timezones.urls'
@@ -1023,8 +1011,6 @@ def test_change_readonly_in_other_timezone(self):
response = self.client.get(reverse('admin:timezones_timestamp_change', args=(t.pk,)))
self.assertContains(response, t.created.astimezone(ICT).isoformat())
-AdminTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(AdminTests)
-
class UtilitiesTests(BaseDateTimeTests):
3  tests/regressiontests/admin_views/tests.py
View
@@ -3315,7 +3315,7 @@ def test_css_classes(self):
except ImportError:
docutils = None
-#@unittest.skipUnless(docutils, "no docutils installed.")
+@unittest.skipUnless(docutils, "no docutils installed.")
class AdminDocsTest(TestCase):
urls = "regressiontests.admin_views.urls"
fixtures = ['admin-views-users.xml']
@@ -3357,7 +3357,6 @@ def test_filters(self):
self.assertContains(response, '<h3 id="built_in-add">add</h3>', html=True)
self.assertContains(response, '<li><a href="#built_in-add">add</a></li>', html=True)
-AdminDocsTest = unittest.skipUnless(docutils, "no docutils installed.")(AdminDocsTest)
class ValidXHTMLTests(TestCase):
urls = "regressiontests.admin_views.urls"
118 tests/regressiontests/cache/tests.py
View
@@ -824,7 +824,9 @@ def test_second_call_doesnt_crash(self):
self.assertTrue("Cache table 'test cache table' could not be created" in err.getvalue())
-DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests)
+@override_settings(USE_TZ=True)
+class DBCacheWithTimeZoneTests(DBCacheTests):
+ pass
class DBCacheRouter(object):
@@ -927,6 +929,9 @@ def test_incr_decr_timeout(self):
# To check the memcached backend, the test settings file will
# need to contain a cache backend setting that points at
# your memcache server.
+@unittest.skipUnless(
+ settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'),
+ "memcached not available")
class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
backend_name = 'django.core.cache.backends.memcached.MemcachedCache'
@@ -956,8 +961,6 @@ def test_invalid_keys(self):
# memcached limits key length to 250
self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value')
-MemcachedCacheTests = unittest.skipUnless(settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'), "memcached not available")(MemcachedCacheTests)
-
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
"""
@@ -1048,6 +1051,16 @@ def test_close(self):
self.assertTrue(cache.closed)
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
+ CACHE_MIDDLEWARE_SECONDS=1,
+ CACHES={
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ },
+ },
+ USE_I18N=False,
+)
class CacheUtils(TestCase):
"""TestCase for django.utils.cache functions."""
@@ -1144,27 +1157,28 @@ def test_patch_cache_control(self):
parts = set(cc_delim_re.split(response['Cache-Control']))
self.assertEqual(parts, expected_cc)
-CacheUtils = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHE_MIDDLEWARE_SECONDS=1,
+
+@override_settings(
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'KEY_PREFIX': 'cacheprefix',
},
},
- USE_I18N=False,
-)(CacheUtils)
+)
+class PrefixedCacheUtils(CacheUtils):
+ pass
+
-PrefixedCacheUtils = override_settings(
+@override_settings(
+ CACHE_MIDDLEWARE_SECONDS=60,
+ CACHE_MIDDLEWARE_KEY_PREFIX='test',
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- 'KEY_PREFIX': 'cacheprefix',
},
},
-)(CacheUtils)
-
-
+)
class CacheHEADTest(TestCase):
def setUp(self):
@@ -1216,17 +1230,19 @@ def test_head_with_cached_get(self):
self.assertNotEqual(get_cache_data, None)
self.assertEqual(test_content, get_cache_data.content)
-CacheHEADTest = override_settings(
- CACHE_MIDDLEWARE_SECONDS=60,
- CACHE_MIDDLEWARE_KEY_PREFIX='test',
+
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
},
-)(CacheHEADTest)
-
-
+ LANGUAGES=(
+ ('en', 'English'),
+ ('es', 'Spanish'),
+ ),
+)
class CacheI18nTest(TestCase):
def setUp(self):
@@ -1391,33 +1407,39 @@ def set_cache(request, lang, msg):
# reset the language
translation.deactivate()
-CacheI18nTest = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHES={
- 'default': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- },
- },
- LANGUAGES=(
- ('en', 'English'),
- ('es', 'Spanish'),
- ),
-)(CacheI18nTest)
-PrefixedCacheI18nTest = override_settings(
+@override_settings(
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'KEY_PREFIX': 'cacheprefix'
},
},
-)(CacheI18nTest)
+)
+class PrefixedCacheI18nTest(CacheI18nTest):
+ pass
def hello_world_view(request, value):
return HttpResponse('Hello World %s' % value)
+@override_settings(
+ CACHE_MIDDLEWARE_ALIAS='other',
+ CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
+ CACHE_MIDDLEWARE_SECONDS=30,
+ CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
+ CACHES={
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ },
+ 'other': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'LOCATION': 'other',
+ 'TIMEOUT': '1',
+ },
+ },
+)
class CacheMiddlewareTest(TestCase):
def setUp(self):
@@ -1635,24 +1657,17 @@ def test_view_decorator(self):
response = other_with_timeout_view(request, '18')
self.assertEqual(response.content, 'Hello World 18')
-CacheMiddlewareTest = override_settings(
- CACHE_MIDDLEWARE_ALIAS='other',
- CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
- CACHE_MIDDLEWARE_SECONDS=30,
- CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
+
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
+ CACHE_MIDDLEWARE_SECONDS=1,
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
- 'other': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- 'LOCATION': 'other',
- 'TIMEOUT': '1',
- },
},
-)(CacheMiddlewareTest)
-
-
+ USE_I18N=False,
+)
class TestWithTemplateResponse(TestCase):
"""
Tests various headers w/ TemplateResponse.
@@ -1740,17 +1755,6 @@ def test_with_etag(self):
response = response.render()
self.assertTrue(response.has_header('ETag'))
-TestWithTemplateResponse = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHE_MIDDLEWARE_SECONDS=1,
- CACHES={
- 'default': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- },
- },
- USE_I18N=False,
-)(TestWithTemplateResponse)
-
class TestEtagWithAdmin(TestCase):
# See https://code.djangoproject.com/ticket/16003
19 tests/regressiontests/forms/tests/media.py
View
@@ -5,6 +5,10 @@
from django.test.utils import override_settings
+@override_settings(
+ STATIC_URL=None,
+ MEDIA_URL='http://media.example.com/media/',
+)
class FormsMediaTestCase(TestCase):
"""Tests for the media handling on widgets and forms"""
@@ -451,12 +455,11 @@ class Media:
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")
-FormsMediaTestCase = override_settings(
- STATIC_URL=None,
- MEDIA_URL='http://media.example.com/media/',
-)(FormsMediaTestCase)
-
+@override_settings(
+ STATIC_URL='http://media.example.com/static/',
+ MEDIA_URL='http://media.example.com/media/',
+)
class StaticFormsMediaTestCase(TestCase):
"""Tests for the media handling on widgets and forms"""
@@ -902,9 +905,3 @@ class Media:
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")
-
-
-StaticFormsMediaTestCase = override_settings(
- STATIC_URL='http://media.example.com/static/',
- MEDIA_URL='http://media.example.com/media/',
-)(StaticFormsMediaTestCase)
23 tests/regressiontests/i18n/contenttypes/tests.py
View
@@ -8,6 +8,17 @@
from django.utils import translation
+@override_settings(
+ USE_I18N=True,
+ LOCALE_PATHS=(
+ os.path.join(os.path.dirname(__file__), 'locale'),
+ ),
+ LANGUAGE_CODE='en',
+ LANGUAGES=(
+ ('en', 'English'),
+ ('fr', 'French'),
+ ),
+)
class ContentTypeTests(TestCase):
def test_verbose_name(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
@@ -20,15 +31,3 @@ def test_field_override(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
company_type.name = 'Other'
self.assertEqual(unicode(company_type), 'Other')
-
-ContentTypeTests = override_settings(
- USE_I18N=True,
- LOCALE_PATHS=(
- os.path.join(os.path.dirname(__file__), 'locale'),
- ),
- LANGUAGE_CODE='en',
- LANGUAGES=(
- ('en', 'English'),
- ('fr', 'French'),
- ),
-)(ContentTypeTests)
31 tests/regressiontests/i18n/patterns/tests.py
View
@@ -9,21 +9,7 @@
from django.utils import translation
-class URLTestCaseBase(TestCase):
- """
- TestCase base-class for the URL tests.
- """
- urls = 'regressiontests.i18n.patterns.urls.default'
-
- def setUp(self):
- # Make sure the cache is empty before we are doing our tests.
- clear_url_caches()
-
- def tearDown(self):
- # Make sure we will leave an empty cache for other testcases.
- clear_url_caches()
-
-URLTestCaseBase = override_settings(
+@override_settings(
USE_I18N=True,
LOCALE_PATHS=(
os.path.join(os.path.dirname(__file__), 'locale'),
@@ -41,7 +27,20 @@ def tearDown(self):
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
),
-)(URLTestCaseBase)
+)
+class URLTestCaseBase(TestCase):
+ """
+ TestCase base-class for the URL tests.
+ """
+ urls = 'regressiontests.i18n.patterns.urls.default'
+
+ def setUp(self):
+ # Make sure the cache is empty before we are doing our tests.
+ clear_url_caches()
+
+ def tearDown(self):
+ # Make sure we will leave an empty cache for other testcases.
+ clear_url_caches()
class URLPrefixTests(URLTestCaseBase):
4 tests/regressiontests/middleware/tests.py
View
@@ -584,6 +584,7 @@ def test_no_compress_uncompressible_response(self):
self.assertEqual(r.get('Content-Encoding'), None)
+@override_settings(USE_ETAGS=True)
class ETagGZipMiddlewareTest(TestCase):
"""
Tests if the ETag middleware behaves correctly with GZip middleware.
@@ -610,6 +611,3 @@ def test_compress_response(self):
nogzip_etag = response.get('ETag')
self.assertNotEqual(gzip_etag, nogzip_etag)
-ETagGZipMiddlewareTest = override_settings(
- USE_ETAGS=True,
-)(ETagGZipMiddlewareTest)
9 tests/regressiontests/settings_tests/tests.py
View
@@ -6,7 +6,7 @@
from django.test.utils import override_settings
-# @override_settings(TEST='override')
+@override_settings(TEST='override')
class FullyDecoratedTranTestCase(TransactionTestCase):
def test_override(self):
@@ -22,9 +22,8 @@ def test_decorated_testcase_name(self):
def test_decorated_testcase_module(self):
self.assertEquals(FullyDecoratedTranTestCase.__module__, __name__)
-FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
-# @override_settings(TEST='override')
+@override_settings(TEST='override')
class FullyDecoratedTestCase(TestCase):
def test_override(self):
@@ -34,8 +33,6 @@ def test_override(self):
def test_method_override(self):
self.assertEqual(settings.TEST, 'override2')
-FullyDecoratedTestCase = override_settings(TEST='override')(FullyDecoratedTestCase)
-
class ClassDecoratedTestCaseSuper(TestCase):
"""
@@ -47,6 +44,7 @@ def test_max_recursion_error(self):
pass
+@override_settings(TEST='override')
class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
def test_override(self):
self.assertEqual(settings.TEST, 'override')
@@ -66,7 +64,6 @@ def test_max_recursion_error(self):
except RuntimeError, e:
self.fail()
-ClassDecoratedTestCase = override_settings(TEST='override')(ClassDecoratedTestCase)
class SettingGetter(object):
def __init__(self):
20 tests/regressiontests/staticfiles_tests/tests.py
View
@@ -98,9 +98,9 @@ def assertStaticRaises(self, exc, path, result, **kwargs):
self.assertRaises(exc, self.assertStaticRenders, path, result, **kwargs)
+@override_settings(**TEST_SETTINGS)
class StaticFilesTestCase(BaseStaticFilesTestCase, TestCase):
pass
-StaticFilesTestCase = override_settings(**TEST_SETTINGS)(StaticFilesTestCase)
class BaseCollectionTestCase(BaseStaticFilesTestCase):
@@ -343,17 +343,21 @@ def test_ordering_override(self):
self.assertFileContains('file2.txt', 'duplicate of file2.txt')
+@override_settings(
+ STATICFILES_STORAGE='regressiontests.staticfiles_tests.storage.DummyStorage',
+)
class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
"""
Tests for #15035
"""
pass
-TestCollectionNonLocalStorage = override_settings(
- STATICFILES_STORAGE='regressiontests.staticfiles_tests.storage.DummyStorage',
-)(TestCollectionNonLocalStorage)
-
+# we set DEBUG to False here since the template tag wouldn't work otherwise
+@override_settings(**dict(TEST_SETTINGS,
+ STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
+ DEBUG=False,
+))
class TestCollectionCachedStorage(BaseCollectionTestCase,
BaseStaticFilesTestCase, TestCase):
"""
@@ -515,12 +519,6 @@ def test_cache_key_memcache_validation(self):
self.assertEqual(cache_key, 'staticfiles:e95bbc36387084582df2a70750d7b351')
-# we set DEBUG to False here since the template tag wouldn't work otherwise
-TestCollectionCachedStorage = override_settings(**dict(TEST_SETTINGS,
- STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
- DEBUG=False,
-))(TestCollectionCachedStorage)
-
if sys.platform != 'win32':
class TestCollectionLinks(CollectionTestCase, TestDefaults):
Please sign in to comment.
Something went wrong with that request. Please try again.