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
20 from django.test import TestCase
21 from django.core.urlresolvers import reverse
22 from patchwork.models import Patch, Person, State
23 from patchwork.tests.utils import defaults, create_maintainer
25 class MultipleUpdateTest(TestCase):
27 defaults.project.save()
28 self.user = create_maintainer(defaults.project)
29 self.client.login(username = self.user.username,
30 password = self.user.username)
31 self.properties_form_id = 'patchform-properties'
33 'patchwork.views.patch.list', args = [defaults.project.linkname])
35 'action': 'Update', 'project': str(defaults.project.id),
36 'form': 'patchlistform', 'archived': '*', 'delegate': '*',
39 for name in ['patch one', 'patch two', 'patch three']:
40 patch = Patch(project = defaults.project, msgid = name,
41 name = name, content = '',
42 submitter = Person.objects.get(user = self.user))
44 self.patches.append(patch)
46 def _selectAllPatches(self, data):
47 for patch in self.patches:
48 data['patch_id:%d' % patch.id] = 'checked'
50 def testArchivingPatches(self):
51 data = self.base_data.copy()
52 data.update({'archived': 'True'})
53 self._selectAllPatches(data)
54 response = self.client.post(self.url, data)
55 self.assertContains(response, 'No patches to display',
57 for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
58 self.assertTrue(patch.archived)
60 def testUnArchivingPatches(self):
61 # Start with one patch archived and the remaining ones unarchived.
62 self.patches[0].archived = True
63 self.patches[0].save()
64 data = self.base_data.copy()
65 data.update({'archived': 'False'})
66 self._selectAllPatches(data)
67 response = self.client.post(self.url, data)
68 self.assertContains(response, self.properties_form_id,
70 for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
71 self.assertFalse(patch.archived)
73 def _testStateChange(self, state):
74 data = self.base_data.copy()
75 data.update({'state': str(state)})
76 self._selectAllPatches(data)
77 response = self.client.post(self.url, data)
78 self.assertContains(response, self.properties_form_id,
82 def testStateChangeValid(self):
83 states = [patch.state.pk for patch in self.patches]
84 state = State.objects.exclude(pk__in = states)[0]
85 self._testStateChange(state.pk)
86 for p in self.patches:
87 self.assertEquals(Patch.objects.get(pk = p.pk).state, state)
89 def testStateChangeInvalid(self):
90 state = max(State.objects.all().values_list('id', flat = True)) + 1
91 orig_states = [patch.state for patch in self.patches]
92 response = self._testStateChange(state)
94 [Patch.objects.get(pk = p.pk).state for p in self.patches],
96 self.assertFormError(response, 'patchform', 'state',
97 'Select a valid choice. That choice is not one ' + \
98 'of the available choices.')
100 def _testDelegateChange(self, delegate_str):
101 data = self.base_data.copy()
102 data.update({'delegate': delegate_str})
103 self._selectAllPatches(data)
104 response = self.client.post(self.url, data)
105 self.assertContains(response, self.properties_form_id,
109 def testDelegateChangeValid(self):
110 delegate = create_maintainer(defaults.project)
111 response = self._testDelegateChange(str(delegate.pk))
112 for p in self.patches:
113 self.assertEquals(Patch.objects.get(pk = p.pk).delegate, delegate)
115 def testDelegateClear(self):
116 response = self._testDelegateChange('')
117 for p in self.patches:
118 self.assertEquals(Patch.objects.get(pk = p.pk).delegate, None)