]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/updates.py
tests: Add multiple patch update test
[patchwork] / apps / patchwork / tests / updates.py
1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
3 #
4 # This file is part of the Patchwork package.
5 #
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 import unittest
21 from django.test import TestCase
22 from django.test.client import Client
23 from django.core.urlresolvers import reverse
24 from patchwork.models import Patch, Person, State
25 from patchwork.tests.utils import defaults, create_maintainer, find_in_context
26
27 class MultipleUpdateTest(TestCase):
28     def setUp(self):
29         defaults.project.save()
30         self.user = create_maintainer(defaults.project)
31         self.client.login(username = self.user.username,
32                 password = self.user.username)
33         self.patches = []
34         for name in ['patch one', 'patch two', 'patch three']:
35             patch = Patch(project = defaults.project, msgid = name,
36                             name = name, content = '',
37                             submitter = Person.objects.get(user = self.user))
38             patch.save()
39             self.patches.append(patch)
40         
41     def testStateChangeValid(self):
42         states = [patch.state.pk for patch in self.patches]
43         state = State.objects.exclude(pk__in = states)[0]
44         data = {'action':   'Update',
45                 'project':  str(defaults.project.id),
46                 'form':     'patchlistform',
47                 'archived': '*',
48                 'delegate': '*',
49                 'state':    str(state.pk),
50         }
51         for patch in self.patches:
52             data['patch_id:%d' % patch.id] = 'checked'
53
54         url = reverse('patchwork.views.patch.list',
55                 args = [defaults.project.linkname])
56         response = self.client.post(url, data)
57         self.failUnlessEqual(response.status_code, 200)
58         
59         for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
60             self.assertEquals(patch.state, state)
61
62     def tearDown(self):
63         for p in self.patches:
64             p.delete()
65