]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Clean up 'test_confirm'
authorStephen Finucane <stephen.finucane@intel.com>
Mon, 20 Jun 2016 13:47:24 +0000 (14:47 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 30 Jun 2016 15:04:42 +0000 (16:04 +0100)
* Make use of 'create_' helper functions
* Remove unneeded 'XXX.objects.delete()' calls (all objects are deleted
  on teardown of each test)
* Include every import on its own line
* Use underscore_case, rather than camelCase

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/tests/test_confirm.py

index 5c5c69e59191a6d097f75eb738a001c48fb8e76d..ff3e38398977f81d6147c28c31760a99858b26cb 100644 (file)
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from patchwork.models import EmailConfirmation, Person
+from patchwork.models import EmailConfirmation
+from patchwork.tests.utils import create_user
 
 
 def _confirmation_url(conf):
     return reverse('confirm', kwargs={'key': conf.key})
 
 
-class TestUser(object):
-    username = 'testuser'
-    email = 'test@example.com'
-    secondary_email = 'test2@example.com'
-    password = None
-
-    def __init__(self):
-        self.password = User.objects.make_random_password()
-        self.user = User.objects.create_user(self.username,
-                                             self.email, self.password)
+def _generate_secondary_email(user):
+    return 'secondary_%d@example.com' % user.id
 
 
 class InvalidConfirmationTest(TestCase):
 
     def setUp(self):
-        EmailConfirmation.objects.all().delete()
-        Person.objects.all().delete()
-        self.user = TestUser()
+        self.user = create_user()
+        self.secondary_email = _generate_secondary_email(self.user)
+
         self.conf = EmailConfirmation(type='userperson',
-                                      email=self.user.secondary_email,
-                                      user=self.user.user)
+                                      email=self.secondary_email,
+                                      user=self.user)
         self.conf.save()
 
-    def testInactiveConfirmation(self):
+    def test_inactive_confirmation(self):
         self.conf.active = False
         self.conf.save()
         response = self.client.get(_confirmation_url(self.conf))
@@ -60,7 +52,7 @@ class InvalidConfirmationTest(TestCase):
         self.assertEqual(response.context['error'], 'inactive')
         self.assertEqual(response.context['conf'], self.conf)
 
-    def testExpiredConfirmation(self):
+    def test_expired_confirmation(self):
         self.conf.date -= self.conf.validity
         self.conf.save()
         response = self.client.get(_confirmation_url(self.conf))