]> git.ozlabs.org Git - patchwork/blob - patchwork/tests/test_updates.py
login: Focus the username field on load
[patchwork] / patchwork / tests / test_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 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
24
25 class MultipleUpdateTest(TestCase):
26     fixtures = ['default_states']
27
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.properties_form_id = 'patchform-properties'
34         self.url = reverse(
35             'patchwork.views.patch.list', args = [defaults.project.linkname])
36         self.base_data = {
37             'action': 'Update', 'project': str(defaults.project.id),
38             'form': 'patchlistform', 'archived': '*', 'delegate': '*',
39             'state': '*'}
40         self.patches = []
41         for name in ['patch one', 'patch two', 'patch three']:
42             patch = Patch(project = defaults.project, msgid = name,
43                             name = name, content = '',
44                             submitter = Person.objects.get(user = self.user))
45             patch.save()
46             self.patches.append(patch)
47
48     def _selectAllPatches(self, data):
49         for patch in self.patches:
50             data['patch_id:%d' % patch.id] = 'checked'
51
52     def testArchivingPatches(self):
53         data = self.base_data.copy()
54         data.update({'archived': 'True'})
55         self._selectAllPatches(data)
56         response = self.client.post(self.url, data)
57         self.assertContains(response, 'No patches to display',
58                             status_code = 200)
59         for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
60             self.assertTrue(patch.archived)
61
62     def testUnArchivingPatches(self):
63         # Start with one patch archived and the remaining ones unarchived.
64         self.patches[0].archived = True
65         self.patches[0].save()
66         data = self.base_data.copy()
67         data.update({'archived': 'False'})
68         self._selectAllPatches(data)
69         response = self.client.post(self.url, data)
70         self.assertContains(response, self.properties_form_id,
71                             status_code = 200)
72         for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
73             self.assertFalse(patch.archived)
74
75     def _testStateChange(self, state):
76         data = self.base_data.copy()
77         data.update({'state': str(state)})
78         self._selectAllPatches(data)
79         response = self.client.post(self.url, data)
80         self.assertContains(response, self.properties_form_id,
81                             status_code = 200)
82         return response
83
84     def testStateChangeValid(self):
85         states = [patch.state.pk for patch in self.patches]
86         state = State.objects.exclude(pk__in = states)[0]
87         self._testStateChange(state.pk)
88         for p in self.patches:
89             self.assertEquals(Patch.objects.get(pk = p.pk).state, state)
90
91     def testStateChangeInvalid(self):
92         state = max(State.objects.all().values_list('id', flat = True)) + 1
93         orig_states = [patch.state for patch in self.patches]
94         response = self._testStateChange(state)
95         self.assertEquals( \
96                 [Patch.objects.get(pk = p.pk).state for p in self.patches],
97                 orig_states)
98         self.assertFormError(response, 'patchform', 'state',
99                     'Select a valid choice. That choice is not one ' + \
100                         'of the available choices.')
101
102     def _testDelegateChange(self, delegate_str):
103         data = self.base_data.copy()
104         data.update({'delegate': delegate_str})
105         self._selectAllPatches(data)
106         response = self.client.post(self.url, data)
107         self.assertContains(response, self.properties_form_id,
108                             status_code=200)
109         return response
110
111     def testDelegateChangeValid(self):
112         delegate = create_maintainer(defaults.project)
113         response = self._testDelegateChange(str(delegate.pk))
114         for p in self.patches:
115             self.assertEquals(Patch.objects.get(pk = p.pk).delegate, delegate)
116
117     def testDelegateClear(self):
118         response = self._testDelegateChange('')
119         for p in self.patches:
120             self.assertEquals(Patch.objects.get(pk = p.pk).delegate, None)