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
140
141
142
143
144
145
146
147
148
149
|
# Copyright 2010 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for Code of Conduct views."""
__metaclass__ = type
from zope.component import getUtility
from canonical.testing.layers import DatabaseFunctionalLayer
from lp.registry.interfaces.codeofconduct import ISignedCodeOfConductSet
from lp.registry.model.codeofconduct import SignedCodeOfConduct
from lp.testing import (
login_celebrity,
TestCaseWithFactory,
)
from lp.testing.views import create_initialized_view
class TestSignedCodeOfConductAckView(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestSignedCodeOfConductAckView, self).setUp()
self.signed_coc_set = getUtility(ISignedCodeOfConductSet)
self.owner = self.factory.makePerson()
self.admin = login_celebrity('admin')
def test_view_properties(self):
view = create_initialized_view(self.signed_coc_set, name="+new")
self.assertEqual(
'Register a code of conduct signature', view.label)
self.assertEqual(view.label, view.page_title)
self.assertEqual(['owner'], view.field_names)
url = 'http://launchpad.dev/codeofconduct/console'
self.assertEqual(url, view.next_url)
self.assertEqual(url, view.cancel_url)
def test_register_coc_signed_on_paper(self):
form = {
'field.owner': self.owner.name,
'field.actions.add': 'Register',
}
view = create_initialized_view(
self.signed_coc_set, name="+new", form=form,
principal=self.admin)
self.assertEqual([], view.errors)
results = self.signed_coc_set.searchByUser(self.owner.id)
self.assertEqual(1, results.count())
signed_coc = results[0]
self.assertEqual(self.admin, signed_coc.recipient)
class SignCodeOfConductTestCase(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setUp(self):
super(SignCodeOfConductTestCase, self).setUp()
user = self.factory.makePerson()
gpg_key = self.factory.makeGPGKey(user)
self.signed_coc = self.sign_coc(user, gpg_key)
self.admin = login_celebrity('admin')
def sign_coc(self, user, gpg_key):
"""Return a SignedCodeOfConduct using dummy text."""
signed_coc = SignedCodeOfConduct(
owner=user, signingkey=gpg_key,
signedcode="Dummy CoC signed text.", active=True)
return signed_coc
def verify_common_view_properties(self, view):
self.assertEqual(['admincomment'], view.field_names)
self.assertEqual(
view.page_title, view.label)
url = 'http://launchpad.dev/codeofconduct/console/%d' % (
self.signed_coc.id)
self.assertEqual(url, view.next_url)
self.assertEqual(url, view.cancel_url)
def verify_admincomment_required(self, action_name, view_name):
# Empty comments are not permitted for any state change.
form = {
'field.admincomment': '',
'field.actions.change': action_name,
}
view = create_initialized_view(
self.signed_coc, name=view_name, form=form,
principal=self.admin)
self.assertEqual(1, len(view.errors))
self.assertEqual('admincomment', view.errors[0].field_name)
class TestSignedCodeOfConductActiveView(SignCodeOfConductTestCase):
def test_view_properties(self):
self.signed_coc.active = False
view = create_initialized_view(self.signed_coc, name="+activate")
self.assertEqual(
'Activate code of conduct signature', view.label)
self.assertTrue(view.state)
self.verify_common_view_properties(view)
def test_activate(self):
self.signed_coc.active = False
form = {
'field.admincomment': 'The user is sorry.',
'field.actions.change': 'Activate',
}
view = create_initialized_view(
self.signed_coc, name="+activate", form=form,
principal=self.admin)
self.assertEqual([], view.errors)
self.assertTrue(self.signed_coc.active)
self.assertEqual(self.admin, self.signed_coc.recipient)
self.assertEqual(
'The user is sorry.', self.signed_coc.admincomment)
def test_admincomment_required(self):
self.verify_admincomment_required('Activate', '+activate')
class TestSignedCodeOfConductDeactiveView(SignCodeOfConductTestCase):
def test_view_properties(self):
self.signed_coc.active = True
view = create_initialized_view(self.signed_coc, name="+deactivate")
self.assertEqual(
'Deactivate code of conduct signature', view.label)
self.assertFalse(view.state)
self.verify_common_view_properties(view)
def test_deactivate(self):
self.signed_coc.active = True
form = {
'field.admincomment': 'The user is bad.',
'field.actions.change': 'Deactivate',
}
view = create_initialized_view(
self.signed_coc, name="+deactivate", form=form,
principal=self.admin)
self.assertEqual([], view.errors)
self.assertFalse(self.signed_coc.active)
self.assertEqual(
'The user is bad.', self.signed_coc.admincomment)
def test_admincomment_required(self):
self.verify_admincomment_required('Deactivate', '+deactivate')
|