]> git.ozlabs.org Git - patchwork/commitdiff
tests: Move 'reverse' calls inside 'setUp'
authorStephen Finucane <stephen.finucane@intel.com>
Fri, 21 Aug 2015 14:32:11 +0000 (15:32 +0100)
committerDamien Lespiau <damien.lespiau@intel.com>
Fri, 18 Sep 2015 14:51:13 +0000 (15:51 +0100)
Django creates test databases after it loads tests. However, any
operations that exist at class level will be executed before this
database is created. Fix the instances of this issue (mostly 'reverse'
calls or similar) by moving the calls into the relevant 'setUp'
functions for each test.

Acked-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
patchwork/tests/test_mail_settings.py
patchwork/tests/test_user.py

index 35c832ae7136ed0d32794a0b638c40d6d30a7cf1..477f39fa681c0924fde70f920ec55d9311ec3d94 100644 (file)
@@ -25,8 +25,9 @@ from patchwork.models import EmailOptout, EmailConfirmation, Person
 from patchwork.tests.utils import create_user, error_strings
 
 class MailSettingsTest(TestCase):
-    view = 'patchwork.views.mail.settings'
-    url = reverse(view)
+
+    def setUp(self):
+        self.url = reverse('patchwork.views.mail.settings')
 
     def testMailSettingsGET(self):
         response = self.client.get(self.url)
@@ -75,8 +76,9 @@ class MailSettingsTest(TestCase):
         self.assertTrue(('action="%s"' % optin_url) in response.content)
 
 class OptoutRequestTest(TestCase):
-    view = 'patchwork.views.mail.optout'
-    url = reverse(view)
+
+    def setUp(self):
+        self.url = reverse('patchwork.views.mail.optout')
 
     def testOptOutRequestGET(self):
         response = self.client.get(self.url)
@@ -121,10 +123,9 @@ class OptoutRequestTest(TestCase):
         self.assertEquals(len(mail.outbox), 0)
 
 class OptoutTest(TestCase):
-    view = 'patchwork.views.mail.optout'
-    url = reverse(view)
 
     def setUp(self):
+        self.url = reverse('patchwork.views.mail.optout')
         self.email = u'foo@example.com'
         self.conf = EmailConfirmation(type = 'optout', email = self.email)
         self.conf.save()
@@ -154,10 +155,9 @@ class OptoutPreexistingTest(OptoutTest):
         EmailOptout(email = self.email).save()
 
 class OptinRequestTest(TestCase):
-    view = 'patchwork.views.mail.optin'
-    url = reverse(view)
 
     def setUp(self):
+        self.url = reverse('patchwork.views.mail.optin')
         self.email = u'foo@example.com'
         EmailOptout(email = self.email).save()
 
@@ -229,8 +229,9 @@ class OptinTest(TestCase):
 
 class OptinWithoutOptoutTest(TestCase):
     """Test an opt-in with no existing opt-out"""
-    view = 'patchwork.views.mail.optin'
-    url = reverse(view)
+
+    def setUp(self):
+        self.url = reverse('patchwork.views.mail.optin')
 
     def testOptInWithoutOptout(self):
         email = u'foo@example.com'
@@ -245,16 +246,15 @@ class UserProfileOptoutFormTest(TestCase):
     """Test that the correct optin/optout forms appear on the user profile
        page, for logged-in users"""
 
-    view = 'patchwork.views.user.profile'
-    url = reverse(view)
-    optout_url = reverse('patchwork.views.mail.optout')
-    optin_url = reverse('patchwork.views.mail.optin')
-    form_re_template = ('<form\s+[^>]*action="%(url)s"[^>]*>'
-                        '.*?<input\s+[^>]*value="%(email)s"[^>]*>.*?'
-                        '</form>')
-    secondary_email = 'test2@example.com'
-
     def setUp(self):
+        self.url = reverse('patchwork.views.user.profile')
+        self.optout_url = reverse('patchwork.views.mail.optout')
+        self.optin_url = reverse('patchwork.views.mail.optin')
+        self.form_re_template = ('<form\s+[^>]*action="%(url)s"[^>]*>'
+                                 '.*?<input\s+[^>]*value="%(email)s"[^>]*>.*?'
+                                 '</form>')
+        self.secondary_email = 'test2@example.com'
+
         self.user = create_user()
         self.client.login(username = self.user.username,
                 password = self.user.username)
index 8bef45a746b45d49c0b3448b27e77d4575172101..ab461268b2930164d782508725b623e582eea57d 100644 (file)
@@ -25,6 +25,7 @@ from django.contrib.auth.models import User
 from patchwork.models import EmailConfirmation, Person, Bundle, UserProfile
 from patchwork.tests.utils import defaults, error_strings
 
+
 def _confirmation_url(conf):
     return reverse('patchwork.views.confirm', kwargs = {'key': conf.key})
 
@@ -120,7 +121,7 @@ class UserPersonConfirmTest(TestCase):
         self.assertEquals(conf.active, False)
 
 class UserLoginRedirectTest(TestCase):
-    
+
     def testUserLoginRedirect(self):
         url = '/user/'
         response = self.client.get(url)
@@ -177,8 +178,12 @@ class UserProfileTest(TestCase):
 
 
 class UserPasswordChangeTest(TestCase):
-    form_url = reverse('django.contrib.auth.views.password_change')
-    done_url = reverse('django.contrib.auth.views.password_change_done')
+    user = None
+
+    def setUp(self):
+        self.form_url = reverse('django.contrib.auth.views.password_change')
+        self.done_url = reverse(
+            'django.contrib.auth.views.password_change_done')
 
     def testPasswordChangeForm(self):
         self.user = TestUser()