]> git.ozlabs.org Git - patchwork/commitdiff
tests: Add multiple patch update test
authorJeremy Kerr <jk@ozlabs.org>
Thu, 2 Sep 2010 10:46:37 +0000 (18:46 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 2 Sep 2010 11:50:29 +0000 (19:50 +0800)
Add a test for updating mulitple patches. Currently fails with django
1.1.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/tests/__init__.py
apps/patchwork/tests/updates.py [new file with mode: 0644]
apps/patchwork/tests/utils.py

index 044c8baca9c4124389901f2833aa6c1658fda943..5ec3923797233de4d5bc96e4fbb5802e0d2c8332 100644 (file)
@@ -18,9 +18,9 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import unittest
-from patchwork.tests import patchparser, encodings, bundles, mboxviews
+from patchwork.tests import patchparser, encodings, bundles, mboxviews, updates
 
-modules = [patchparser, encodings, bundles, mboxviews]
+modules = [patchparser, encodings, bundles, mboxviews, updates]
 
 def suite():
     suite = unittest.TestSuite()
diff --git a/apps/patchwork/tests/updates.py b/apps/patchwork/tests/updates.py
new file mode 100644 (file)
index 0000000..584b787
--- /dev/null
@@ -0,0 +1,65 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import unittest
+from django.test import TestCase
+from django.test.client import Client
+from django.core.urlresolvers import reverse
+from patchwork.models import Patch, Person, State
+from patchwork.tests.utils import defaults, create_maintainer, find_in_context
+
+class MultipleUpdateTest(TestCase):
+    def setUp(self):
+        defaults.project.save()
+        self.user = create_maintainer(defaults.project)
+        self.client.login(username = self.user.username,
+                password = self.user.username)
+        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)
+        
+    def testStateChangeValid(self):
+        states = [patch.state.pk for patch in self.patches]
+        state = State.objects.exclude(pk__in = states)[0]
+        data = {'action':   'Update',
+                'project':  str(defaults.project.id),
+                'form':     'patchlistform',
+                'archived': '*',
+                'delegate': '*',
+                'state':    str(state.pk),
+        }
+        for patch in self.patches:
+            data['patch_id:%d' % patch.id] = 'checked'
+
+        url = reverse('patchwork.views.patch.list',
+                args = [defaults.project.linkname])
+        response = self.client.post(url, data)
+        self.failUnlessEqual(response.status_code, 200)
+        
+        for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
+            self.assertEquals(patch.state, state)
+
+    def tearDown(self):
+        for p in self.patches:
+            p.delete()
+
index 02e0523bc9dfa4147eab1b4c4a403c85657f22e0..5dc5d16e47dd46997750ee3fd3bf529ec80b5134 100644 (file)
@@ -64,6 +64,13 @@ def create_user():
 
     return user
 
+def create_maintainer(project):
+    user = create_user()
+    profile = user.get_profile()
+    profile.maintainer_projects.add(project)
+    profile.save()
+    return user
+
 def find_in_context(context, key):
     if isinstance(context, list):
         for c in context: