Code

Ticket #4788: skipped_test_deco_r8069.diff

File skipped_test_deco_r8069.diff, 2.4 KB (added by devin, 6 years ago)

added decorators for skipping tests

Line 
1Index: django/test/__init__.py
2===================================================================
3--- django/test/__init__.py     (revision 8069)
4+++ django/test/__init__.py     (working copy)
5@@ -4,3 +4,6 @@
6 
7 from django.test.client import Client
8 from django.test.testcases import TestCase
9+
10+class SkippedTest(Exception):
11+    pass
12\ No newline at end of file
13Index: django/test/decorators.py
14===================================================================
15--- django/test/decorators.py   (revision 0)
16+++ django/test/decorators.py   (revision 0)
17@@ -0,0 +1,23 @@
18+from django.core import urlresolvers
19+from django.test import SkippedTest
20+
21+def views_required(required_views=[]):
22+    def urls_found():
23+        try:
24+            for view in required_views:
25+                url = urlresolvers.reverse(view)
26+            return True
27+        except urlresolvers.NoReverseMatch:
28+            return False
29+    return conditional_skip(urls_found)
30+
31+def conditional_skip(required_condition):
32+    if required_condition():
33+        return lambda x: x
34+    else:
35+        return skip_test
36+
37+def skip_test(function):
38+    def _skip(x):
39+        raise SkippedTest
40+    return _skip
41\ No newline at end of file
42Index: django/contrib/auth/tests/basic.py
43===================================================================
44--- django/contrib/auth/tests/basic.py  (revision 8069)
45+++ django/contrib/auth/tests/basic.py  (working copy)
46@@ -56,12 +56,14 @@
47 """
48 
49 from django.test import TestCase
50+from django.test.decorators import views_required
51 from django.core import mail
52 
53 class PasswordResetTest(TestCase):
54     fixtures = ['authtestdata.json']
55     urls = 'django.contrib.auth.urls'
56     
57+    @views_required(required_views=['django.contrib.auth.views.password_reset'])
58     def test_email_not_found(self):
59         "Error is raised if the provided email address isn't currently registered"
60         response = self.client.get('/password_reset/')
61@@ -70,6 +72,7 @@
62         self.assertContains(response, "That e-mail address doesn't have an associated user account")
63         self.assertEquals(len(mail.outbox), 0)
64     
65+    @views_required(required_views=['django.contrib.auth.views.password_reset'])
66     def test_email_found(self):
67         "Email is sent if a valid email address is provided for password reset"
68         response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})