Merge lp:~jcsackett/launchpad/bugfix-612408 into lp:launchpad

Proposed by Curtis Hovey
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 11310
Proposed branch: lp:~jcsackett/launchpad/bugfix-612408
Merge into: lp:launchpad
Diff against target: 66 lines (+25/-3)
3 files modified
lib/lp/registry/model/sourcepackage.py (+2/-0)
lib/lp/registry/tests/test_sourcepackage.py (+21/-0)
lib/lp/soyuz/tests/test_publishing.py (+2/-3)
To merge this branch: bzr merge lp:~jcsackett/launchpad/bugfix-612408
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+31599@code.launchpad.net

Commit message

Handles situations where summary is requested in sp and dsp with no publication history. Previously if summary was called for a package without history, an oops was the result.

Description of the change

During the preimplementation discussion, the cause of the error was discovered in the model and that it is possible for there to be a sourcepackagerelease that had no binaries, which is why an empty list was returned instead of None.

The fix was to convert the empty list to None in the return. Additional test coverage was added to verify the 3 conditions that SourcePackage.summary must handle.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Launcpad wraps code at 78 characters so that it can be quoted in email. Run `make lint` to verify that files are okay.

review: Needs Information (code)
Revision history for this message
Curtis Hovey (sinzui) wrote :

Hi John.

Thanks for making this change. Creating the soyuz publication and cache data for binary package is truly difficult. I think we want to make that easier in the future, but for now, using sample data to close an oops is the best thing.

You can land your branch after you address my style concern below.

> === modified file 'lib/lp/registry/tests/test_sourcepackage.py'
> --- lib/lp/registry/tests/test_sourcepackage.py 2010-08-03 15:28:48 +0000
> +++ lib/lp/registry/tests/test_sourcepackage.py 2010-08-04 14:23:49 +0000
> @@ -226,6 +226,25 @@
> self.assertRaises(
> NoPartnerArchive, sourcepackage.get_default_archive)
>
> + def test_source_package_summary_no_releases_returns_None(self):
> + sourcepackage = self.factory.makeSourcePackage()
> + self.assertEqual(sourcepackage.summary, None)
> +
> + def test_source_package_summary_with_releases_returns_None(self):
> + sourcepackage = self.factory.makeSourcePackage()
> + self.factory.makeSourcePackageRelease(
> + sourcepackagename=sourcepackage.sourcepackagename)
> + self.assertEqual(sourcepackage.summary, None)
> +
> + def test_source_package_summary_with_binaries_returns_list(self):
> + sp = getUtility(
> + ILaunchpadCelebrities).ubuntu['warty'].getSourcePackage(
> + 'mozilla-firefox')
> + expected_summary = u'mozilla-firefox: Mozilla Firefox \
> +Web Browser\nmozilla-firefox-data: No summary available for \
> +mozilla-firefox-data in ubuntu warty.'
> + self.assertEqual(expected_summary, sp.summary)
> +

This form of wrapping is hard to read we use () to work with long strings
and we take advantage of string concatenation rules. We want to see preserve
indentation so that the code is easy to scan. In general, we avoid
the use of \ because you have to read the ending of a line to know what is
happening on another. We avoid end comments for the same reason. I think
format works:
        expected_summary = (
            u'mozilla-firefox: Mozilla Firefox Web Browser\n'
            u'mozilla-firefox-data: No summary available for '
            u'mozilla-firefox-data in ubuntu warty.')

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/registry/model/sourcepackage.py'
2--- lib/lp/registry/model/sourcepackage.py 2010-07-15 15:01:18 +0000
3+++ lib/lp/registry/model/sourcepackage.py 2010-08-05 17:33:00 +0000
4@@ -307,6 +307,8 @@
5 name_summaries = [
6 '%s: %s' % (binary.name, binary.summary)
7 for binary in current.sample_binary_packages]
8+ if name_summaries == []:
9+ return None
10 return '\n'.join(name_summaries)
11
12 @property
13
14=== modified file 'lib/lp/registry/tests/test_sourcepackage.py'
15--- lib/lp/registry/tests/test_sourcepackage.py 2010-08-03 15:28:48 +0000
16+++ lib/lp/registry/tests/test_sourcepackage.py 2010-08-05 17:33:00 +0000
17@@ -226,6 +226,27 @@
18 self.assertRaises(
19 NoPartnerArchive, sourcepackage.get_default_archive)
20
21+ def test_source_package_summary_no_releases_returns_None(self):
22+ sourcepackage = self.factory.makeSourcePackage()
23+ self.assertEqual(sourcepackage.summary, None)
24+
25+ def test_source_package_summary_with_releases_returns_None(self):
26+ sourcepackage = self.factory.makeSourcePackage()
27+ self.factory.makeSourcePackageRelease(
28+ sourcepackagename=sourcepackage.sourcepackagename)
29+ self.assertEqual(sourcepackage.summary, None)
30+
31+ def test_source_package_summary_with_binaries_returns_list(self):
32+ sp = getUtility(
33+ ILaunchpadCelebrities).ubuntu['warty'].getSourcePackage(
34+ 'mozilla-firefox')
35+
36+ expected_summary = (
37+ u'mozilla-firefox: Mozilla Firefox Web Browser\n'
38+ u'mozilla-firefox-data: No summary available for '
39+ u'mozilla-firefox-data in ubuntu warty.')
40+ self.assertEqual(''.join(expected_summary), sp.summary)
41+
42
43 class TestSourcePackageSecurity(TestCaseWithFactory):
44 """Tests for source package branch linking security."""
45
46=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
47--- lib/lp/soyuz/tests/test_publishing.py 2010-08-02 02:13:52 +0000
48+++ lib/lp/soyuz/tests/test_publishing.py 2010-08-05 17:33:00 +0000
49@@ -146,8 +146,7 @@
50 PackageUploadStatus.DONE: 'setDone',
51 PackageUploadStatus.ACCEPTED: 'setAccepted',
52 }
53- naked_package_upload = remove_security_proxy_and_shout_at_engineer(
54- package_upload)
55+ naked_package_upload = removeSecurityProxy(package_upload)
56 method = getattr(
57 naked_package_upload, status_to_method[upload_status])
58 method()
59@@ -225,7 +224,7 @@
60 changes_file_name=changes_file_name,
61 changes_file_content=changes_file_content,
62 upload_status=upload_status)
63- naked_package_upload = remove_security_proxy_and_shout_at_engineer(
64+ naked_package_upload = removeSecurityProxy(
65 package_upload)
66 naked_package_upload.addSource(spr)
67