1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
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.
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.
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
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
27 class MultipleUpdateTest(TestCase):
29 defaults.project.save()
30 self.user = create_maintainer(defaults.project)
31 self.client.login(username = self.user.username,
32 password = self.user.username)
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))
39 self.patches.append(patch)
41 def _testStateChange(self, state):
42 data = {'action': 'Update',
43 'project': str(defaults.project.id),
44 'form': 'patchlistform',
49 for patch in self.patches:
50 data['patch_id:%d' % patch.id] = 'checked'
52 url = reverse('patchwork.views.patch.list',
53 args = [defaults.project.linkname])
54 response = self.client.post(url, data)
55 self.failUnlessEqual(response.status_code, 200)
58 def testStateChangeValid(self):
59 states = [patch.state.pk for patch in self.patches]
60 state = State.objects.exclude(pk__in = states)[0]
61 self._testStateChange(state.pk)
62 for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
63 self.assertEquals(patch.state, state)
65 def testStateChangeInvalid(self):
66 state = max(State.objects.all().values_list('id', flat = True)) + 1
67 orig_states = [patch.state for patch in self.patches]
68 response = self._testStateChange(state)
70 [Patch.objects.get(pk = p.pk).state for p in self.patches],
72 self.assertFormError(response, 'patchform', 'state',
73 'Select a valid choice. That choice is not one ' + \
74 'of the available choices.')
76 def _testDelegateChange(self, delegate_str):
77 data = {'action': 'Update',
78 'project': str(defaults.project.id),
79 'form': 'patchlistform',
82 'delegate': delegate_str
84 for patch in self.patches:
85 data['patch_id:%d' % patch.id] = 'checked'
87 url = reverse('patchwork.views.patch.list',
88 args = [defaults.project.linkname])
89 response = self.client.post(url, data)
90 self.failUnlessEqual(response.status_code, 200)
93 def testDelegateChangeValid(self):
94 delegate = create_maintainer(defaults.project)
95 response = self._testDelegateChange(str(delegate.pk))
96 for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
97 self.assertEquals(patch.delegate, delegate)
99 def testDelegateClear(self):
100 response = self._testDelegateChange('')
101 for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
102 self.assertEquals(patch.delegate, None)
105 for p in self.patches: