[PATCH 06/25] tests: Clean up 'test_confirm'

Stephen Finucane stephen.finucane at intel.com
Fri Jun 24 07:53:27 AEST 2016


* 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 at intel.com>
---
 patchwork/tests/test_confirm.py |   30 +++++++++++-------------------
 1 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/patchwork/tests/test_confirm.py b/patchwork/tests/test_confirm.py
index 5c5c69e..ff3e383 100644
--- a/patchwork/tests/test_confirm.py
+++ b/patchwork/tests/test_confirm.py
@@ -17,41 +17,33 @@
 # 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 at example.com'
-    secondary_email = 'test2 at 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 at 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))
-- 
1.7.4.1



More information about the Patchwork mailing list