Merge lp:~sinzui/launchpad/obsolete-add-edit into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Paul Hummer
Approved revision: no longer in the source branch.
Merged at revision: 11711
Proposed branch: lp:~sinzui/launchpad/obsolete-add-edit
Merge into: lp:launchpad
Diff against target: 833 lines (+251/-446)
12 files modified
lib/canonical/launchpad/templates/launchpad-addform.pt (+0/-81)
lib/canonical/launchpad/templates/launchpad-editform.pt (+0/-104)
lib/canonical/launchpad/zcml/configure.zcml (+0/-2)
lib/canonical/launchpad/zcml/widgets.zcml (+0/-46)
lib/lp/app/browser/configure.zcml (+14/-0)
lib/lp/registry/browser/codeofconduct.py (+52/-118)
lib/lp/registry/browser/configure.zcml (+6/-18)
lib/lp/registry/browser/tests/test_codeofconduct.py (+149/-0)
lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt (+30/-29)
lib/lp/registry/templates/signedcodeofconduct-acknowledge.pt (+0/-16)
lib/lp/registry/templates/signedcodeofconduct-activate.pt (+0/-16)
lib/lp/registry/templates/signedcodeofconduct-deactivate.pt (+0/-16)
To merge this branch: bzr merge lp:~sinzui/launchpad/obsolete-add-edit
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Review via email: mp+38377@code.launchpad.net

Description of the change

This is my branch to remove addform and editform.

    lp:~sinzui/launchpad/obsolete-add-edit
    Diff size: 710
    Launchpad bug:
        https://bugs.launchpad.net/bugs/433074
        https://bugs.launchpad.net/bugs/414857
    Test command: ./bin/test -vv \
          -t coc -t codeofconduct
    Pre-implementation: no one
    Target release: 10.11

Remove addform and editform
---------------------------

These two templates are only used for their macros.

  lib/canonical/launchpad/templates/launchpad-addform.pt
  lib/canonical/launchpad/templates/launchpad-editform.pt

These are the last templates to use them.

    ./lib/lp/registry/templates/signedcodeofconduct-acknowledge.pt:11:
    ./lib/lp/registry/templates/signedcodeofconduct-activate.pt:11:
    ./lib/lp/registry/templates/signedcodeofconduct-deactivate.pt:11:

Rules
-----

    * Add tests for the existing behaviour
    * Convert the views to LaunchpadFormView
    * Update the ZCML to use the generic edit template

QA
--

As an admin, choose a user that has not signed the CoC to test with

    * Visit https://staging.launchpad.net/codeofconduct
    * Search for the user and verify he does has not signed the CoC.
    * Follow the register link.
    * Enter the user's name and choose Register.
    * Search for the user and view his signed CoC record.
    * Verify his CoC is active.
    * Choose to edit icon
    * Add a comment and choose Deactivate.
    * Verify the CoC now states it is inactive.
    * Choose to edit icon
    * Add a comment and choose Activate.
    * Verify the CoC now states it is active.

Lint
----

Linting changed files:
  lib/canonical/launchpad/zcml/widgets.zcml
  lib/lp/registry/browser/codeofconduct.py
  lib/lp/registry/browser/configure.zcml
  lib/lp/registry/browser/tests/test_codeofconduct.py
  lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt
       3: source has bad indentation.
      12: source has bad indentation.
      16: source exceeds 78 characters.
      16: source has bad indentation.
      23: source has bad indentation.
      32: source has bad indentation.

^ I can fix this after the review. The indentation changes will make the diff
difficult to read.

Test
----

    * lib/lp/registry/browser/tests/test_codeofconduct.py
      * Added tests for the signed CoC management views.
    * lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt
      * Updated the story to use the information the user sees.

Implementation
--------------

    * lib/canonical/launchpad/zcml/widgets.zcml
      * Unregistered the deleted templates.
      * I could move the two remaining templates to lp/app and extract
        the last widget ZCML to lp/app/browser/configure.zcml to remove this
        file.
    * lib/lp/registry/browser/codeofconduct.py
      * Converted the AddView and EditView views into LaunchpadFormViews.
      * This looks like a 100% rewrite in the diff, but I made these changes
        using small refactorings. I am surprised I did this much.
    * lib/lp/registry/browser/configure.zcml
      * Replaced the add/edit ZCML with page ZCML.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

The best kind of code to review is the kind that's getting removed. :) Thanks for sorting out some more tech debt.

Please fix the indentation issues raised by lint. Thank you for thinking of your reviewer when you saw those lint issues.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'lib/canonical/launchpad/templates/launchpad-addform.pt'
--- lib/canonical/launchpad/templates/launchpad-addform.pt 2009-09-18 20:25:59 +0000
+++ lib/canonical/launchpad/templates/launchpad-addform.pt 1970-01-01 00:00:00 +0000
@@ -1,81 +0,0 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 metal:use-macro="view/macro:page/main_only"
6>
7 <body>
8
9 <div metal:fill-slot="main">
10
11 <div tal:condition="nothing">
12 This file is a modified version of zope/app/form/browser/add.pt for use
13 in the Launchpad system. You should not edit this file, but rather use
14 it as the default_template attribute of your addform. You create your
15 own template for the specific addform, called table-add.pt for example,
16 which is the template which uses this one.
17 </div>
18
19 <div metal:define-macro="addform">
20
21 <form action="."
22 tal:attributes="action request/URL"
23 method="post"
24 enctype="multipart/form-data"
25 accept-charset="UTF-8">
26
27 <div metal:define-macro="formbody">
28
29 <h1
30 tal:condition="view/label"
31 tal:content="view/label"
32 metal:define-slot="heading"
33 >Add Something</h1>
34
35 <p metal:define-slot="extra_info" tal:replace="nothing">
36 This is the description of the add form.
37 This text will be in bold, beneath the title of the add form,
38 and should explain a little bit about the form.
39 </p>
40
41 <p class="error message"
42 tal:define="status view/update"
43 tal:condition="status"
44 tal:content="status" />
45
46 <div class="row"
47 metal:define-slot="extra_top"
48 tal:replace="nothing">
49 <div>Extra top</div>
50 <div><input type="text" style="width:100%" /></div>
51 </div>
52
53 <div metal:use-macro="context/@@launchpad_widget_macros/launchpad_widget_rows" />
54
55 <div class="row"
56 metal:define-slot="extra_bottom"
57 tal:replace="nothing">
58 <div>Extra bottom</div>
59 <div class="field"><input type="text" style="width:100%" /></div>
60 </div>
61
62 </div>
63 <div class="actions">
64 <input type="submit"
65 value="Add"
66 name="UPDATE_SUBMIT" />
67 </div>
68
69 <div class="row"
70 metal:define-slot="extra_buttons"
71 tal:replace="nothing">
72 </div>
73
74 </form>
75 </div>
76
77 </div>
78 </body>
79
80</html>
81
820
=== removed file 'lib/canonical/launchpad/templates/launchpad-editform.pt'
--- lib/canonical/launchpad/templates/launchpad-editform.pt 2009-09-18 20:25:59 +0000
+++ lib/canonical/launchpad/templates/launchpad-editform.pt 1970-01-01 00:00:00 +0000
@@ -1,104 +0,0 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 metal:use-macro="view/macro:page/main_only"
6>
7 <body>
8
9 <div metal:fill-slot="main">
10
11 <div tal:condition="nothing">
12 This file is a modified version of zope/app/form/browser/edit.pt for use
13 in the Launchpad system. You should not edit this file, but rather use
14 it from your custom editform. You create your own template for the
15 specific editform, called table-edit.pt for example, which is the template
16 which uses this one.</div>
17
18 <div metal:define-macro="editform">
19
20 <h1
21 tal:condition="view/label"
22 tal:content="view/label"
23 >Edit something</h1>
24
25 <form action="." tal:attributes="action request/URL" method="post"
26 enctype="multipart/form-data">
27
28 <div metal:define-macro="formbody">
29
30 <p class="informational message"
31 tal:define="status view/update"
32 tal:condition="status"
33 tal:content="status" />
34
35 <tal:errors
36 define="errors view/errors|nothing;
37 num_errors view/errors/count:len"
38 condition="errors"
39 >
40 <p tal:condition="python: num_errors == 1" class="error message">
41 There is a problem with the information you entered.
42 Please fix it and try again.
43 </p>
44 <p tal:condition="python: num_errors > 1" class="error message">
45 There are
46 <tal:errors replace="num_errors">6</tal:errors>
47 problems with the information you entered.
48 Please fix them and try again.
49 </p>
50 </tal:errors>
51
52 <p class="error message"
53 tal:repeat="top_of_page_error view/top_of_page_errors|nothing"
54 tal:content="structure top_of_page_error">
55 Schema validation errors.
56 </p>
57
58 <div metal:define-slot="extra_info"
59 class="documentDescription"
60 tal:replace="nothing">
61 This is where a document heading paragraph can be inserted. In
62 your actual customised editform, you can fill-slot this with
63 a descriptive paragraph.
64 </div>
65
66 <div class="row"
67 metal:define-slot="extra_top" tal:replace="nothing">
68 <div>Extra top</div>
69 <div class="field"><input type="text" style="width:100%" /></div>
70 </div>
71
72 <div metal:use-macro="context/@@launchpad_widget_macros/launchpad_widget_rows" />
73
74 <div class="separator"></div>
75
76 <div class="row"
77 metal:define-slot="extra_bottom" tal:replace="nothing">
78 <div>Extra bottom</div>
79 <div class="field"><input type="text" style="width:100%" /></div>
80 </div>
81
82 </div>
83
84 <div class="actions">
85 <input
86 type="submit"
87 name="UPDATE_SUBMIT"
88 value="Change"
89 />
90 </div>
91
92 <div class="row" metal:define-slot="extra_buttons"
93 tal:replace="nothing">
94 </div>
95
96 <div class="separator"></div>
97
98 </form>
99
100 </div>
101 </div>
102
103 </body>
104</html>
1050
=== modified file 'lib/canonical/launchpad/zcml/configure.zcml'
--- lib/canonical/launchpad/zcml/configure.zcml 2010-09-30 23:21:35 +0000
+++ lib/canonical/launchpad/zcml/configure.zcml 2010-10-15 01:29:43 +0000
@@ -29,8 +29,6 @@
29 <include file="temporaryblobstorage.zcml" />29 <include file="temporaryblobstorage.zcml" />
30 <include file="webservice.zcml" />30 <include file="webservice.zcml" />
3131
32 <include file="widgets.zcml" />
33
34 <!-- System homepages -->32 <!-- System homepages -->
3533
36 <!-- Event configuration -->34 <!-- Event configuration -->
3735
=== removed file 'lib/canonical/launchpad/zcml/widgets.zcml'
--- lib/canonical/launchpad/zcml/widgets.zcml 2009-07-13 18:15:02 +0000
+++ lib/canonical/launchpad/zcml/widgets.zcml 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
1<!-- Copyright 2009 Canonical Ltd. This software is licensed under the
2 GNU Affero General Public License version 3 (see the file LICENSE).
3-->
4
5<configure
6 xmlns="http://namespaces.zope.org/zope"
7 xmlns:browser="http://namespaces.zope.org/browser"
8 xmlns:i18n="http://namespaces.zope.org/i18n"
9 i18n_domain="launchpad">
10
11 <!-- Launchpad Add and Edit Form METAL
12 These templates can be used by any of the add or edit forms
13 in Launchpad -->
14 <browser:page
15 for="*"
16 name="launchpad_addform"
17 layer="canonical.launchpad.layers.LaunchpadLayer"
18 permission="zope.Public"
19 template="../templates/launchpad-addform.pt"
20 />
21
22 <browser:page
23 for="*"
24 name="launchpad_editform"
25 layer="canonical.launchpad.layers.LaunchpadLayer"
26 permission="zope.Public"
27 template="../templates/launchpad-editform.pt"
28 />
29
30 <browser:page
31 for="*"
32 name="launchpad_form"
33 layer="canonical.launchpad.layers.LaunchpadLayer"
34 permission="zope.Public"
35 template="../templates/launchpad-form.pt"
36 />
37
38 <browser:page
39 for="*"
40 name="launchpad_widget_macros"
41 layer="canonical.launchpad.layers.LaunchpadLayer"
42 permission="zope.Public"
43 template="../templates/launchpad-widget-macros.pt"
44 />
45
46</configure>
470
=== modified file 'lib/lp/app/browser/configure.zcml'
--- lib/lp/app/browser/configure.zcml 2010-10-03 15:30:06 +0000
+++ lib/lp/app/browser/configure.zcml 2010-10-15 01:29:43 +0000
@@ -22,6 +22,20 @@
22 />22 />
23 <browser:page23 <browser:page
24 for="*"24 for="*"
25 name="launchpad_form"
26 layer="canonical.launchpad.layers.LaunchpadLayer"
27 permission="zope.Public"
28 template="../templates/launchpad-form.pt"
29 />
30 <browser:page
31 for="*"
32 name="launchpad_widget_macros"
33 layer="canonical.launchpad.layers.LaunchpadLayer"
34 permission="zope.Public"
35 template="../templates/launchpad-widget-macros.pt"
36 />
37 <browser:page
38 for="*"
25 name="+related-pages"39 name="+related-pages"
26 class="canonical.launchpad.browser.launchpad.NavigationMenuTabs"40 class="canonical.launchpad.browser.launchpad.NavigationMenuTabs"
27 template="../templates/navigationmenu-related-pages.pt"41 template="../templates/navigationmenu-related-pages.pt"
2842
=== renamed file 'lib/canonical/launchpad/templates/launchpad-form.pt' => 'lib/lp/app/templates/launchpad-form.pt'
=== renamed file 'lib/canonical/launchpad/templates/launchpad-widget-macros.pt' => 'lib/lp/app/templates/launchpad-widget-macros.pt'
=== modified file 'lib/lp/registry/browser/codeofconduct.py'
--- lib/lp/registry/browser/codeofconduct.py 2010-08-20 20:31:18 +0000
+++ lib/lp/registry/browser/codeofconduct.py 2010-10-15 01:29:43 +0000
@@ -23,10 +23,6 @@
23 'SignedCodeOfConductDeactiveView',23 'SignedCodeOfConductDeactiveView',
24 ]24 ]
2525
26from zope.app.form.browser.add import (
27 AddView,
28 EditView,
29 )
30from zope.component import getUtility26from zope.component import getUtility
3127
32from canonical.launchpad.webapp import (28from canonical.launchpad.webapp import (
@@ -49,7 +45,6 @@
49 ISignedCodeOfConduct,45 ISignedCodeOfConduct,
50 ISignedCodeOfConductSet,46 ISignedCodeOfConductSet,
51 )47 )
52from lp.registry.interfaces.person import IPerson
5348
5449
55class SignedCodeOfConductSetNavigation(GetitemNavigation):50class SignedCodeOfConductSetNavigation(GetitemNavigation):
@@ -197,38 +192,24 @@
197 return coc_set[coc_conf.currentrelease]192 return coc_set[coc_conf.currentrelease]
198193
199194
200class SignedCodeOfConductAckView(AddView):195class SignedCodeOfConductAckView(LaunchpadFormView):
201 """Acknowledge a Paper Submitted CoC."""196 """Acknowledge a Paper Submitted CoC."""
202197 schema = ISignedCodeOfConduct
203 def __init__(self, context, request):198 field_names = ['owner']
204 self.context = context199 label = 'Register a code of conduct signature'
205 self.request = request200 page_title = label
206 self.bag = getUtility(ILaunchBag)201
207 self._nextURL = '.'202 @property
208 self.page_title = self.label203 def next_url(self):
209 AddView.__init__(self, context, request)204 return canonical_url(self.context)
210205
211 def createAndAdd(self, data):206 cancel_url = next_url
207
208 @action('Register', name='add')
209 def createAndAdd(self, action, data):
212 """Verify and Add the Acknowledge SignedCoC entry."""210 """Verify and Add the Acknowledge SignedCoC entry."""
213 kw = {}211 self.context.acknowledgeSignature(
214212 user=data['owner'], recipient=self.user)
215 for key, value in data.items():
216 kw[str(key)] = value
217
218 # XXX cprov 2005-03-23:
219 # rename unused key:value
220 kw['user'] = kw['owner']
221 del kw['owner']
222
223 recipient = getUtility(ILaunchBag).user
224 kw['recipient'] = recipient
225
226 # use utility to store it in the database
227 sCoC_util = getUtility(ISignedCodeOfConductSet)
228 sCoC_util.acknowledgeSignature(**kw)
229
230 def nextURL(self):
231 return self._nextURL
232213
233214
234class SignedCodeOfConductView:215class SignedCodeOfConductView:
@@ -265,86 +246,39 @@
265 return True246 return True
266247
267248
268# XXX: salgado, bug=414861, 2009-08-17: This view must be converted to a249class SignedCodeOfConductActiveView(LaunchpadFormView):
269# LaunchpadFormView and define a 'cancel_url' so that the form gets a cancel250 """Active a SignedCodeOfConduct Entry."""
270# link.251 schema = ISignedCodeOfConduct
271class SignedCodeOfConductActiveView(EditView):252 field_names = ['admincomment']
272 """Active a SignedCodeOfConduct Entry.253 label = 'Activate code of conduct signature'
273 When activating a signature:254 page_title = label
274 * Grant a new admincomment,255 state = True
275 * store the recipient,256
276 * set active.257 @property
277 """258 def next_url(self):
278259 return canonical_url(self.context)
279 def __init__(self, context, request):260
280 self.context = context261 cancel_url = next_url
281 self.request = request262
282 self.page_title = self.label263 def _change(self, action, data):
283 EditView.__init__(self, context, request)264 admincomment = data['admincomment']
284265 sCoC_util = getUtility(ISignedCodeOfConductSet)
285 def changed(self):266 sCoC_util.modifySignature(
286 admincomment = self.request.form.get('field.admincomment')267 sign_id=self.context.id, recipient=self.user,
287268 admincomment=admincomment, state=self.state)
288 if admincomment:269 self.request.response.redirect(self.next_url)
289 # No verification is needed since this page is protected by270
290 # lp.Admin271 @action('Activate', name='change')
291 recipient = IPerson(self.request.principal, None)272 def activate(self, action, data):
292 kw = {}273 self._change(action, data)
293 kw['recipient'] = recipient274
294 kw['admincomment'] = admincomment275
295 kw['sign_id'] = self.context.id276class SignedCodeOfConductDeactiveView(SignedCodeOfConductActiveView):
296 kw['state'] = True277 """Deactivate a SignedCodeOfConduct Entry."""
297278 label = 'Deactivate code of conduct signature'
298 # use utility to active it in the database279 page_title = label
299 sCoC_util = getUtility(ISignedCodeOfConductSet)280 state = False
300 sCoC_util.modifySignature(**kw)281
301282 @action('Deactivate', name='change')
302 # now redirect to view the SignedCoC283 def deactivate(self, action, data):
303 self.request.response.redirect(self.request.URL[-1])284 self._change(action, data)
304
305 # XXX: cprov 2005-02-26:
306 # How to proceed with no admincomment ?
307
308
309# XXX: salgado, bug=414857, 2009-08-17: This view must be converted to a
310# LaunchpadFormView and define a 'cancel_url' so that the form gets a cancel
311# link.
312class SignedCodeOfConductDeactiveView(EditView):
313 """Deactive a SignedCodeOfConduct Entry.
314 When deactivating a signature:
315 * Grant admincomment,
316 * store recipient,
317 * clear active.
318 """
319
320 def __init__(self, context, request):
321 self.context = context
322 self.request = request
323 self.page_title = self.label
324 EditView.__init__(self, context, request)
325
326 def changed(self):
327 admincomment = self.request.form.get('field.admincomment')
328
329 if admincomment:
330 # No verification is needed since this page is protected by
331 # lp.Edit
332 recipient = IPerson(self.request.principal, None)
333
334 kw = {}
335 kw['recipient'] = recipient
336 kw['admincomment'] = admincomment
337 kw['sign_id'] = self.context.id
338 kw['state'] = False
339
340 # use utility to active it in the database
341 sCoC_util = getUtility(ISignedCodeOfConductSet)
342 sCoC_util.modifySignature(**kw)
343
344 # now redirect to view the SignedCoC
345 self.request.response.redirect(self.request.URL[-1])
346
347
348 # XXX: cprov 2005-02-26:
349 # How to proceed with no admincomment ?
350
351285
=== modified file 'lib/lp/registry/browser/configure.zcml'
--- lib/lp/registry/browser/configure.zcml 2010-10-14 20:20:47 +0000
+++ lib/lp/registry/browser/configure.zcml 2010-10-15 01:29:43 +0000
@@ -256,26 +256,18 @@
256 template="../templates/signedcodeofconduct-index.pt"256 template="../templates/signedcodeofconduct-index.pt"
257 name="+index"/>257 name="+index"/>
258 </browser:pages>258 </browser:pages>
259 <browser:editform259 <browser:page
260 name="+activate"260 name="+activate"
261 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"261 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"
262 schema="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"
263 class="lp.registry.browser.codeofconduct.SignedCodeOfConductActiveView"262 class="lp.registry.browser.codeofconduct.SignedCodeOfConductActiveView"
264 label="Activate code of conduct signature"
265 fields="admincomment"
266 permission="launchpad.Admin"263 permission="launchpad.Admin"
267 template="../templates/signedcodeofconduct-activate.pt">264 template="../../app/templates/generic-edit.pt" />
268 </browser:editform>265 <browser:page
269 <browser:editform
270 name="+deactivate"266 name="+deactivate"
271 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"267 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"
272 schema="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"
273 class="lp.registry.browser.codeofconduct.SignedCodeOfConductDeactiveView"268 class="lp.registry.browser.codeofconduct.SignedCodeOfConductDeactiveView"
274 label="Deactivate code of conduct signature"
275 fields="admincomment"
276 permission="launchpad.Admin"269 permission="launchpad.Admin"
277 template="../templates/signedcodeofconduct-deactivate.pt">270 template="../../app/templates/generic-edit.pt" />
278 </browser:editform>
279 <browser:url271 <browser:url
280 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConductSet"272 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConductSet"
281 path_expression="string:console"273 path_expression="string:console"
@@ -298,16 +290,12 @@
298 permission="launchpad.Admin"290 permission="launchpad.Admin"
299 template="../templates/codeofconduct-admin.pt"291 template="../templates/codeofconduct-admin.pt"
300 name="+index"/>292 name="+index"/>
301 <browser:addform293 <browser:page
302 name="+new"294 name="+new"
303 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConductSet"295 for="lp.registry.interfaces.codeofconduct.ISignedCodeOfConductSet"
304 schema="lp.registry.interfaces.codeofconduct.ISignedCodeOfConduct"
305 label="Register a code of conduct signature"
306 fields="owner"
307 class="lp.registry.browser.codeofconduct.SignedCodeOfConductAckView"296 class="lp.registry.browser.codeofconduct.SignedCodeOfConductAckView"
308 permission="launchpad.Admin"297 permission="launchpad.Admin"
309 template="../templates/signedcodeofconduct-acknowledge.pt">298 template="../../app/templates/generic-edit.pt" />
310 </browser:addform>
311 </facet>299 </facet>
312 <browser:url300 <browser:url
313 for="lp.registry.interfaces.irc.IIrcID"301 for="lp.registry.interfaces.irc.IIrcID"
314302
=== added file 'lib/lp/registry/browser/tests/test_codeofconduct.py'
--- lib/lp/registry/browser/tests/test_codeofconduct.py 1970-01-01 00:00:00 +0000
+++ lib/lp/registry/browser/tests/test_codeofconduct.py 2010-10-15 01:29:43 +0000
@@ -0,0 +1,149 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for Code of Conduct views."""
5
6__metaclass__ = type
7
8from zope.component import getUtility
9
10from canonical.testing.layers import DatabaseFunctionalLayer
11from lp.registry.interfaces.codeofconduct import ISignedCodeOfConductSet
12from lp.registry.model.codeofconduct import SignedCodeOfConduct
13from lp.testing import (
14 login_celebrity,
15 TestCaseWithFactory,
16 )
17from lp.testing.views import create_initialized_view
18
19
20class TestSignedCodeOfConductAckView(TestCaseWithFactory):
21
22 layer = DatabaseFunctionalLayer
23
24 def setUp(self):
25 super(TestSignedCodeOfConductAckView, self).setUp()
26 self.signed_coc_set = getUtility(ISignedCodeOfConductSet)
27 self.owner = self.factory.makePerson()
28 self.admin = login_celebrity('admin')
29
30 def test_view_properties(self):
31 view = create_initialized_view(self.signed_coc_set, name="+new")
32 self.assertEqual(
33 'Register a code of conduct signature', view.label)
34 self.assertEqual(view.label, view.page_title)
35 self.assertEqual(['owner'], view.field_names)
36 url = 'http://launchpad.dev/codeofconduct/console'
37 self.assertEqual(url, view.next_url)
38 self.assertEqual(url, view.cancel_url)
39
40 def test_register_coc_signed_on_paper(self):
41 form = {
42 'field.owner': self.owner.name,
43 'field.actions.add': 'Register',
44 }
45 view = create_initialized_view(
46 self.signed_coc_set, name="+new", form=form,
47 principal=self.admin)
48 self.assertEqual([], view.errors)
49 results = self.signed_coc_set.searchByUser(self.owner.id)
50 self.assertEqual(1, results.count())
51 signed_coc = results[0]
52 self.assertEqual(self.admin, signed_coc.recipient)
53
54
55class SignCodeOfConductTestCase(TestCaseWithFactory):
56
57 layer = DatabaseFunctionalLayer
58
59 def setUp(self):
60 super(SignCodeOfConductTestCase, self).setUp()
61 user = self.factory.makePerson()
62 gpg_key = self.factory.makeGPGKey(user)
63 self.signed_coc = self.sign_coc(user, gpg_key)
64 self.admin = login_celebrity('admin')
65
66 def sign_coc(self, user, gpg_key):
67 """Return a SignedCodeOfConduct using dummy text."""
68 signed_coc = SignedCodeOfConduct(
69 owner=user, signingkey=gpg_key,
70 signedcode="Dummy CoC signed text.", active=True)
71 return signed_coc
72
73 def verify_common_view_properties(self, view):
74 self.assertEqual(['admincomment'], view.field_names)
75 self.assertEqual(
76 view.page_title, view.label)
77 url = 'http://launchpad.dev/codeofconduct/console/%d' % (
78 self.signed_coc.id)
79 self.assertEqual(url, view.next_url)
80 self.assertEqual(url, view.cancel_url)
81
82 def verify_admincomment_required(self, action_name, view_name):
83 # Empty comments are not permitted for any state change.
84 form = {
85 'field.admincomment': '',
86 'field.actions.change': action_name,
87 }
88 view = create_initialized_view(
89 self.signed_coc, name=view_name, form=form,
90 principal=self.admin)
91 self.assertEqual(1, len(view.errors))
92 self.assertEqual('admincomment', view.errors[0].field_name)
93
94
95class TestSignedCodeOfConductActiveView(SignCodeOfConductTestCase):
96
97 def test_view_properties(self):
98 self.signed_coc.active = False
99 view = create_initialized_view(self.signed_coc, name="+activate")
100 self.assertEqual(
101 'Activate code of conduct signature', view.label)
102 self.assertTrue(view.state)
103 self.verify_common_view_properties(view)
104
105 def test_activate(self):
106 self.signed_coc.active = False
107 form = {
108 'field.admincomment': 'The user is sorry.',
109 'field.actions.change': 'Activate',
110 }
111 view = create_initialized_view(
112 self.signed_coc, name="+activate", form=form,
113 principal=self.admin)
114 self.assertEqual([], view.errors)
115 self.assertTrue(self.signed_coc.active)
116 self.assertEqual(self.admin, self.signed_coc.recipient)
117 self.assertEqual(
118 'The user is sorry.', self.signed_coc.admincomment)
119
120 def test_admincomment_required(self):
121 self.verify_admincomment_required('Activate', '+activate')
122
123
124class TestSignedCodeOfConductDeactiveView(SignCodeOfConductTestCase):
125
126 def test_view_properties(self):
127 self.signed_coc.active = True
128 view = create_initialized_view(self.signed_coc, name="+deactivate")
129 self.assertEqual(
130 'Deactivate code of conduct signature', view.label)
131 self.assertFalse(view.state)
132 self.verify_common_view_properties(view)
133
134 def test_deactivate(self):
135 self.signed_coc.active = True
136 form = {
137 'field.admincomment': 'The user is bad.',
138 'field.actions.change': 'Deactivate',
139 }
140 view = create_initialized_view(
141 self.signed_coc, name="+deactivate", form=form,
142 principal=self.admin)
143 self.assertEqual([], view.errors)
144 self.assertFalse(self.signed_coc.active)
145 self.assertEqual(
146 'The user is bad.', self.signed_coc.admincomment)
147
148 def test_admincomment_required(self):
149 self.verify_admincomment_required('Deactivate', '+deactivate')
0150
=== modified file 'lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt'
--- lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt 2009-08-18 14:17:32 +0000
+++ lib/lp/registry/stories/gpg-coc/98-cocacknowledge.txt 2010-10-15 01:29:43 +0000
@@ -1,41 +1,42 @@
1Check to see no CoC signature is registered for Mark:1Check to see no CoC signature is registered for Mark:
22
3 >>> admin_browser.open('http://localhost:9000/codeofconduct/console')3 >>> admin_browser.open('http://localhost:9000/codeofconduct/console')
4 >>> admin_browser.getControl(name='searchfor').value = ["all"]4 >>> admin_browser.getControl(name='searchfor').value = ["all"]
5 >>> admin_browser.getControl(name='name').value = "mark"5 >>> admin_browser.getControl(name='name').value = "mark"
6 >>> admin_browser.getControl(name='search').click()6 >>> admin_browser.getControl(name='search').click()
7 >>> "No signatures found." in admin_browser.contents7 >>> "No signatures found." in admin_browser.contents
8 True8 True
99
10Perform Acknowledge process as Foo bar person:10Perform Acknowledge process as Foo bar person:
1111
12 >>> admin_browser.open('http://localhost:9000/codeofconduct/console/+new')12 >>> admin_browser.open('http://localhost:9000/codeofconduct/console/+new')
13 >>> admin_browser.title13 >>> admin_browser.title
14 'Register a code of conduct signature'14 'Register a code of conduct signature'
1515
16 >>> admin_browser.getControl(name='field.owner').value = "mark@example.com"16 >>> admin_browser.getControl(
17 >>> admin_browser.getControl(name='UPDATE_SUBMIT').click()17 ... name='field.owner').value = "mark@example.com"
18 >>> admin_browser.url18 >>> admin_browser.getControl('Register').click()
19 'http://localhost:9000/codeofconduct/console/'19 >>> admin_browser.url
20 'http://localhost:9000/codeofconduct/console'
2021
21Ensure the CoC was acknowledge by searching in the CoC Admin Console:22Ensure the CoC was acknowledge by searching in the CoC Admin Console:
2223
23 >>> admin_browser.open('http://launchpad.dev/codeofconduct/console')24 >>> admin_browser.open('http://launchpad.dev/codeofconduct/console')
24 >>> admin_browser.getControl(name='searchfor').value = ["all"]25 >>> admin_browser.getControl(name='searchfor').value = ["all"]
25 >>> admin_browser.getControl(name='name').value = "mark"26 >>> admin_browser.getControl(name='name').value = "mark"
26 >>> admin_browser.getControl(name='search').click()27 >>> admin_browser.getControl(name='search').click()
27 >>> print extract_text(find_tag_by_id(admin_browser.contents, 'matches'))28 >>> print extract_text(find_tag_by_id(admin_browser.contents, 'matches'))
28 Mark ... paper submission accepted by Foo Bar [ACTIVE]29 Mark ... paper submission accepted by Foo Bar [ACTIVE]
2930
30Test if the advertisement email was sent:31Test if the advertisement email was sent:
3132
32 >>> import email33 >>> import email
33 >>> from lp.services.mail import stub34 >>> from lp.services.mail import stub
34 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()35 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
35 >>> msg = email.message_from_string(raw_msg)36 >>> msg = email.message_from_string(raw_msg)
36 >>> print msg.get_payload(decode=True)37 >>> print msg.get_payload(decode=True)
37 <BLANKLINE>38 <BLANKLINE>
38 ...39 ...
39 User: 'Mark Shuttleworth'40 User: 'Mark Shuttleworth'
40 Paper Submitted acknowledge by Foo Bar41 Paper Submitted acknowledge by Foo Bar
41 ...42 ...
4243
=== removed file 'lib/lp/registry/templates/signedcodeofconduct-acknowledge.pt'
--- lib/lp/registry/templates/signedcodeofconduct-acknowledge.pt 2009-08-17 15:36:10 +0000
+++ lib/lp/registry/templates/signedcodeofconduct-acknowledge.pt 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 xmlns:i18n="http://xml.zope.org/namespaces/i18n"
6 metal:use-macro="view/macro:page/locationless"
7 i18n:domain="launchpad"
8>
9 <body>
10 <div metal:fill-slot="main">
11 <div metal:use-macro="context/@@launchpad_addform/addform"/>
12 </div>
13 </body>
14 </html>
15
16
170
=== removed file 'lib/lp/registry/templates/signedcodeofconduct-activate.pt'
--- lib/lp/registry/templates/signedcodeofconduct-activate.pt 2009-08-17 15:36:10 +0000
+++ lib/lp/registry/templates/signedcodeofconduct-activate.pt 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 xmlns:i18n="http://xml.zope.org/namespaces/i18n"
6 metal:use-macro="view/macro:page/locationless"
7 i18n:domain="launchpad"
8>
9 <body>
10 <div metal:fill-slot="main">
11 <div metal:use-macro="context/@@launchpad_editform/editform"/>
12 </div>
13 </body>
14 </html>
15
16
170
=== removed file 'lib/lp/registry/templates/signedcodeofconduct-deactivate.pt'
--- lib/lp/registry/templates/signedcodeofconduct-deactivate.pt 2009-08-17 15:36:10 +0000
+++ lib/lp/registry/templates/signedcodeofconduct-deactivate.pt 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 xmlns:i18n="http://xml.zope.org/namespaces/i18n"
6 metal:use-macro="view/macro:page/locationless"
7 i18n:domain="launchpad"
8>
9 <body>
10 <div metal:fill-slot="main">
11 <div metal:use-macro="context/@@launchpad_editform/editform"/>
12 </div>
13 </body>
14 </html>
15
16