Merge lp:~sinzui/launchpad/edit-packaging-oops-bug-456622 into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~sinzui/launchpad/edit-packaging-oops-bug-456622
Merge into: lp:launchpad
Diff against target: 182 lines
4 files modified
lib/lp/bugs/stories/distribution/xx-distribution-upstream-bug-report.txt (+2/-1)
lib/lp/registry/browser/sourcepackage.py (+36/-2)
lib/lp/registry/browser/tests/sourcepackage-views.txt (+49/-4)
lib/lp/registry/interfaces/sourcepackage.py (+4/-5)
To merge this branch: bzr merge lp:~sinzui/launchpad/edit-packaging-oops-bug-456622
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+14007@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :
Download full text (3.4 KiB)

This is my branch to fix oopses for empty form values in +edit-packaging.

    lp:~sinzui/launchpad/edit-packaging-oops-bug-456622
    Diff size: 169
    Launchpad bug: https://bugs.launchpad.net/bugs/456622
                   https://bugs.launchpad.net/bugs/438090
                   https://bugs.launchpad.net/bugs/276417
    Test command: ./bin/test -vvt "lp.registry.*sourcepackage-views"
    Pre-implementation: No one. This look similar to other OOPs I fixed in
       the past week.
    Target release: 3.1.10

= Fix oopses for empty form values in +edit-packaging =

Bug 456622 [OOPS submitting empty +edit-packaging page]
    As seen in OOPS-1388EA532 a NoneError: None isn't acceptable as a value
    for Packaging.productseries is raised when the form is submitted with the
    product series field empty

Bug 438090 ["Define upstream link" form text is gibberish]
    * The form should not refer to things that don't exist in Launchpad,
      such as "product series".
    * The form label should use standard Launchpad capitalization and
      punctuation, i.e. "Project series:" rather than "Product Series".
    * The page title should be "Link to an upstream project".
    * The language should be free from grammar errors.

Bug 276417 [Launchpad thanks you for package-upstream link no-op]
    * An informational alert appears, falsely claiming "Upstream link updated,
      thank you!".

== Rules ==

Bug 456622 [OOPS submitting empty +edit-packaging page]
    * Add validation to the form
    * Add setupFields to force the productseries field to be required.

Bug 438090 ["Define upstream link" form text is gibberish]
    * Updated the schema to be clear about what is expected
    * Fix the forms label/page_title to: Link to an upstream project

Bug 276417 [Launchpad thanks you for package-upstream link no-op]
    * Return early if the update action is a no-op.

== QA ==

Visit staging.
    * Choose to edit a sourcepackage link
    * Verify that the form ask you to choose a *Project* series.
    * Verify it is listed in the field.
    * Change nothing and Choose update
    * Verify you are not thanks for changing the link
    * Choose edit again.
    * Empty the field and choose update
    * Verify the form reports a field error.

== Lint ==

Linting changed files:
  lib/lp/registry/browser/sourcepackage.py
  lib/lp/registry/browser/tests/sourcepackage-views.txt
  lib/lp/registry/interfaces/sourcepackage.py

== Test ==

    * lib/lp/registry/browser/tests/sourcepackage-views.txt
      * Verified the new page title.
      * Verified that the widget has the correct default value.
      * Added a test to verify the form explains that the project series
        must be chosen.
      * Added a test to verify a change notification is not shown when there
        is no change.

== Implementation ==

    * lib/lp/registry/browser/sourcepackage.py
      * Updated the page title.
      * Added setupFields to make the field required--it is not required
        by the object's main schema.
      * Added a setupWidgets to set the default value of the HTML field.
      * Added a validate method to raise a clear error message.
      * Updated the change...

Read more...

Revision history for this message
Brad Crittenden (bac) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/stories/distribution/xx-distribution-upstream-bug-report.txt'
2--- lib/lp/bugs/stories/distribution/xx-distribution-upstream-bug-report.txt 2009-09-28 12:59:33 +0000
3+++ lib/lp/bugs/stories/distribution/xx-distribution-upstream-bug-report.txt 2009-10-27 18:37:15 +0000
4@@ -194,7 +194,8 @@
5 >>> user_browser.open("http://bugs.launchpad.dev/ubuntu/+upstreamreport")
6 >>> user_browser.getLink('link').click()
7 >>> print user_browser.title
8- Define upstream link : ...
9+ Link to an upstream project : ...
10+
11
12 If you are logged in and can edit the upstream project, you can also set
13 a bug tracker and a bug supervisor. Let's first fix Firefox to stop using
14
15=== modified file 'lib/lp/registry/browser/sourcepackage.py'
16--- lib/lp/registry/browser/sourcepackage.py 2009-10-16 15:00:55 +0000
17+++ lib/lp/registry/browser/sourcepackage.py 2009-10-27 18:37:15 +0000
18@@ -18,6 +18,9 @@
19 from apt_pkg import ParseSrcDepends
20 from zope.component import getUtility, getMultiAdapter
21 from zope.app.form.interfaces import IInputWidget
22+from zope.formlib.form import FormFields
23+
24+from lazr.restful.interface import copy_field
25
26 from canonical.launchpad import helpers
27 from lp.bugs.browser.bugtask import BugTargetTraversalMixin
28@@ -121,19 +124,50 @@
29
30
31 class SourcePackageChangeUpstreamView(LaunchpadEditFormView):
32+ """A view to set the `IProductSeries` of a sourcepackage."""
33 schema = ISourcePackage
34 field_names = ['productseries']
35
36- label = 'Define upstream link'
37+ label = 'Link to an upstream project'
38 page_title = label
39
40 @property
41 def cancel_url(self):
42 return canonical_url(self.context)
43
44+ def setUpFields(self):
45+ """ See `LaunchpadFormView`.
46+
47+ The productseries field is required by the view.
48+ """
49+ super(SourcePackageChangeUpstreamView, self).setUpFields()
50+ field = copy_field(ISourcePackage['productseries'], required=True)
51+ self.form_fields = self.form_fields.omit('productseries')
52+ self.form_fields = self.form_fields + FormFields(field)
53+
54+ def setUpWidgets(self):
55+ """See `LaunchpadFormView`.
56+
57+ Set the current `IProductSeries` as the default value.
58+ """
59+ super(SourcePackageChangeUpstreamView, self).setUpWidgets()
60+ if self.context.productseries is not None:
61+ widget = self.widgets.get('productseries')
62+ widget.setRenderedValue(self.context.productseries)
63+
64+ def validate(self, data):
65+ productseries = data.get('productseries', None)
66+ if productseries is None:
67+ message = "You must choose a project series."
68+ self.setFieldError('productseries', message)
69+
70 @action(_("Change"), name="change")
71 def change(self, action, data):
72- self.context.setPackaging(data['productseries'], self.user)
73+ productseries = data['productseries']
74+ if self.context.productseries == productseries:
75+ # There is nothing to do.
76+ return
77+ self.context.setPackaging(productseries, self.user)
78 self.request.response.addNotification('Upstream link updated.')
79 self.next_url = canonical_url(self.context)
80
81
82=== modified file 'lib/lp/registry/browser/tests/sourcepackage-views.txt'
83--- lib/lp/registry/browser/tests/sourcepackage-views.txt 2009-09-28 12:59:33 +0000
84+++ lib/lp/registry/browser/tests/sourcepackage-views.txt 2009-10-27 18:37:15 +0000
85@@ -13,21 +13,27 @@
86 >>> package = factory.makeSourcePackage(
87 ... sourcepackagename=sourcepackagename, distroseries=distroseries)
88
89- >>> view = create_view(package, name='+edit-packaging')
90+ >>> view = create_initialized_view(package, name='+edit-packaging')
91 >>> print view.label
92- Define upstream link
93+ Link to an upstream project
94
95 >>> print view.page_title
96- Define upstream link
97+ Link to an upstream project
98
99 >>> print view.cancel_url
100 http://launchpad.dev/youbuntu/busy/+source/bonkers
101
102-The view allows the owner or admin to change productseries field.
103+
104+The view allows the logged in user to change product series field. The value
105+of the product series field is None by default because it is not required to
106+create a source package.
107
108 >>> view.field_names
109 ['productseries']
110
111+ >>> print view.widgets.get('productseries')._getFormValue()
112+ <BLANKLINE>
113+
114 >>> print package.productseries
115 None
116
117@@ -51,3 +57,42 @@
118
119 >>> print package.productseries.name
120 crazy
121+
122+ >>> transaction.commit()
123+
124+The form shows the current product series if it is set.
125+
126+ >>> view = create_initialized_view(package, name='+edit-packaging')
127+ >>> print view.widgets.get('productseries')._getFormValue().name
128+ crazy
129+
130+The form requires a product series. An error is raised if the field is left
131+empty.
132+
133+ >>> form = {
134+ ... 'field.productseries': '',
135+ ... 'field.actions.change': 'Change',
136+ ... }
137+ >>> view = create_initialized_view(
138+ ... package, name='+edit-packaging', form=form,
139+ ... principal=product.owner)
140+ >>> for error in view.errors:
141+ ... print error
142+ ('productseries', u'Project series', RequiredMissing())
143+ You must choose a project series.
144+
145+Submitting the same product series as the current packaging is not an error,
146+but there is no notification message that the upstream link was updated.
147+
148+ >>> form = {
149+ ... 'field.productseries': 'bonkers/crazy',
150+ ... 'field.actions.change': 'Change',
151+ ... }
152+ >>> view = create_initialized_view(
153+ ... package, name='+edit-packaging', form=form,
154+ ... principal=product.owner)
155+ >>> view.errors
156+ []
157+
158+ >>> print view.request.response.notifications
159+ []
160
161=== modified file 'lib/lp/registry/interfaces/sourcepackage.py'
162--- lib/lp/registry/interfaces/sourcepackage.py 2009-09-28 14:10:33 +0000
163+++ lib/lp/registry/interfaces/sourcepackage.py 2009-10-27 18:37:15 +0000
164@@ -90,14 +90,13 @@
165 # This is really a reference to an IProductSeries.
166 productseries = exported(
167 ReferenceChoice(
168- title=_("Product Series"), required=False,
169+ title=_("Project series"), required=False,
170 vocabulary="ProductSeries",
171 schema=Interface,
172 description=_(
173- "The best guess we have as to the Launchpad ProductSeries "
174- "for this Source Package. Try find packaging information for "
175- "this specific distroseries then try parent series and "
176- "previous Ubuntu series.")))
177+ "The registered project series that this source package."
178+ "is based on. This series may be the same as the one that "
179+ "earlier versions of this source packages were based on.")))
180
181 releases = Attribute("The full set of source package releases that "
182 "have been published in this distroseries under this source "