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
1=== modified file 'src/webcatalog/management/commands/import_app_install_data.py'
2--- src/webcatalog/management/commands/import_app_install_data.py 2012-04-20 16:57:50 +0000
3+++ src/webcatalog/management/commands/import_app_install_data.py 2012-05-09 15:34:21 +0000
4@@ -313,6 +313,13 @@
5 version=version,
6 comment=app_comment,
7 )
8+
9+ screenshot_url = package.candidateRecord.get('Screenshot-Url')
10+ if screenshot_url is not None and (
11+ screenshot_url not in app.screenshots):
12+ app.applicationmedia_set.create(
13+ media_type='screenshot', url=screenshot_url)
14+
15 self.fetch_icon_from_extras(app, candidate)
16 if self.verbosity == 1:
17 self.output("\n", 1)
18
19=== modified file 'src/webcatalog/tests/test_commands.py'
20--- src/webcatalog/tests/test_commands.py 2012-05-03 12:13:00 +0000
21+++ src/webcatalog/tests/test_commands.py 2012-05-09 15:34:21 +0000
22@@ -89,7 +89,8 @@
23 # firefox and scribus in the cache.
24 use_mock_apt_cache = True
25
26- def make_mock_apt_package(self, name, description, uri='', summary=''):
27+ def make_mock_apt_package(self, name, description, uri='', summary='',
28+ screenshot_url=''):
29 """Helper to DRY up creating a mock apt package."""
30 mock_package = Mock(spec=apt.package.Package)
31 mock_package.candidate.description = description
32@@ -98,6 +99,10 @@
33 mock_package.candidate.section = ''
34 mock_package.candidate.summary = summary
35 mock_package.candidate.version = '1.2.3-4ubuntu1~dev'
36+ apt_record = {}
37+ if screenshot_url:
38+ apt_record['Screenshot-Url'] = screenshot_url
39+ mock_package.candidateRecord = apt_record
40 return mock_package
41
42 def make_mock_apt_cache(self):
43@@ -112,7 +117,8 @@
44 description="Scribus description")
45 mock_other_app = self.make_mock_apt_package('otherapp',
46 description="Otherapp description",
47- summary="Otherapp the Internet\nA tagline for Otherapp")
48+ summary="Otherapp the Internet\nA tagline for Otherapp",
49+ screenshot_url="http://example.com/screenshot_for_otherapp.png")
50 mock_app_install_data = self.make_mock_apt_package('app-install-data',
51 description="App install desc.",
52 uri='http://example.com/app-install-1.01.deb')
53@@ -283,6 +289,21 @@
54 self.assertTrue(firefox.icon.size > 1)
55 self.assertTrue(scribus.icon.size > 1)
56
57+ def test_screenshot_added_to_model(self):
58+ call_command(
59+ 'import_app_install_data', 'natty',
60+ local_app_install_data=self.deb_location,
61+ local_app_install_data_partner=self.deb_location,
62+ verbosity=0)
63+
64+ otherapp = Application.objects.get(package_name='otherapp')
65+ self.assertEqual(1, otherapp.applicationmedia_set.count())
66+ app_media = otherapp.applicationmedia_set.all()[0]
67+ self.assertEqual('screenshot', app_media.media_type)
68+ self.assertEqual(
69+ "http://example.com/screenshot_for_otherapp.png",
70+ app_media.url)
71+
72 def get_package_uri_for_series(self):
73 uri = import_app_install_data.Command().get_package_uri_for_series(
74 'app-install-data', 'natty')

Subscribers

People subscribed via source and target branches