Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored March 30, 2012
13  django/contrib/auth/tests/context_processors.py
@@ -8,6 +8,12 @@
8 8
 from django.test.utils import override_settings
9 9
 
10 10
 
  11
+@override_settings(
  12
+    TEMPLATE_DIRS=(
  13
+            os.path.join(os.path.dirname(__file__), 'templates'),
  14
+        ),
  15
+    USE_TZ=False,                           # required for loading the fixture
  16
+)
11 17
 class AuthContextProcessorTests(TestCase):
12 18
     """
13 19
     Tests for the ``django.contrib.auth.context_processors.auth`` processor
@@ -95,10 +101,3 @@ def test_user_attrs(self):
95 101
         # See bug #12060
96 102
         self.assertEqual(response.context['user'], user)
97 103
         self.assertEqual(user, response.context['user'])
98  
-
99  
-AuthContextProcessorTests = override_settings(
100  
-    TEMPLATE_DIRS=(
101  
-            os.path.join(os.path.dirname(__file__), 'templates'),
102  
-        ),
103  
-    USE_TZ=False,                           # required for loading the fixture
104  
-)(AuthContextProcessorTests)
19  django/contrib/auth/tests/forms.py
@@ -11,6 +11,7 @@
11 11
 from django.utils.translation import ugettext as _
12 12
 
13 13
 
  14
+@override_settings(USE_TZ=False)
14 15
 class UserCreationFormTest(TestCase):
15 16
 
16 17
     fixtures = ['authtestdata.json']
@@ -75,9 +76,8 @@ def test_success(self):
75 76
         u = form.save()
76 77
         self.assertEqual(repr(u), '<User: jsmith@example.com>')
77 78
 
78  
-UserCreationFormTest = override_settings(USE_TZ=False)(UserCreationFormTest)
79  
-
80 79
 
  80
+@override_settings(USE_TZ=False)
81 81
 class AuthenticationFormTest(TestCase):
82 82
 
83 83
     fixtures = ['authtestdata.json']
@@ -128,9 +128,8 @@ def test_success(self):
128 128
         self.assertTrue(form.is_valid())
129 129
         self.assertEqual(form.non_field_errors(), [])
130 130
 
131  
-AuthenticationFormTest = override_settings(USE_TZ=False)(AuthenticationFormTest)
132  
-
133 131
 
  132
+@override_settings(USE_TZ=False)
134 133
 class SetPasswordFormTest(TestCase):
135 134
 
136 135
     fixtures = ['authtestdata.json']
@@ -156,9 +155,8 @@ def test_success(self):
156 155
         form = SetPasswordForm(user, data)
157 156
         self.assertTrue(form.is_valid())
158 157
 
159  
-SetPasswordFormTest = override_settings(USE_TZ=False)(SetPasswordFormTest)
160  
-
161 158
 
  159
+@override_settings(USE_TZ=False)
162 160
 class PasswordChangeFormTest(TestCase):
163 161
 
164 162
     fixtures = ['authtestdata.json']
@@ -205,9 +203,8 @@ def test_field_order(self):
205 203
         self.assertEqual(PasswordChangeForm(user, {}).fields.keys(),
206 204
                          ['old_password', 'new_password1', 'new_password2'])
207 205
 
208  
-PasswordChangeFormTest = override_settings(USE_TZ=False)(PasswordChangeFormTest)
209  
-
210 206
 
  207
+@override_settings(USE_TZ=False)
211 208
 class UserChangeFormTest(TestCase):
212 209
 
213 210
     fixtures = ['authtestdata.json']
@@ -254,9 +251,7 @@ def test_bug_17944_unknown_password_algorithm(self):
254 251
         form.as_table()
255 252
 
256 253
 
257  
-UserChangeFormTest = override_settings(USE_TZ=False)(UserChangeFormTest)
258  
-
259  
-
  254
+@override_settings(USE_TZ=False)
260 255
 class PasswordResetFormTest(TestCase):
261 256
 
262 257
     fixtures = ['authtestdata.json']
@@ -334,5 +329,3 @@ def test_unusable_password(self):
334 329
         self.assertFalse(form.is_valid())
335 330
         self.assertEqual(form["email"].errors,
336 331
                          [_(u"The user account associated with this e-mail address cannot reset the password.")])
337  
-
338  
-PasswordResetFormTest = override_settings(USE_TZ=False)(PasswordResetFormTest)
2  django/contrib/auth/tests/hashers.py
@@ -4,7 +4,6 @@
4 4
     PBKDF2SHA1PasswordHasher, get_hasher, UNUSABLE_PASSWORD)
5 5
 from django.utils import unittest
6 6
 from django.utils.unittest import skipUnless
7  
-from django.test.utils import override_settings
8 7
 
9 8
 
10 9
 try:
@@ -19,6 +18,7 @@
19 18
 
20 19
 
21 20
 class TestUtilsHashPass(unittest.TestCase):
  21
+
22 22
     def setUp(self):
23 23
         load_hashers(password_hashers=default_hashers)
24 24
 
12  django/contrib/auth/tests/models.py
@@ -5,6 +5,7 @@
5 5
     SiteProfileNotAvailable, UserManager)
6 6
 
7 7
 
  8
+@override_settings(USE_TZ=False)
8 9
 class ProfileTestCase(TestCase):
9 10
     fixtures = ['authtestdata.json']
10 11
 
@@ -38,9 +39,8 @@ def test_site_profile_not_available(self):
38 39
         settings.AUTH_PROFILE_MODULE = 'foo.bar'
39 40
         self.assertRaises(SiteProfileNotAvailable, user.get_profile)
40 41
 
41  
-ProfileTestCase = override_settings(USE_TZ=False)(ProfileTestCase)
42  
-
43 42
 
  43
+@override_settings(USE_TZ=False)
44 44
 class NaturalKeysTestCase(TestCase):
45 45
     fixtures = ['authtestdata.json']
46 46
 
@@ -53,9 +53,8 @@ def test_group_natural_key(self):
53 53
         users_group = Group.objects.create(name='users')
54 54
         self.assertEquals(Group.objects.get_by_natural_key('users'), users_group)
55 55
 
56  
-NaturalKeysTestCase = override_settings(USE_TZ=False)(NaturalKeysTestCase)
57  
-
58 56
 
  57
+@override_settings(USE_TZ=False)
59 58
 class LoadDataWithoutNaturalKeysTestCase(TestCase):
60 59
     fixtures = ['regular.json']
61 60
 
@@ -64,9 +63,8 @@ def test_user_is_created_and_added_to_group(self):
64 63
         group = Group.objects.get(name='my_group')
65 64
         self.assertEquals(group, user.groups.get())
66 65
 
67  
-LoadDataWithoutNaturalKeysTestCase = override_settings(USE_TZ=False)(LoadDataWithoutNaturalKeysTestCase)
68  
-
69 66
 
  67
+@override_settings(USE_TZ=False)
70 68
 class LoadDataWithNaturalKeysTestCase(TestCase):
71 69
     fixtures = ['natural.json']
72 70
 
@@ -75,8 +73,6 @@ def test_user_is_created_and_added_to_group(self):
75 73
         group = Group.objects.get(name='my_group')
76 74
         self.assertEquals(group, user.groups.get())
77 75
 
78  
-LoadDataWithNaturalKeysTestCase = override_settings(USE_TZ=False)(LoadDataWithNaturalKeysTestCase)
79  
-
80 76
 
81 77
 class UserManagerTestCase(TestCase):
82 78
 
3  django/contrib/auth/tests/signals.py
@@ -3,6 +3,7 @@
3 3
 from django.contrib.auth import signals
4 4
 
5 5
 
  6
+@override_settings(USE_TZ=False)
6 7
 class SignalTestCase(TestCase):
7 8
     urls = 'django.contrib.auth.tests.urls'
8 9
     fixtures = ['authtestdata.json']
@@ -46,5 +47,3 @@ def test_logout(self):
46 47
         self.client.get('/logout/next_page/')
47 48
         self.assertEqual(len(self.logged_out), 1)
48 49
         self.assertEqual(self.logged_out[0].username, 'testclient')
49  
-
50  
-SignalTestCase = override_settings(USE_TZ=False)(SignalTestCase)
3  django/contrib/auth/tests/views.py
@@ -18,6 +18,7 @@
18 18
                 SetPasswordForm, PasswordResetForm)
19 19
 
20 20
 
  21
+@override_settings(USE_TZ=False)
21 22
 class AuthViewsTestCase(TestCase):
22 23
     """
23 24
     Helper base class for all the follow test cases.
@@ -52,8 +53,6 @@ def login(self, password='password'):
52 53
     def assertContainsEscaped(self, response, text, **kwargs):
53 54
         return self.assertContains(response, escape(force_unicode(text)), **kwargs)
54 55
 
55  
-AuthViewsTestCase = override_settings(USE_TZ=False)(AuthViewsTestCase)
56  
-
57 56
 
58 57
 class AuthViewNamedURLTests(AuthViewsTestCase):
59 58
     urls = 'django.contrib.auth.urls'
4  django/contrib/messages/tests/cookie.py
@@ -38,6 +38,7 @@ def stored_cookie_messages_count(storage, response):
@@ -130,6 +131,3 @@ def test_json_encoder_decoder(self):
8  django/contrib/sessions/tests.py
@@ -287,7 +287,9 @@ def test_sessionmanager_save(self):
287 287
         self.assertEqual(self.session['y'], 2)
288 288
 
289 289
 
290  
-DatabaseSessionWithTimeZoneTests = override_settings(USE_TZ=True)(DatabaseSessionTests)
  290
+@override_settings(USE_TZ=True)
  291
+class DatabaseSessionWithTimeZoneTests(DatabaseSessionTests):
  292
+    pass
291 293
 
292 294
 
293 295
 class CacheDBSessionTests(SessionTestsMixin, TestCase):
@@ -308,7 +310,9 @@ def test_load_overlong_key(self):
308 310
         restore_warnings_state(warnings_state)
309 311
 
310 312
 
311  
-CacheDBSessionWithTimeZoneTests = override_settings(USE_TZ=True)(CacheDBSessionTests)
  313
+@override_settings(USE_TZ=True)
  314
+class CacheDBSessionWithTimeZoneTests(CacheDBSessionTests):
  315
+    pass
312 316
 
313 317
 
314 318
 # Don't need DB flushing for these tests, so can use unittest.TestCase as base class
5  django/contrib/sitemaps/tests/https.py
@@ -26,7 +26,8 @@ def test_secure_sitemap_section(self):
26 26
 </urlset>
27 27
 """ % (self.base_url, date.today()))
28 28
 
29  
-#@override_settings(SECURE_PROXY_SSL_HEADER=False)
  29
+
  30
+@override_settings(SECURE_PROXY_SSL_HEADER=False)
30 31
 class HTTPSDetectionSitemapTests(SitemapTestsBase):
31 32
     extra = {'wsgi.url_scheme': 'https'}
32 33
 
@@ -47,5 +48,3 @@ def test_sitemap_section_with_https_request(self):
47 48
 <url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
48 49
 </urlset>
49 50
 """ % (self.base_url.replace('http://', 'https://'), date.today()))
50  
-
51  
-HTTPSDetectionSitemapTests = override_settings(SECURE_PROXY_SSL_HEADER=False)(HTTPSDetectionSitemapTests)
16  docs/topics/testing.txt
@@ -1450,14 +1450,13 @@ The decorator can also be applied to test case classes::
1450 1450
     from django.test import TestCase
1451 1451
     from django.test.utils import override_settings
1452 1452
 
  1453
+    @override_settings(LOGIN_URL='/other/login/')
1453 1454
     class LoginTestCase(TestCase):
1454 1455
 
1455 1456
         def test_login(self):
1456 1457
             response = self.client.get('/sekrit/')
1457 1458
             self.assertRedirects(response, '/other/login/?next=/sekrit/')
1458 1459
 
1459  
-    LoginTestCase = override_settings(LOGIN_URL='/other/login/')(LoginTestCase)
1460  
-
1461 1460
 .. note::
1462 1461
 
1463 1462
     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::
1467 1466
     the original ``LoginTestCase`` is still equally affected by the
1468 1467
     decorator.
1469 1468
 
1470  
-On Python 2.6 and higher you can also use the well known decorator syntax to
1471  
-decorate the class::
1472  
-
1473  
-    from django.test import TestCase
1474  
-    from django.test.utils import override_settings
1475  
-
1476  
-    @override_settings(LOGIN_URL='/other/login/')
1477  
-    class LoginTestCase(TestCase):
1478  
-
1479  
-        def test_login(self):
1480  
-            response = self.client.get('/sekrit/')
1481  
-            self.assertRedirects(response, '/other/login/?next=/sekrit/')
1482  
-
1483 1469
 .. note::
1484 1470
 
1485 1471
     When overriding settings, make sure to handle the cases in which your app's
4  tests/modeltests/proxy_model_inheritance/tests.py
@@ -18,7 +18,7 @@
18 18
 from django.test.utils import override_settings
19 19
 
20 20
 
21  
-# @override_settings(INSTALLED_APPS=('app1', 'app2'))
  21
+@override_settings(INSTALLED_APPS=('app1', 'app2'))
22 22
 class ProxyModelInheritanceTests(TransactionTestCase):
23 23
 
24 24
     def setUp(self):
@@ -41,5 +41,3 @@ def test_table_exists(self):
41 41
         from .app2.models import NiceModel
42 42
         self.assertEqual(NiceModel.objects.all().count(), 0)
43 43
         self.assertEqual(ProxyModel.objects.all().count(), 0)
44  
-
45  
-ProxyModelInheritanceTests = override_settings(INSTALLED_APPS=('app1', 'app2'))(ProxyModelInheritanceTests)
26  tests/modeltests/timezones/tests.py
@@ -74,7 +74,7 @@ def tearDownClass(self):
74 74
             time.tzset()
75 75
 
76 76
 
77  
-#@override_settings(USE_TZ=False)
  77
+@override_settings(USE_TZ=False)
78 78
 class LegacyDatabaseTests(BaseDateTimeTests):
79 79
 
80 80
     def test_naive_datetime(self):
@@ -268,14 +268,11 @@ def test_raw_sql(self):
268 268
                 [event],
269 269
                 transform=lambda d: d)
270 270
 
271  
-LegacyDatabaseTests = override_settings(USE_TZ=False)(LegacyDatabaseTests)
272 271
 
273  
-
274  
-#@override_settings(USE_TZ=True)
  272
+@override_settings(USE_TZ=True)
275 273
 class NewDatabaseTests(BaseDateTimeTests):
276 274
 
277 275
     @requires_tz_support
278  
-    @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
279 276
     def test_naive_datetime(self):
280 277
         dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
281 278
         with warnings.catch_warnings(record=True) as recorded:
@@ -289,7 +286,6 @@ def test_naive_datetime(self):
289 286
         self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
290 287
 
291 288
     @requires_tz_support
292  
-    @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
293 289
     def test_datetime_from_date(self):
294 290
         dt = datetime.date(2011, 9, 1)
295 291
         with warnings.catch_warnings(record=True) as recorded:
@@ -302,7 +298,6 @@ def test_datetime_from_date(self):
302 298
         self.assertEqual(event.dt, datetime.datetime(2011, 9, 1, tzinfo=EAT))
303 299
 
304 300
     @requires_tz_support
305  
-    @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
306 301
     @skipUnlessDBFeature('supports_microsecond_precision')
307 302
     def test_naive_datetime_with_microsecond(self):
308 303
         dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)
@@ -317,7 +312,6 @@ def test_naive_datetime_with_microsecond(self):
317 312
         self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
318 313
 
319 314
     @requires_tz_support
320  
-    @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
321 315
     @skipIfDBFeature('supports_microsecond_precision')
322 316
     def test_naive_datetime_with_microsecond_unsupported(self):
323 317
         dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)
@@ -400,7 +394,6 @@ def test_query_filter_with_pytz_timezones(self):
400 394
         self.assertEqual(Event.objects.filter(dt__range=(prev, next)).count(), 1)
401 395
 
402 396
     @requires_tz_support
403  
-    @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
404 397
     def test_query_filter_with_naive_datetime(self):
405 398
         dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)
406 399
         Event.objects.create(dt=dt)
@@ -492,8 +485,6 @@ def test_null_datetime(self):
492 485
         e = MaybeEvent.objects.create()
493 486
         self.assertEqual(e.dt, None)
494 487
 
495  
-NewDatabaseTests = override_settings(USE_TZ=True)(NewDatabaseTests)
496  
-
497 488
 
498 489
 class SerializationTests(BaseDateTimeTests):
499 490
 
@@ -648,7 +639,7 @@ def test_aware_datetime_in_other_timezone(self):
648 639
             obj = serializers.deserialize('yaml', data).next().object
649 640
             self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)
650 641
 
651  
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
  642
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
652 643
 class TemplateTests(BaseDateTimeTests):
653 644
 
654 645
     @requires_tz_support
@@ -887,9 +878,8 @@ def test_now_template_tag_uses_current_time_zone(self):
887 878
         with timezone.override(ICT):
888 879
             self.assertEqual(tpl.render(Context({})), "+0700")
889 880
 
890  
-TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests)
891 881
 
892  
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
  882
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
893 883
 class LegacyFormsTests(BaseDateTimeTests):
894 884
 
895 885
     def test_form(self):
@@ -923,9 +913,8 @@ def test_model_form(self):
923 913
         e = Event.objects.get()
924 914
         self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 13, 20, 30))
925 915
 
926  
-LegacyFormsTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)(LegacyFormsTests)
927 916
 
928  
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
  917
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
929 918
 class NewFormsTests(BaseDateTimeTests):
930 919
 
931 920
     @requires_tz_support
@@ -970,9 +959,8 @@ def test_model_form(self):
970 959
         e = Event.objects.get()
971 960
         self.assertEqual(e.dt, datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
972 961
 
973  
-NewFormsTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(NewFormsTests)
974 962
 
975  
-#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
  963
+@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
976 964
 class AdminTests(BaseDateTimeTests):
977 965
 
978 966
     urls = 'modeltests.timezones.urls'
@@ -1023,8 +1011,6 @@ def test_change_readonly_in_other_timezone(self):
1023 1011
             response = self.client.get(reverse('admin:timezones_timestamp_change', args=(t.pk,)))
1024 1012
         self.assertContains(response, t.created.astimezone(ICT).isoformat())
1025 1013
 
1026  
-AdminTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(AdminTests)
1027  
-
1028 1014
 
1029 1015
 class UtilitiesTests(BaseDateTimeTests):
1030 1016
 
3  tests/regressiontests/admin_views/tests.py
@@ -3315,7 +3315,7 @@ def test_css_classes(self):
3315 3315
 except ImportError:
3316 3316
     docutils = None
3317 3317
 
3318  
-#@unittest.skipUnless(docutils, "no docutils installed.")
  3318
+@unittest.skipUnless(docutils, "no docutils installed.")
3319 3319
 class AdminDocsTest(TestCase):
3320 3320
     urls = "regressiontests.admin_views.urls"
3321 3321
     fixtures = ['admin-views-users.xml']
@@ -3357,7 +3357,6 @@ def test_filters(self):
3357 3357
         self.assertContains(response, '<h3 id="built_in-add">add</h3>', html=True)
3358 3358
         self.assertContains(response, '<li><a href="#built_in-add">add</a></li>', html=True)
3359 3359
 
3360  
-AdminDocsTest = unittest.skipUnless(docutils, "no docutils installed.")(AdminDocsTest)
3361 3360
 
3362 3361
 class ValidXHTMLTests(TestCase):
3363 3362
     urls = "regressiontests.admin_views.urls"
118  tests/regressiontests/cache/tests.py
@@ -824,7 +824,9 @@ def test_second_call_doesnt_crash(self):
824 824
         self.assertTrue("Cache table 'test cache table' could not be created" in err.getvalue())
825 825
 
826 826
 
827  
-DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests)
  827
+@override_settings(USE_TZ=True)
  828
+class DBCacheWithTimeZoneTests(DBCacheTests):
  829
+    pass
828 830
 
829 831
 
830 832
 class DBCacheRouter(object):
@@ -927,6 +929,9 @@ def test_incr_decr_timeout(self):
927 929
 # To check the memcached backend, the test settings file will
928 930
 # need to contain a cache backend setting that points at
929 931
 # your memcache server.
  932
+@unittest.skipUnless(
  933
+    settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'),
  934
+    "memcached not available")
930 935
 class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
931 936
     backend_name = 'django.core.cache.backends.memcached.MemcachedCache'
932 937
 
@@ -956,8 +961,6 @@ def test_invalid_keys(self):
956 961
         # memcached limits key length to 250
957 962
         self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value')
958 963
 
959  
-MemcachedCacheTests = unittest.skipUnless(settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'), "memcached not available")(MemcachedCacheTests)
960  
-
961 964
 
962 965
 class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
963 966
     """
@@ -1048,6 +1051,16 @@ def test_close(self):
1048 1051
         self.assertTrue(cache.closed)
1049 1052
 
1050 1053
 
  1054
+@override_settings(
  1055
+        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
  1056
+        CACHE_MIDDLEWARE_SECONDS=1,
  1057
+        CACHES={
  1058
+            'default': {
  1059
+                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  1060
+            },
  1061
+        },
  1062
+        USE_I18N=False,
  1063
+)
1051 1064
 class CacheUtils(TestCase):
1052 1065
     """TestCase for django.utils.cache functions."""
1053 1066
 
@@ -1144,27 +1157,28 @@ def test_patch_cache_control(self):
1144 1157
             parts = set(cc_delim_re.split(response['Cache-Control']))
1145 1158
             self.assertEqual(parts, expected_cc)
1146 1159
 
1147  
-CacheUtils = override_settings(
1148  
-        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
1149  
-        CACHE_MIDDLEWARE_SECONDS=1,
  1160
+
  1161
+@override_settings(
1150 1162
         CACHES={
1151 1163
             'default': {
1152 1164
                 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  1165
+                'KEY_PREFIX': 'cacheprefix',
1153 1166
             },
1154 1167
         },
1155  
-        USE_I18N=False,
1156  
-)(CacheUtils)
  1168
+)
  1169
+class PrefixedCacheUtils(CacheUtils):
  1170
+    pass
  1171
+
1157 1172
 
1158  
-PrefixedCacheUtils = override_settings(
  1173
+@override_settings(
  1174
+        CACHE_MIDDLEWARE_SECONDS=60,
  1175
+        CACHE_MIDDLEWARE_KEY_PREFIX='test',
1159 1176
         CACHES={
1160 1177
             'default': {
1161 1178
                 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1162  
-                'KEY_PREFIX': 'cacheprefix',
1163 1179
             },
1164 1180
         },
1165  
-)(CacheUtils)
1166  
-
1167  
-
  1181
+)
1168 1182
 class CacheHEADTest(TestCase):
1169 1183
 
1170 1184
     def setUp(self):
@@ -1216,17 +1230,19 @@ def test_head_with_cached_get(self):
1216 1230
         self.assertNotEqual(get_cache_data, None)
1217 1231
         self.assertEqual(test_content, get_cache_data.content)
1218 1232
 
1219  
-CacheHEADTest = override_settings(
1220  
-        CACHE_MIDDLEWARE_SECONDS=60,
1221  
-        CACHE_MIDDLEWARE_KEY_PREFIX='test',
  1233
+
  1234
+@override_settings(
  1235
+        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
1222 1236
         CACHES={
1223 1237
             'default': {
1224 1238
                 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1225 1239
             },
1226 1240
         },
1227  
-)(CacheHEADTest)
1228  
-
1229  
-
  1241
+        LANGUAGES=(
  1242
+            ('en', 'English'),
  1243
+            ('es', 'Spanish'),
  1244
+        ),
  1245
+)
1230 1246
 class CacheI18nTest(TestCase):
1231 1247
 
1232 1248
     def setUp(self):
@@ -1391,33 +1407,39 @@ def set_cache(request, lang, msg):
1391 1407
         # reset the language
1392 1408
         translation.deactivate()
1393 1409
 
1394  
-CacheI18nTest = override_settings(
1395  
-        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
1396  
-        CACHES={
1397  
-            'default': {
1398  
-                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1399  
-            },
1400  
-        },
1401  
-        LANGUAGES=(
1402  
-            ('en', 'English'),
1403  
-            ('es', 'Spanish'),
1404  
-        ),
1405  
-)(CacheI18nTest)
1406 1410
 
1407  
-PrefixedCacheI18nTest = override_settings(
  1411
+@override_settings(
1408 1412
         CACHES={
1409 1413
             'default': {
1410 1414
                 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1411 1415
                 'KEY_PREFIX': 'cacheprefix'
1412 1416
             },
1413 1417
         },
1414  
-)(CacheI18nTest)
  1418
+)
  1419
+class PrefixedCacheI18nTest(CacheI18nTest):
  1420
+    pass
1415 1421
 
1416 1422
 
1417 1423
 def hello_world_view(request, value):
1418 1424
     return HttpResponse('Hello World %s' % value)
1419 1425
 
1420 1426
 
  1427
+@override_settings(
  1428
+        CACHE_MIDDLEWARE_ALIAS='other',
  1429
+        CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
  1430
+        CACHE_MIDDLEWARE_SECONDS=30,
  1431
+        CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
  1432
+        CACHES={
  1433
+            'default': {
  1434
+                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  1435
+            },
  1436
+            'other': {
  1437
+                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  1438
+                'LOCATION': 'other',
  1439
+                'TIMEOUT': '1',
  1440
+            },
  1441
+        },
  1442
+)
1421 1443
 class CacheMiddlewareTest(TestCase):
1422 1444
 
1423 1445
     def setUp(self):
@@ -1635,24 +1657,17 @@ def test_view_decorator(self):
1635 1657
         response = other_with_timeout_view(request, '18')
1636 1658
         self.assertEqual(response.content, 'Hello World 18')
1637 1659
 
1638  
-CacheMiddlewareTest = override_settings(
1639  
-        CACHE_MIDDLEWARE_ALIAS='other',
1640  
-        CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
1641  
-        CACHE_MIDDLEWARE_SECONDS=30,
1642  
-        CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
  1660
+
  1661
+@override_settings(
  1662
+        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
  1663
+        CACHE_MIDDLEWARE_SECONDS=1,
1643 1664
         CACHES={
1644 1665
             'default': {
1645 1666
                 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1646 1667
             },
1647  
-            'other': {
1648  
-                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1649  
-                'LOCATION': 'other',
1650  
-                'TIMEOUT': '1',
1651  
-            },
1652 1668
         },
1653  
-)(CacheMiddlewareTest)
1654  
-
1655  
-
  1669
+        USE_I18N=False,
  1670
+)
1656 1671
 class TestWithTemplateResponse(TestCase):
1657 1672
     """
1658 1673
     Tests various headers w/ TemplateResponse.
@@ -1740,17 +1755,6 @@ def test_with_etag(self):
1740 1755
         response = response.render()
1741 1756
         self.assertTrue(response.has_header('ETag'))
1742 1757
 
1743  
-TestWithTemplateResponse = override_settings(
1744  
-        CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
1745  
-        CACHE_MIDDLEWARE_SECONDS=1,
1746  
-        CACHES={
1747  
-            'default': {
1748  
-                'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
1749  
-            },
1750  
-        },
1751  
-        USE_I18N=False,
1752  
-)(TestWithTemplateResponse)
1753  
-
1754 1758
 
1755 1759
 class TestEtagWithAdmin(TestCase):
1756 1760
     # See https://code.djangoproject.com/ticket/16003
19  tests/regressiontests/forms/tests/media.py
@@ -5,6 +5,10 @@
5 5
 from django.test.utils import override_settings
6 6
 
7 7
 
  8
+@override_settings(
  9
+    STATIC_URL=None,
  10
+    MEDIA_URL='http://media.example.com/media/',
  11
+)
8 12
 class FormsMediaTestCase(TestCase):
9 13
     """Tests for the media handling on widgets and forms"""
10 14
 
@@ -451,12 +455,11 @@ class Media:
451 455
 <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
452 456
 <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")
453 457
 
454  
-FormsMediaTestCase = override_settings(
455  
-    STATIC_URL=None,
456  
-    MEDIA_URL='http://media.example.com/media/',
457  
-)(FormsMediaTestCase)
458  
-
459 458
 
  459
+@override_settings(
  460
+    STATIC_URL='http://media.example.com/static/',
  461
+    MEDIA_URL='http://media.example.com/media/',
  462
+)
460 463
 class StaticFormsMediaTestCase(TestCase):
461 464
     """Tests for the media handling on widgets and forms"""
462 465
 
@@ -902,9 +905,3 @@ class Media:
902 905
 <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
903 906
 <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
904 907
 <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")
905  
-
906  
-
907  
-StaticFormsMediaTestCase = override_settings(
908  
-    STATIC_URL='http://media.example.com/static/',
909  
-    MEDIA_URL='http://media.example.com/media/',
910  
-)(StaticFormsMediaTestCase)
23  tests/regressiontests/i18n/contenttypes/tests.py
@@ -8,6 +8,17 @@
8 8
 from django.utils import translation
9 9
 
10 10
 
  11
+@override_settings(
  12
+    USE_I18N=True,
  13
+    LOCALE_PATHS=(
  14
+        os.path.join(os.path.dirname(__file__), 'locale'),
  15
+    ),
  16
+    LANGUAGE_CODE='en',
  17
+    LANGUAGES=(
  18
+        ('en', 'English'),
  19
+        ('fr', 'French'),
  20
+    ),
  21
+)
11 22
 class ContentTypeTests(TestCase):
12 23
     def test_verbose_name(self):
13 24
         company_type = ContentType.objects.get(app_label='i18n', model='company')
@@ -20,15 +31,3 @@ def test_field_override(self):
20 31
         company_type = ContentType.objects.get(app_label='i18n', model='company')
21 32
         company_type.name = 'Other'
22 33
         self.assertEqual(unicode(company_type), 'Other')
23  
-
24  
-ContentTypeTests = override_settings(
25  
-    USE_I18N=True,
26  
-    LOCALE_PATHS=(
27  
-        os.path.join(os.path.dirname(__file__), 'locale'),
28  
-    ),
29  
-    LANGUAGE_CODE='en',
30  
-    LANGUAGES=(
31  
-        ('en', 'English'),
32  
-        ('fr', 'French'),
33  
-    ),
34  
-)(ContentTypeTests)
31  tests/regressiontests/i18n/patterns/tests.py
@@ -9,21 +9,7 @@
9 9
 from django.utils import translation
10 10
 
11 11
 
12  
-class URLTestCaseBase(TestCase):
13  
-    """
14  
-    TestCase base-class for the URL tests.
15  
-    """
16  
-    urls = 'regressiontests.i18n.patterns.urls.default'
17  
-
18  
-    def setUp(self):
19  
-        # Make sure the cache is empty before we are doing our tests.
20  
-        clear_url_caches()
21  
-
22  
-    def tearDown(self):
23  
-        # Make sure we will leave an empty cache for other testcases.
24  
-        clear_url_caches()
25  
-
26  
-URLTestCaseBase = override_settings(
  12
+@override_settings(
27 13
     USE_I18N=True,
28 14
     LOCALE_PATHS=(
29 15
         os.path.join(os.path.dirname(__file__), 'locale'),
@@ -41,7 +27,20 @@ def tearDown(self):
41 27
         'django.middleware.locale.LocaleMiddleware',
42 28
         'django.middleware.common.CommonMiddleware',
43 29
     ),
44  
-)(URLTestCaseBase)
  30
+)
  31
+class URLTestCaseBase(TestCase):
  32
+    """
  33
+    TestCase base-class for the URL tests.
  34
+    """
  35
+    urls = 'regressiontests.i18n.patterns.urls.default'
  36
+
  37
+    def setUp(self):
  38
+        # Make sure the cache is empty before we are doing our tests.
  39
+        clear_url_caches()
  40
+
  41
+    def tearDown(self):
  42
+        # Make sure we will leave an empty cache for other testcases.
  43
+        clear_url_caches()
45 44
 
46 45
 
47 46
 class URLPrefixTests(URLTestCaseBase):
4  tests/regressiontests/middleware/tests.py
@@ -584,6 +584,7 @@ def test_no_compress_uncompressible_response(self):
584 584
         self.assertEqual(r.get('Content-Encoding'), None)
585 585
 
586 586
 
  587
+@override_settings(USE_ETAGS=True)
587 588
 class ETagGZipMiddlewareTest(TestCase):
588 589
     """
589 590
     Tests if the ETag middleware behaves correctly with GZip middleware.
@@ -610,6 +611,3 @@ def test_compress_response(self):
610 611
         nogzip_etag = response.get('ETag')
611 612
 
612 613
         self.assertNotEqual(gzip_etag, nogzip_etag)
613  
-ETagGZipMiddlewareTest = override_settings(
614  
-    USE_ETAGS=True,
615  
-)(ETagGZipMiddlewareTest)
9  tests/regressiontests/settings_tests/tests.py
@@ -6,7 +6,7 @@
6 6
 from django.test.utils import override_settings
7 7
 
8 8
 
9  
-# @override_settings(TEST='override')
  9
+@override_settings(TEST='override')
10 10
 class FullyDecoratedTranTestCase(TransactionTestCase):
11 11
 
12 12
     def test_override(self):
@@ -22,9 +22,8 @@ def test_decorated_testcase_name(self):
22 22
     def test_decorated_testcase_module(self):
23 23
         self.assertEquals(FullyDecoratedTranTestCase.__module__, __name__)
24 24
 
25  
-FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
26 25
 
27  
-# @override_settings(TEST='override')
  26
+@override_settings(TEST='override')
28 27
 class FullyDecoratedTestCase(TestCase):
29 28
 
30 29
     def test_override(self):
@@ -34,8 +33,6 @@ def test_override(self):
34 33
     def test_method_override(self):
35 34
         self.assertEqual(settings.TEST, 'override2')
36 35
 
37  
-FullyDecoratedTestCase = override_settings(TEST='override')(FullyDecoratedTestCase)
38  
-
39 36
 
40 37
 class ClassDecoratedTestCaseSuper(TestCase):
41 38
     """
@@ -47,6 +44,7 @@ def test_max_recursion_error(self):
47 44
         pass
48 45
 
49 46
 
  47
+@override_settings(TEST='override')
50 48
 class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
51 49
     def test_override(self):
52 50
         self.assertEqual(settings.TEST, 'override')
@@ -66,7 +64,6 @@ def test_max_recursion_error(self):
66 64
         except RuntimeError, e:
67 65
             self.fail()
68 66
 
69  
-ClassDecoratedTestCase = override_settings(TEST='override')(ClassDecoratedTestCase)
70 67
 
71 68
 class SettingGetter(object):
72 69
     def __init__(self):
20  tests/regressiontests/staticfiles_tests/tests.py
@@ -98,9 +98,9 @@ def assertStaticRaises(self, exc, path, result, **kwargs):
98 98
         self.assertRaises(exc, self.assertStaticRenders, path, result, **kwargs)
99 99
 
100 100
 
  101
+@override_settings(**TEST_SETTINGS)
101 102
 class StaticFilesTestCase(BaseStaticFilesTestCase, TestCase):
102 103
     pass
103  
-StaticFilesTestCase = override_settings(**TEST_SETTINGS)(StaticFilesTestCase)
104 104
 
105 105
 
106 106
 class BaseCollectionTestCase(BaseStaticFilesTestCase):
@@ -343,17 +343,21 @@ def test_ordering_override(self):
343 343
         self.assertFileContains('file2.txt', 'duplicate of file2.txt')
344 344
 
345 345
 
  346
+@override_settings(
  347
+    STATICFILES_STORAGE='regressiontests.staticfiles_tests.storage.DummyStorage',
  348
+)
346 349
 class TestCollectionNonLocalStorage(CollectionTestCase, TestNoFilesCreated):
347 350
     """
348 351
     Tests for #15035
349 352
     """
350 353
     pass
351 354
 
352  
-TestCollectionNonLocalStorage = override_settings(
353  
-    STATICFILES_STORAGE='regressiontests.staticfiles_tests.storage.DummyStorage',
354  
-)(TestCollectionNonLocalStorage)
355  
-
356 355
 
  356
+# we set DEBUG to False here since the template tag wouldn't work otherwise
  357
+@override_settings(**dict(TEST_SETTINGS,
  358
+    STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
  359
+    DEBUG=False,
  360
+))
357 361
 class TestCollectionCachedStorage(BaseCollectionTestCase,
358 362
         BaseStaticFilesTestCase, TestCase):
359 363
     """
@@ -515,12 +519,6 @@ def test_cache_key_memcache_validation(self):
515 519
         self.assertEqual(cache_key, 'staticfiles:e95bbc36387084582df2a70750d7b351')
516 520
 
517 521
 
518  
-# we set DEBUG to False here since the template tag wouldn't work otherwise
519  
-TestCollectionCachedStorage = override_settings(**dict(TEST_SETTINGS,
520  
-    STATICFILES_STORAGE='django.contrib.staticfiles.storage.CachedStaticFilesStorage',
521  
-    DEBUG=False,
522  
-))(TestCollectionCachedStorage)
523  
-
524 522
 if sys.platform != 'win32':
525 523
 
526 524
     class TestCollectionLinks(CollectionTestCase, TestDefaults):

0 notes on commit eb163f3

Please sign in to comment.
Something went wrong with that request. Please try again.