]> git.ozlabs.org Git - patchwork/blob - apps/patchwork/tests/updates.py
e5f175c37757f30062c1dee4fb164385dc267634
[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 _testStateChange(self, state):
42         data = {'action':   'Update',
43                 'project':  str(defaults.project.id),
44                 'form':     'patchlistform',
45                 'archived': '*',
46                 'delegate': '*',
47                 'state':    str(state),
48         }
49         for patch in self.patches:
50             data['patch_id:%d' % patch.id] = 'checked'
51
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)
56         return response
57
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)
64
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)
69         self.assertEquals( \
70                 [Patch.objects.get(pk = p.pk).state for p in self.patches],
71                 orig_states)
72         self.assertFormError(response, 'patchform', 'state',
73                     'Select a valid choice. That choice is not one ' + \
74                         'of the available choices.')
75
76     def _testDelegateChange(self, delegate_str):
77         data = {'action':   'Update',
78                 'project':  str(defaults.project.id),
79                 'form':     'patchlistform',
80                 'archived': '*',
81                 'state':    '*',
82                 'delegate': delegate_str
83         }
84         for patch in self.patches:
85             data['patch_id:%d' % patch.id] = 'checked'
86
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)
91         return response
92
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)
98
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)
103
104     def tearDown(self):
105         for p in self.patches:
106             p.delete()
107