forked from getpatchwork/patchwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_updates.py
More file actions
139 lines (106 loc) · 4.92 KB
/
Copy pathtest_updates.py
File metadata and controls
139 lines (106 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Patchwork - automated patch tracking system
# Copyright (C) 2010 Jeremy Kerr <jk@ozlabs.org>
#
# This file is part of the Patchwork package.
#
# Patchwork is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Patchwork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.test import TestCase
from patchwork.compat import reverse
from patchwork.models import Patch
from patchwork.models import State
from patchwork.tests.utils import create_patches
from patchwork.tests.utils import create_project
from patchwork.tests.utils import create_state
from patchwork.tests.utils import create_maintainer
class MultipleUpdateTest(TestCase):
properties_form_id = 'patchform-properties'
def setUp(self):
self.project = create_project()
self.user = create_maintainer(self.project)
self.patches = create_patches(3, project=self.project)
self.client.login(username=self.user.username,
password=self.user.username)
self.url = reverse('patch-list', args=[self.project.linkname])
self.base_data = {
'action': 'Update',
'project': str(self.project.id),
'form': 'patchlistform',
'archived': '*',
'delegate': '*',
'state': '*'
}
def _select_all_patches(self, data):
for patch in self.patches:
data['patch_id:%d' % patch.id] = 'checked'
def test_archiving_patches(self):
data = self.base_data.copy()
data.update({'archived': 'True'})
self._select_all_patches(data)
response = self.client.post(self.url, data)
self.assertContains(response, 'No patches to display',
status_code=200)
# Don't use the cached version of patches: retrieve from the DB
for patch in [Patch.objects.get(pk=p.pk) for p in self.patches]:
self.assertTrue(patch.archived)
def test_unarchiving_patches(self):
# Start with one patch archived and the remaining ones unarchived.
self.patches[0].archived = True
self.patches[0].save()
data = self.base_data.copy()
data.update({'archived': 'False'})
self._select_all_patches(data)
response = self.client.post(self.url, data)
self.assertContains(response, self.properties_form_id,
status_code=200)
for patch in [Patch.objects.get(pk=p.pk) for p in self.patches]:
self.assertFalse(patch.archived)
def _test_state_change(self, state):
data = self.base_data.copy()
data.update({'state': str(state)})
self._select_all_patches(data)
response = self.client.post(self.url, data)
self.assertContains(response, self.properties_form_id,
status_code=200)
return response
def test_state_change_valid(self):
state = create_state()
self._test_state_change(state.pk)
for patch in [Patch.objects.get(pk=p.pk) for p in self.patches]:
self.assertEqual(patch.state, state)
def test_state_change_invalid(self):
state = max(State.objects.all().values_list('id', flat=True)) + 1
orig_states = [patch.state for patch in self.patches]
response = self._test_state_change(state)
new_states = [Patch.objects.get(pk=p.pk).state for p in self.patches]
self.assertEqual(new_states, orig_states)
self.assertFormError(response, 'patchform', 'state',
'Select a valid choice. That choice is not one ' +
'of the available choices.')
def _test_delegate_change(self, delegate_str):
data = self.base_data.copy()
data.update({'delegate': delegate_str})
self._select_all_patches(data)
response = self.client.post(self.url, data)
self.assertContains(response, self.properties_form_id, status_code=200)
return response
def test_delegate_change_valid(self):
delegate = create_maintainer(self.project)
self._test_delegate_change(str(delegate.pk))
for patch in [Patch.objects.get(pk=p.pk) for p in self.patches]:
self.assertEqual(patch.delegate, delegate)
def test_delegate_clear(self):
self._test_delegate_change('')
for patch in [Patch.objects.get(pk=p.pk) for p in self.patches]:
self.assertEqual(patch.delegate, None)