Merge lp:~michael.nelson/ubuntu-webcatalog/987838-no-screenshots-for-extras-2 into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Merged
Approved by: Natalia Bidart
Approved revision: 123
Merged at revision: 121
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/987838-no-screenshots-for-extras-2
Merge into: lp:ubuntu-webcatalog
Diff against target: 74 lines (+30/-2)
2 files modified
src/webcatalog/management/commands/import_app_install_data.py (+7/-0)
src/webcatalog/tests/test_commands.py (+23/-2)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/987838-no-screenshots-for-extras-2
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+105175@code.launchpad.net

Commit message

Extract Screenshot-Url from packages metadata when present.

Description of the change

Overview
========

The first branch for this bug fixed an apparently unrelated issue, this branch fixes the actual issue that we were not pulling the screenshot url out of the package (which is where it is defined for packages in extra).

`fab test`

Details
=======
I switched off ImportAppInstallTestCase.use_mock_apt_cache and ran a test to find out where i could find the screenshot url... I didn't see a key for it on package or package.candidate but grabbed it from package.candidateRecord [1]

Once coded, I've run the test (for precise) with use_mock_apt_cache=False to ensure the screenshot is set for the 'leds' package. The only uncertainty that i need to check is that package.candidateRecord exists on lucid (Edit: it's available on lucid also [2]).

You can demonstrate this working locally [3].

[1] https://pastebin.canonical.com/65727/
[2] https://pastebin.canonical.com/65733/
[3] https://pastebin.canonical.com/65734/

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Branch look pretty awesome.

One tiny note, instead of:

if 'Screenshot-Url' in package.candidateRecord:
    screenshot_url = package.candidateRecord['Screenshot-Url']

I usually prefer something like:

screenshot_url = package.candidateRecord.get('Screenshot-Url')
if screenshot_url is not None and screenshot_url not in app.screenshots:
    app.applicationmedia_set.create(media_type='screenshot', url=screenshot_url)

The benefits I see in the second option are:

* you access the package.candidateRecord dict only once
* you do not duplicate the literal 'Screenshot-Url' and thus avoid risk of typos
* you avoid an if (and then another inner level in the logic)

So, if you think is worth it, feel free to tweak the code in this MP. I'll be approving anyways since this looks great.

review: Approve
Revision history for this message
Michael Nelson (michael.nelson) wrote :

On Wed, May 9, 2012 at 4:42 PM, Natalia Bidart
<email address hidden> wrote:
> One tiny note, instead of:
>
> if 'Screenshot-Url' in package.candidateRecord:
>    screenshot_url = package.candidateRecord['Screenshot-Url']
>
> I usually prefer something like:
>
> screenshot_url = package.candidateRecord.get('Screenshot-Url')
> if screenshot_url is not None and screenshot_url not in app.screenshots:
>    app.applicationmedia_set.create(media_type='screenshot', url=screenshot_url)
>
> The benefits I see in the second option are:
>
> * you access the package.candidateRecord dict only once
> * you do not duplicate the literal 'Screenshot-Url' and thus avoid risk of typos
> * you avoid an if (and then another inner level in the logic)
>
> So, if you think is worth it, feel free to tweak the code in this MP. I'll be approving anyways since this looks great.

Indeed - thanks! pushed with r123.

123. By Michael Nelson

REFACTOR: improve screenshot_url detection after review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webcatalog/management/commands/import_app_install_data.py'
--- src/webcatalog/management/commands/import_app_install_data.py 2012-04-20 16:57:50 +0000
+++ src/webcatalog/management/commands/import_app_install_data.py 2012-05-09 15:34:21 +0000
@@ -313,6 +313,13 @@
313 version=version,313 version=version,
314 comment=app_comment,314 comment=app_comment,
315 )315 )
316
317 screenshot_url = package.candidateRecord.get('Screenshot-Url')
318 if screenshot_url is not None and (
319 screenshot_url not in app.screenshots):
320 app.applicationmedia_set.create(
321 media_type='screenshot', url=screenshot_url)
322
316 self.fetch_icon_from_extras(app, candidate)323 self.fetch_icon_from_extras(app, candidate)
317 if self.verbosity == 1:324 if self.verbosity == 1:
318 self.output("\n", 1)325 self.output("\n", 1)
319326
=== modified file 'src/webcatalog/tests/test_commands.py'
--- src/webcatalog/tests/test_commands.py 2012-05-03 12:13:00 +0000
+++ src/webcatalog/tests/test_commands.py 2012-05-09 15:34:21 +0000
@@ -89,7 +89,8 @@
89 # firefox and scribus in the cache.89 # firefox and scribus in the cache.
90 use_mock_apt_cache = True90 use_mock_apt_cache = True
9191
92 def make_mock_apt_package(self, name, description, uri='', summary=''):92 def make_mock_apt_package(self, name, description, uri='', summary='',
93 screenshot_url=''):
93 """Helper to DRY up creating a mock apt package."""94 """Helper to DRY up creating a mock apt package."""
94 mock_package = Mock(spec=apt.package.Package)95 mock_package = Mock(spec=apt.package.Package)
95 mock_package.candidate.description = description96 mock_package.candidate.description = description
@@ -98,6 +99,10 @@
98 mock_package.candidate.section = ''99 mock_package.candidate.section = ''
99 mock_package.candidate.summary = summary100 mock_package.candidate.summary = summary
100 mock_package.candidate.version = '1.2.3-4ubuntu1~dev'101 mock_package.candidate.version = '1.2.3-4ubuntu1~dev'
102 apt_record = {}
103 if screenshot_url:
104 apt_record['Screenshot-Url'] = screenshot_url
105 mock_package.candidateRecord = apt_record
101 return mock_package106 return mock_package
102107
103 def make_mock_apt_cache(self):108 def make_mock_apt_cache(self):
@@ -112,7 +117,8 @@
112 description="Scribus description")117 description="Scribus description")
113 mock_other_app = self.make_mock_apt_package('otherapp',118 mock_other_app = self.make_mock_apt_package('otherapp',
114 description="Otherapp description",119 description="Otherapp description",
115 summary="Otherapp the Internet\nA tagline for Otherapp")120 summary="Otherapp the Internet\nA tagline for Otherapp",
121 screenshot_url="http://example.com/screenshot_for_otherapp.png")
116 mock_app_install_data = self.make_mock_apt_package('app-install-data',122 mock_app_install_data = self.make_mock_apt_package('app-install-data',
117 description="App install desc.",123 description="App install desc.",
118 uri='http://example.com/app-install-1.01.deb')124 uri='http://example.com/app-install-1.01.deb')
@@ -283,6 +289,21 @@
283 self.assertTrue(firefox.icon.size > 1)289 self.assertTrue(firefox.icon.size > 1)
284 self.assertTrue(scribus.icon.size > 1)290 self.assertTrue(scribus.icon.size > 1)
285291
292 def test_screenshot_added_to_model(self):
293 call_command(
294 'import_app_install_data', 'natty',
295 local_app_install_data=self.deb_location,
296 local_app_install_data_partner=self.deb_location,
297 verbosity=0)
298
299 otherapp = Application.objects.get(package_name='otherapp')
300 self.assertEqual(1, otherapp.applicationmedia_set.count())
301 app_media = otherapp.applicationmedia_set.all()[0]
302 self.assertEqual('screenshot', app_media.media_type)
303 self.assertEqual(
304 "http://example.com/screenshot_for_otherapp.png",
305 app_media.url)
306
286 def get_package_uri_for_series(self):307 def get_package_uri_for_series(self):
287 uri = import_app_install_data.Command().get_package_uri_for_series(308 uri = import_app_install_data.Command().get_package_uri_for_series(
288 'app-install-data', 'natty')309 'app-install-data', 'natty')

Subscribers

People subscribed via source and target branches