]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Remove duplicated bulk patch creation
authorStephen Finucane <stephen.finucane@intel.com>
Thu, 18 Feb 2016 15:27:11 +0000 (15:27 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 18 Feb 2016 21:13:16 +0000 (21:13 +0000)
A number of tests were bulk creating patches. Seeing as this is a
common operation, it's better to move this into a common location.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/tests/test_bundles.py
patchwork/tests/test_updates.py
patchwork/tests/test_user.py
patchwork/tests/test_xmlrpc.py
patchwork/tests/utils.py

index 958bb55494c46b2f54c5ebaea51d25a210cbec71..cbed216b700892608ecd0aa31f7f3c35d55dfe9b 100644 (file)
@@ -25,11 +25,12 @@ import unittest
 from django.conf import settings
 from django.test import TestCase
 from django.utils.http import urlencode
-
-from patchwork.models import Patch, Bundle, BundlePatch, Person
-from patchwork.tests.utils import defaults, create_user, find_in_context
 from django.utils.six.moves import range, zip
 
+from patchwork.models import Bundle, BundlePatch
+from patchwork.tests.utils import (defaults, create_user, find_in_context,
+                                   create_patches)
+
 
 def bundle_url(bundle):
     return '/bundle/%s/%s/' % (bundle.owner.username, bundle.name)
@@ -65,7 +66,6 @@ class BundleTestBase(TestCase):
     fixtures = ['default_states']
 
     def setUp(self, patch_count=3):
-        patch_names = ['testpatch%d' % (i) for i in range(1, patch_count + 1)]
         self.user = create_user()
         self.client.login(username=self.user.username,
                           password=self.user.username)
@@ -73,15 +73,7 @@ class BundleTestBase(TestCase):
         self.bundle = Bundle(owner=self.user, project=defaults.project,
                              name='testbundle')
         self.bundle.save()
-        self.patches = []
-
-        for patch_name in patch_names:
-            patch = Patch(project=defaults.project,
-                          msgid=patch_name, name=patch_name,
-                          submitter=Person.objects.get(user=self.user),
-                          content='')
-            patch.save()
-            self.patches.append(patch)
+        self.patches = create_patches(patch_count)
 
     def tearDown(self):
         for patch in self.patches:
index d40a0a2bbafd0055e365bfc0ff5c7fb8cb724661..15504f8a3ad382037c32397e326d32531178855f 100644 (file)
@@ -20,8 +20,8 @@
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from patchwork.models import Patch, Person, State
-from patchwork.tests.utils import defaults, create_maintainer
+from patchwork.models import Patch, State
+from patchwork.tests.utils import defaults, create_maintainer, create_patches
 
 
 class MultipleUpdateTest(TestCase):
@@ -38,13 +38,7 @@ class MultipleUpdateTest(TestCase):
             'action': 'Update', 'project': str(defaults.project.id),
             'form': 'patchlistform', 'archived': '*', 'delegate': '*',
             'state': '*'}
-        self.patches = []
-        for name in ['patch one', 'patch two', 'patch three']:
-            patch = Patch(project=defaults.project, msgid=name,
-                          name=name, content='',
-                          submitter=Person.objects.get(user=self.user))
-            patch.save()
-            self.patches.append(patch)
+        self.patches = create_patches(3)
 
     def _selectAllPatches(self, data):
         for patch in self.patches:
index bd97eb74c109d6a634613c20b067a743b135dac8..2d8ebf6567cc220a2dc9db799591c029ca798b18 100644 (file)
@@ -23,9 +23,9 @@ from django.core import mail
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from patchwork.models import (EmailConfirmation, Person, Bundle, UserProfile,
-                              Patch)
+from patchwork.models import EmailConfirmation, Person, Bundle, UserProfile
 from patchwork.tests.utils import defaults, error_strings
+from patchwork.tests import utils
 
 
 def _confirmation_url(conf):
@@ -144,23 +144,6 @@ class UserProfileTest(TestCase):
         self.client.login(username=self.user.username,
                           password=self.user.password)
 
-    # FIXME(stephenfin) Remove duplication from this and test_xmlrpc
-    def _createPatches(self, count=1):
-        defaults.project.save()
-        defaults.patch_author_person.save()
-
-        patches = []
-
-        for _ in range(0, count):
-            patch = Patch(project=defaults.project,
-                          submitter=defaults.patch_author_person,
-                          msgid=make_msgid(),
-                          content=defaults.patch)
-            patch.save()
-            patches.append(patch)
-
-        return patches
-
     def testUserProfile(self):
         response = self.client.get('/user/')
         self.assertContains(response, 'User Profile: %s' % self.user.username)
@@ -183,7 +166,7 @@ class UserProfileTest(TestCase):
         self.assertContains(response, bundle.get_absolute_url())
 
     def testUserProfileTodos(self):
-        patches = self._createPatches(5)
+        patches = utils.create_patches(5)
         for patch in patches:
             patch.delegate = self.user.user
             patch.save()
index bbb7dfbbd744f895c31fde3fbb59d96230330dcb..a5b69fb9e6c175349c6e340621609c2e8a76c959 100644 (file)
@@ -17,7 +17,6 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from email.utils import make_msgid
 import unittest
 
 from django.conf import settings
@@ -25,8 +24,7 @@ from django.core.urlresolvers import reverse
 from django.test import LiveServerTestCase
 from django.utils.six.moves import xmlrpc_client
 
-from patchwork.models import Patch
-from patchwork.tests.utils import defaults
+from patchwork.tests import utils
 
 
 @unittest.skipUnless(settings.ENABLE_XMLRPC,
@@ -44,41 +42,25 @@ class XMLRPCTest(LiveServerTestCase):
         self.assertRedirects(response,
                              reverse('help', kwargs={'path': 'pwclient/'}))
 
-    def _createPatches(self, count=1):
-        defaults.project.save()
-        defaults.patch_author_person.save()
-
-        patches = []
-
-        for _ in range(0, count):
-            patch = Patch(project=defaults.project,
-                          submitter=defaults.patch_author_person,
-                          msgid=make_msgid(),
-                          content=defaults.patch)
-            patch.save()
-            patches.append(patch)
-
-        return patches
-
     def testListSingle(self):
-        patch_objs = self._createPatches()
+        patch_objs = utils.create_patches()
         patches = self.rpc.patch_list()
         self.assertEqual(len(patches), 1)
         self.assertEqual(patches[0]['id'], patch_objs[0].id)
 
     def testListMultiple(self):
-        self._createPatches(5)
+        utils.create_patches(5)
         patches = self.rpc.patch_list()
         self.assertEqual(len(patches), 5)
 
     def testListMaxCount(self):
-        patch_objs = self._createPatches(5)
+        patch_objs = utils.create_patches(5)
         patches = self.rpc.patch_list({'max_count': 2})
         self.assertEqual(len(patches), 2)
         self.assertEqual(patches[0]['id'], patch_objs[0].id)
 
     def testListNegativeMaxCount(self):
-        patch_objs = self._createPatches(5)
+        patch_objs = utils.create_patches(5)
         patches = self.rpc.patch_list({'max_count': -1})
         self.assertEqual(len(patches), 1)
         self.assertEqual(patches[0]['id'], patch_objs[-1].id)
index 04250a8cdad88e5af3f9ee772e3854644bbc7c18..45eb2d3f9d4649ccce92574c0a8b9ecc76abd1db 100644 (file)
@@ -26,7 +26,7 @@ import os
 
 from django.contrib.auth.models import User
 
-from patchwork.models import Project, Person
+from patchwork.models import Project, Person, Patch
 
 
 # helper functions for tests
@@ -86,6 +86,25 @@ def create_maintainer(project):
     return user
 
 
+def create_patches(count=1):
+    """Create 'count' unique patches."""
+    defaults.project.save()
+    defaults.patch_author_person.save()
+
+    patches = []
+
+    for i in range(0, count):
+        patch = Patch(project=defaults.project,
+                      submitter=defaults.patch_author_person,
+                      msgid=make_msgid(),
+                      name='testpatch%d' % (i + 1),
+                      content=defaults.patch)
+        patch.save()
+        patches.append(patch)
+
+    return patches
+
+
 def find_in_context(context, key):
     if isinstance(context, list):
         for c in context: