← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:fix-publishing-webservice-ci-builds into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:fix-publishing-webservice-ci-builds into launchpad:master with ~cjwatson/launchpad:remove-dsp-is-upstream-link-allowed as a prerequisite.

Commit message:
Fix publishing webservice for published CI builds

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/429509

Published CI builds don't have a component or section.  Fix `ArchivePublisherBase.component_name` and `ArchivePublisherBase.section_name` not to crash in that case.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-publishing-webservice-ci-builds into launchpad:master.
diff --git a/lib/lp/soyuz/browser/tests/test_publishing_webservice.py b/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
index 4f1b7dd..674711d 100644
--- a/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
+++ b/lib/lp/soyuz/browser/tests/test_publishing_webservice.py
@@ -5,11 +5,14 @@
 
 from functools import partial
 
+from testtools.matchers import ContainsDict, Equals, Is
 from zope.security.proxy import removeSecurityProxy
 
+from lp.registry.interfaces.sourcepackage import SourcePackageType
 from lp.services.librarian.browser import ProxiedLibraryFileAlias
 from lp.services.webapp.interfaces import OAuthPermission
 from lp.soyuz.adapters.proxiedsourcefiles import ProxiedSourceLibraryFileAlias
+from lp.soyuz.enums import BinaryPackageFormat
 from lp.testing import (
     TestCaseWithFactory,
     api_url,
@@ -120,6 +123,44 @@ class SourcePackagePublishingHistoryWebserviceTests(TestCaseWithFactory):
         self.assertEqual(200, response.status)
         self.assertTrue(response.jsonBody())
 
+    def test_ci_build(self):
+        person = self.factory.makePerson()
+        webservice = webservice_for_person(
+            person, permission=OAuthPermission.READ_PUBLIC
+        )
+        with person_logged_in(person):
+            distroseries = self.factory.makeDistroSeries()
+            archive = self.factory.makeArchive(
+                distribution=distroseries.distribution
+            )
+            build = self.factory.makeCIBuild()
+            owner = build.git_repository.owner
+            spn = self.factory.makeSourcePackageName()
+            spr = build.createSourcePackageRelease(
+                distroseries, spn, "1.0", creator=owner, archive=archive
+            )
+            spph = self.factory.makeSourcePackagePublishingHistory(
+                sourcepackagerelease=spr,
+                format=SourcePackageType.CI_BUILD,
+            )
+            url = api_url(spph)
+
+        response = webservice.get(url, api_version="devel")
+
+        self.assertEqual(200, response.status)
+        with person_logged_in(person):
+            self.assertThat(
+                response.jsonBody(),
+                ContainsDict(
+                    {
+                        "component_name": Is(None),
+                        "section_name": Is(None),
+                        "source_package_name": Equals(spn.name),
+                        "source_package_version": Equals(spr.version),
+                    }
+                ),
+            )
+
 
 class BinaryPackagePublishingHistoryWebserviceTests(TestCaseWithFactory):
 
@@ -196,3 +237,41 @@ class BinaryPackagePublishingHistoryWebserviceTests(TestCaseWithFactory):
                 for bpf in bpph.binarypackagerelease.files
             ]
         self.assertContentEqual(expected_info, info)
+
+    def test_ci_build(self):
+        person = self.factory.makePerson()
+        webservice = webservice_for_person(
+            person, permission=OAuthPermission.READ_PUBLIC
+        )
+        with person_logged_in(person):
+            build = self.factory.makeCIBuild()
+            bpn = self.factory.makeBinaryPackageName()
+            bpr = build.createBinaryPackageRelease(
+                bpn,
+                "1.0",
+                "test summary",
+                "test description",
+                BinaryPackageFormat.WHL,
+                False,
+            )
+            bpph = self.factory.makeBinaryPackagePublishingHistory(
+                binarypackagerelease=bpr,
+                binpackageformat=BinaryPackageFormat.WHL,
+            )
+            url = api_url(bpph)
+
+        response = webservice.get(url, api_version="devel")
+
+        self.assertEqual(200, response.status)
+        with person_logged_in(person):
+            self.assertThat(
+                response.jsonBody(),
+                ContainsDict(
+                    {
+                        "binary_package_name": Equals(bpn.name),
+                        "binary_package_version": Equals(bpr.version),
+                        "component_name": Is(None),
+                        "section_name": Is(None),
+                    }
+                ),
+            )
diff --git a/lib/lp/soyuz/model/publishing.py b/lib/lp/soyuz/model/publishing.py
index 2a7a3e1..76356e8 100644
--- a/lib/lp/soyuz/model/publishing.py
+++ b/lib/lp/soyuz/model/publishing.py
@@ -212,13 +212,13 @@ class ArchivePublisherBase:
 
     @property
     def component_name(self):
-        """See `ISourcePackagePublishingHistory`"""
-        return self.component.name
+        """See `IPublishingView`."""
+        return self.component.name if self.component is not None else None
 
     @property
     def section_name(self):
-        """See `ISourcePackagePublishingHistory`"""
-        return self.section.name
+        """See `IPublishingView`."""
+        return self.section.name if self.section is not None else None
 
 
 @implementer(ISourcePackagePublishingHistory)