summaryrefslogtreecommitdiffstats
path: root/apps/patchwork/tests/updates.py
blob: e5f175c37757f30062c1dee4fb164385dc267634 (plain)
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
# 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

import unittest
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from patchwork.models import Patch, Person, State
from patchwork.tests.utils import defaults, create_maintainer, find_in_context

class MultipleUpdateTest(TestCase):
    def setUp(self):
        defaults.project.save()
        self.user = create_maintainer(defaults.project)
        self.client.login(username = self.user.username,
                password = self.user.username)
        self.patches = []
        for name in ['patch one', 'patch two', 'patch three']:
            patch = Patch(project = defaults.project, msgid = name,
                            name = name, content = '',
                            submitter = Person.objects.get(user = self.user))
            patch.save()
            self.patches.append(patch)
        
    def _testStateChange(self, state):
        data = {'action':   'Update',
                'project':  str(defaults.project.id),
                'form':     'patchlistform',
                'archived': '*',
                'delegate': '*',
                'state':    str(state),
        }
        for patch in self.patches:
            data['patch_id:%d' % patch.id] = 'checked'

        url = reverse('patchwork.views.patch.list',
                args = [defaults.project.linkname])
        response = self.client.post(url, data)
        self.failUnlessEqual(response.status_code, 200)
        return response

    def testStateChangeValid(self):
        states = [patch.state.pk for patch in self.patches]
        state = State.objects.exclude(pk__in = states)[0]
        self._testStateChange(state.pk)
        for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
            self.assertEquals(patch.state, state)

    def testStateChangeInvalid(self):
        state = max(State.objects.all().values_list('id', flat = True)) + 1
        orig_states = [patch.state for patch in self.patches]
        response = self._testStateChange(state)
        self.assertEquals( \
                [Patch.objects.get(pk = p.pk).state for p in self.patches],
                orig_states)
        self.assertFormError(response, 'patchform', 'state',
                    'Select a valid choice. That choice is not one ' + \
                        'of the available choices.')

    def _testDelegateChange(self, delegate_str):
        data = {'action':   'Update',
                'project':  str(defaults.project.id),
                'form':     'patchlistform',
                'archived': '*',
                'state':    '*',
                'delegate': delegate_str
        }
        for patch in self.patches:
            data['patch_id:%d' % patch.id] = 'checked'

        url = reverse('patchwork.views.patch.list',
                args = [defaults.project.linkname])
        response = self.client.post(url, data)
        self.failUnlessEqual(response.status_code, 200)
        return response

    def testDelegateChangeValid(self):
        delegate = create_maintainer(defaults.project)
        response = self._testDelegateChange(str(delegate.pk))
        for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
            self.assertEquals(patch.delegate, delegate)

    def testDelegateClear(self):
        response = self._testDelegateChange('')
        for patch in [Patch.objects.get(pk = p.pk) for p in self.patches]:
            self.assertEquals(patch.delegate, None)

    def tearDown(self):
        for p in self.patches:
            p.delete()