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
=== modified file 'lib/lp/registry/model/sourcepackage.py'
--- lib/lp/registry/model/sourcepackage.py 2010-07-15 15:01:18 +0000
+++ lib/lp/registry/model/sourcepackage.py 2010-08-05 17:33:00 +0000
@@ -307,6 +307,8 @@
307 name_summaries = [307 name_summaries = [
308 '%s: %s' % (binary.name, binary.summary)308 '%s: %s' % (binary.name, binary.summary)
309 for binary in current.sample_binary_packages]309 for binary in current.sample_binary_packages]
310 if name_summaries == []:
311 return None
310 return '\n'.join(name_summaries)312 return '\n'.join(name_summaries)
311313
312 @property314 @property
313315
=== 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-05 17:33:00 +0000
@@ -226,6 +226,27 @@
226 self.assertRaises(226 self.assertRaises(
227 NoPartnerArchive, sourcepackage.get_default_archive)227 NoPartnerArchive, sourcepackage.get_default_archive)
228228
229 def test_source_package_summary_no_releases_returns_None(self):
230 sourcepackage = self.factory.makeSourcePackage()
231 self.assertEqual(sourcepackage.summary, None)
232
233 def test_source_package_summary_with_releases_returns_None(self):
234 sourcepackage = self.factory.makeSourcePackage()
235 self.factory.makeSourcePackageRelease(
236 sourcepackagename=sourcepackage.sourcepackagename)
237 self.assertEqual(sourcepackage.summary, None)
238
239 def test_source_package_summary_with_binaries_returns_list(self):
240 sp = getUtility(
241 ILaunchpadCelebrities).ubuntu['warty'].getSourcePackage(
242 'mozilla-firefox')
243
244 expected_summary = (
245 u'mozilla-firefox: Mozilla Firefox Web Browser\n'
246 u'mozilla-firefox-data: No summary available for '
247 u'mozilla-firefox-data in ubuntu warty.')
248 self.assertEqual(''.join(expected_summary), sp.summary)
249
229250
230class TestSourcePackageSecurity(TestCaseWithFactory):251class TestSourcePackageSecurity(TestCaseWithFactory):
231 """Tests for source package branch linking security."""252 """Tests for source package branch linking security."""
232253
=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py 2010-08-02 02:13:52 +0000
+++ lib/lp/soyuz/tests/test_publishing.py 2010-08-05 17:33:00 +0000
@@ -146,8 +146,7 @@
146 PackageUploadStatus.DONE: 'setDone',146 PackageUploadStatus.DONE: 'setDone',
147 PackageUploadStatus.ACCEPTED: 'setAccepted',147 PackageUploadStatus.ACCEPTED: 'setAccepted',
148 }148 }
149 naked_package_upload = remove_security_proxy_and_shout_at_engineer(149 naked_package_upload = removeSecurityProxy(package_upload)
150 package_upload)
151 method = getattr(150 method = getattr(
152 naked_package_upload, status_to_method[upload_status])151 naked_package_upload, status_to_method[upload_status])
153 method()152 method()
@@ -225,7 +224,7 @@
225 changes_file_name=changes_file_name,224 changes_file_name=changes_file_name,
226 changes_file_content=changes_file_content,225 changes_file_content=changes_file_content,
227 upload_status=upload_status)226 upload_status=upload_status)
228 naked_package_upload = remove_security_proxy_and_shout_at_engineer(227 naked_package_upload = removeSecurityProxy(
229 package_upload)228 package_upload)
230 naked_package_upload.addSource(spr)229 naked_package_upload.addSource(spr)
231230