Merge lp:~sinzui/launchpad/prefill-homepageurl-0 into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Māris Fogels
Approved revision: no longer in the source branch.
Merged at revision: 11971
Proposed branch: lp:~sinzui/launchpad/prefill-homepageurl-0
Merge into: lp:launchpad
Diff against target: 266 lines (+74/-93)
3 files modified
lib/lp/registry/browser/sourcepackage.py (+6/-0)
lib/lp/registry/browser/tests/test_sourcepackage_views.py (+61/-66)
lib/lp/registry/stories/packaging/xx-sourcepackage-packaging.txt (+7/-27)
To merge this branch: bzr merge lp:~sinzui/launchpad/prefill-homepageurl-0
Reviewer Review Type Date Requested Status
Māris Fogels (community) Approve
Review via email: mp+41652@code.launchpad.net

Description of the change

This is my branch to prefill the homepageurl when registering projects
for packages.

    lp:~sinzui/launchpad/prefill-homepageurl-0
    Diff size: 101
    Launchpad bug: https://bugs.launchpad.net/bugs/621778
    Test command: ./bin/test -vv -t TestSourcePackageViewHelpers
    Pre-implementation: jelmer
    Target release: 10.12

Prefill the homepageurl when registering projects for packages
--------------------------------------------------------------

This is the final branch needed to support prefilling the project's
homepageurl with the homepage url from the source package release.
All the data, forms, and helpers are in place. The helpers need to
pass the homepageurl to the form.

Rules
-----

    * Update get_register_upstream_url() in browser/sourcepackage.py to
      include the homepageurl field.

QA
--

    * Visit https://qastaging.launchpad.net/ubuntu/+source/maven-plugin-tools
    * Choose to register a new project
    * Verify that the homepageurl is
      http://maven.apache.org/plugins/maven-javadoc-plugin/

Lint
----

Linting changed files:
  lib/lp/registry/browser/sourcepackage.py
  lib/lp/registry/browser/tests/test_sourcepackage_views.py

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

Updated get_register_upstream_url to add the homepageurl using the
SP's currentrelease. The value cannot be None because that is serialised
as 'None' which causes a form error since it is not a valid url.
Refactored the setup for a test so that an SP with publishing history is
available to test the homepage.
    lib/lp/registry/browser/sourcepackage.py
    lib/lp/registry/browser/tests/test_sourcepackage_views.py

To post a comment you must log in.
Revision history for this message
Māris Fogels (mars) wrote :

Hi Curtis,

This looks like an excellent change, r=mars.

You may have an opportunity here to refactor the tests for readability. I found the assertEquals() statements hard to read - a custom method like assertInQueryURL() may be easier to read, and also reduce the dependence on the entire query data structure:

  self.assertInQueryURL('field.homepageurl', 'http://eg.dom/bonkers')

Maris

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/sourcepackage.py'
2--- lib/lp/registry/browser/sourcepackage.py 2010-11-23 23:22:27 +0000
3+++ lib/lp/registry/browser/sourcepackage.py 2010-11-24 13:28:47 +0000
4@@ -115,6 +115,11 @@
5 distroseries_string = "%s/%s" % (
6 source_package.distroseries.distribution.name,
7 source_package.distroseries.name)
8+ current_release = source_package.currentrelease
9+ if current_release is not None and current_release.homepage is not None:
10+ homepage = current_release.homepage
11+ else:
12+ homepage = ''
13 params = {
14 '_return_url': canonical_url(source_package),
15 'field.source_package_name': source_package.sourcepackagename.name,
16@@ -122,6 +127,7 @@
17 'field.name': source_package.name,
18 'field.displayname': displayname,
19 'field.title': displayname,
20+ 'field.homepageurl': homepage,
21 'field.__visited_steps__': ProjectAddStepOne.step_name,
22 'field.actions.continue': 'Continue',
23 }
24
25=== modified file 'lib/lp/registry/browser/tests/test_sourcepackage_views.py'
26--- lib/lp/registry/browser/tests/test_sourcepackage_views.py 2010-11-09 23:29:12 +0000
27+++ lib/lp/registry/browser/tests/test_sourcepackage_views.py 2010-11-24 13:28:47 +0000
28@@ -10,6 +10,7 @@
29
30 from zope.component import getUtility
31 from zope.interface import implements
32+from zope.security.proxy import removeSecurityProxy
33
34 from canonical.launchpad.testing.pages import find_tag_by_id
35 from canonical.testing.layers import DatabaseFunctionalLayer
36@@ -36,38 +37,7 @@
37
38 layer = DatabaseFunctionalLayer
39
40- def test_get_register_upstream_url_displayname(self):
41- distroseries = self.factory.makeDistroRelease(
42- distribution=self.factory.makeDistribution(name='zoobuntu'),
43- name='walrus')
44- source_package = self.factory.makeSourcePackage(
45- distroseries=distroseries,
46- sourcepackagename='python-super-package')
47- url = get_register_upstream_url(source_package)
48- expected_base = '/projects/+new'
49- expected_params = [
50- ('_return_url',
51- 'http://launchpad.dev/zoobuntu/walrus/'
52- '+source/python-super-package'),
53- ('field.__visited_steps__', 'projectaddstep1'),
54- ('field.actions.continue', 'Continue'),
55- # The sourcepackagename 'python-super-package' is split on
56- # the hyphens, and each word is capitalized.
57- ('field.displayname', 'Python Super Package'),
58- ('field.distroseries', 'zoobuntu/walrus'),
59- ('field.name', 'python-super-package'),
60- # The summary is missing, since the source package doesn't
61- # have a binary package release, and parse_qsl() excludes
62- # empty params.
63- ('field.source_package_name', 'python-super-package'),
64- ('field.title', 'Python Super Package'),
65- ]
66- base, query = urllib.splitquery(url)
67- params = cgi.parse_qsl(query)
68- self.assertEqual((expected_base, expected_params),
69- (base, params))
70-
71- def test_get_register_upstream_url_summary(self):
72+ def _makePublishedSourcePackage(self):
73 test_publisher = SoyuzTestPublisher()
74 test_data = test_publisher.makeSourcePackageSummaryData()
75 source_package_name = (
76@@ -79,26 +49,57 @@
77 # updateDistroSeriesPackageCache reconnects the db, so the
78 # objects need to be reloaded.
79 distroseries = getUtility(IDistroSeriesSet).get(distroseries_id)
80- source_package = distroseries.getSourcePackage(source_package_name)
81+ return distroseries.getSourcePackage(source_package_name)
82+
83+ def assertInQueryString(self, url, field, value):
84+ base, query = urllib.splitquery(url)
85+ params = cgi.parse_qsl(query)
86+ self.assertTrue((field, value) in params)
87+
88+ def test_get_register_upstream_url_fields(self):
89+ distroseries = self.factory.makeDistroRelease(
90+ distribution=self.factory.makeDistribution(name='zoobuntu'),
91+ name='walrus')
92+ source_package = self.factory.makeSourcePackage(
93+ distroseries=distroseries,
94+ sourcepackagename='python-super-package')
95 url = get_register_upstream_url(source_package)
96- expected_base = '/projects/+new'
97+ base, query = urllib.splitquery(url)
98+ self.assertEqual('/projects/+new', base)
99+ params = cgi.parse_qsl(query)
100 expected_params = [
101 ('_return_url',
102- 'http://launchpad.dev/youbuntu/busy/+source/bonkers'),
103+ 'http://launchpad.dev/zoobuntu/walrus/'
104+ '+source/python-super-package'),
105 ('field.__visited_steps__', 'projectaddstep1'),
106 ('field.actions.continue', 'Continue'),
107- ('field.displayname', 'Bonkers'),
108- ('field.distroseries', 'youbuntu/busy'),
109- ('field.name', 'bonkers'),
110- ('field.source_package_name', 'bonkers'),
111- ('field.summary', 'summary for flubber-bin\n'
112- + 'summary for flubber-lib'),
113- ('field.title', 'Bonkers'),
114+ ('field.displayname', 'Python Super Package'),
115+ ('field.distroseries', 'zoobuntu/walrus'),
116+ ('field.name', 'python-super-package'),
117+ ('field.source_package_name', 'python-super-package'),
118+ ('field.title', 'Python Super Package'),
119 ]
120- base, query = urllib.splitquery(url)
121- params = cgi.parse_qsl(query)
122- self.assertEqual((expected_base, expected_params),
123- (base, params))
124+ self.assertEqual(expected_params, params)
125+
126+ def test_get_register_upstream_url_displayname(self):
127+ # The sourcepackagename 'python-super-package' is split on
128+ # the hyphens, and each word is capitalized.
129+ distroseries = self.factory.makeDistroRelease(
130+ distribution=self.factory.makeDistribution(name='zoobuntu'),
131+ name='walrus')
132+ source_package = self.factory.makeSourcePackage(
133+ distroseries=distroseries,
134+ sourcepackagename='python-super-package')
135+ url = get_register_upstream_url(source_package)
136+ self.assertInQueryString(
137+ url, 'field.displayname', 'Python Super Package')
138+
139+ def test_get_register_upstream_url_summary(self):
140+ source_package = self._makePublishedSourcePackage()
141+ url = get_register_upstream_url(source_package)
142+ self.assertInQueryString(
143+ url, 'field.summary',
144+ 'summary for flubber-bin\nsummary for flubber-lib')
145
146 def test_get_register_upstream_url_summary_duplicates(self):
147
148@@ -130,28 +131,22 @@
149 distroseries=FakeDistroSeries(
150 name='walrus',
151 distribution=FakeDistribution(name='zoobuntu')),
152- releases=[releases])
153+ releases=[releases],
154+ currentrelease=Faker(homepage=None),
155+ )
156+ url = get_register_upstream_url(source_package)
157+ self.assertInQueryString(
158+ url, 'field.summary',
159+ 'summary for bar\nsummary for baz\nsummary for foo')
160
161+ def test_get_register_upstream_url_homepage(self):
162+ source_package = self._makePublishedSourcePackage()
163+ # SourcePackageReleases cannot be modified by users.
164+ removeSecurityProxy(
165+ source_package.currentrelease).homepage = 'http://eg.dom/bonkers'
166 url = get_register_upstream_url(source_package)
167- expected_base = '/projects/+new'
168- expected_params = [
169- ('_return_url',
170- 'http://launchpad.dev/zoobuntu/walrus/+source/foo'),
171- ('field.__visited_steps__', 'projectaddstep1'),
172- ('field.actions.continue', 'Continue'),
173- ('field.displayname', 'Foo'),
174- ('field.distroseries', 'zoobuntu/walrus'),
175- ('field.name', 'foo'),
176- ('field.source_package_name', 'foo'),
177- ('field.summary', 'summary for bar\n'
178- + 'summary for baz\n'
179- + 'summary for foo'),
180- ('field.title', 'Foo'),
181- ]
182- base, query = urllib.splitquery(url)
183- params = cgi.parse_qsl(query)
184- self.assertEqual((expected_base, expected_params),
185- (base, params))
186+ self.assertInQueryString(
187+ url, 'field.homepageurl', 'http://eg.dom/bonkers')
188
189
190 class TestSourcePackageUpstreamConnectionsView(TestCaseWithFactory):
191
192=== modified file 'lib/lp/registry/stories/packaging/xx-sourcepackage-packaging.txt'
193--- lib/lp/registry/stories/packaging/xx-sourcepackage-packaging.txt 2010-11-11 21:48:20 +0000
194+++ lib/lp/registry/stories/packaging/xx-sourcepackage-packaging.txt 2010-11-24 13:28:47 +0000
195@@ -67,11 +67,12 @@
196 The Hoary Hedgehog Release (active development) ...
197 0.1-2 release (main) ... weeks ago
198
199+
200 Register a project from a source package
201 ----------------------------------------
202
203-If an upstream project doesn't already exist in Launchpad, it can
204-be registered with data from the source package prefilling the first
205+No Privileges Person can register a project for a package, and Launchpad
206+will use the data from the source package to prefill the first
207 step of the multistep form.
208
209 >>> user_browser.open(
210@@ -79,16 +80,6 @@
211 >>> user_browser.getControl(
212 ... 'Register the upstream project').selected = True
213 >>> user_browser.getControl("Link to Upstream Project").click()
214- >>> print user_browser.url.replace('&', '\n&')
215- http://launchpad.dev/projects/+new?_return_url=http...%2Bsource%2Fbonkers
216- &field.__visited_steps__=projectaddstep1
217- &field.actions.continue=Continue
218- &field.displayname=Bonkers
219- &field.distroseries=youbuntu%2Fbusy
220- &field.name=bonkers
221- &field.source_package_name=bonkers
222- &field.summary=summary+for+flubber-bin%0Asummary+for+flubber-lib
223- &field.title=Bonkers
224 >>> print user_browser.getControl(name='field.name').value
225 bonkers
226 >>> print user_browser.getControl(name='field.displayname').value
227@@ -102,9 +93,9 @@
228 ... find_tag_by_id(user_browser.contents, 'step-title'))
229 Step 2 (of 2): Check for duplicate projects
230
231-If the user selects "Choose another upstream project" and then finds out
232-that the project doesn't exist, there is a also a link on the
233-+edit-packaging page to register the project.
234+When No Privileges Person selects "Choose another upstream project" and
235+then finds out that the project doesn't exist, he uses the
236+"Link to Upstream Project" button to register the project.
237
238 >>> user_browser.open(
239 ... 'http://launchpad.dev/youbuntu/busy/+source/bonkers/')
240@@ -115,16 +106,6 @@
241 http://launchpad.dev/youbuntu/busy/+source/bonkers/+edit-packaging
242
243 >>> user_browser.getLink("Register the upstream project").click()
244- >>> print user_browser.url.replace('&', '\n&')
245- http://launchpad.dev/projects/+new?_return_url=http...%2Bsource%2Fbonkers
246- &field.__visited_steps__=projectaddstep1
247- &field.actions.continue=Continue
248- &field.displayname=Bonkers
249- &field.distroseries=youbuntu%2Fbusy
250- &field.name=bonkers
251- &field.source_package_name=bonkers
252- &field.summary=summary+for+flubber-bin%0Asummary+for+flubber-lib
253- &field.title=Bonkers
254 >>> print user_browser.getControl(name='field.name').value
255 bonkers
256 >>> print user_browser.getControl(name='field.displayname').value
257@@ -138,8 +119,7 @@
258 ... find_tag_by_id(user_browser.contents, 'step-title'))
259 Step 2 (of 2): Check for duplicate projects
260
261-If there are no problems with the prefilled data, then the license
262-just needs to be selected. The user will then be redirected back
263+After No Privileges Person select the licenses, he user is redirected back
264 to the source package page and an informational message will be displayed.
265
266 >>> user_browser.getControl(name='field.licenses').value = ['BSD']