← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/snap-channel-nicer-display into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/snap-channel-nicer-display into lp:launchpad.

Commit message:
Present Snap.store_channels using channel titles rather than raw JSON.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/snap-channel-nicer-display/+merge/300366

Present Snap.store_channels using channel titles rather than raw JSON.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/snap-channel-nicer-display into lp:launchpad.
=== modified file 'lib/lp/snappy/browser/snap.py'
--- lib/lp/snappy/browser/snap.py	2016-07-16 07:46:23 +0000
+++ lib/lp/snappy/browser/snap.py	2016-07-18 17:04:50 +0000
@@ -34,6 +34,7 @@
     List,
     TextLine,
     )
+from zope.schema.interfaces import IVocabularyFactory
 
 from lp import _
 from lp.app.browser.launchpadform import (
@@ -61,6 +62,7 @@
 from lp.services.features import getFeatureFlag
 from lp.services.helpers import english_list
 from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint
+from lp.services.propertycache import cachedproperty
 from lp.services.scripts import log
 from lp.services.webapp import (
     canonical_url,
@@ -186,6 +188,22 @@
         else:
             return 'Built on request'
 
+    @cachedproperty
+    def store_channels(self):
+        if self.context.store_channels is not None:
+            vocabulary = getUtility(
+                IVocabularyFactory, name='SnapStoreChannel')(self.context)
+            channel_titles = []
+            for channel in self.context.store_channels:
+                try:
+                    channel_titles.append(
+                        vocabulary.getTermByToken(channel).title)
+                except LookupError:
+                    channel_titles.append(channel)
+            return ', '.join(channel_titles)
+        else:
+            return None
+
 
 def builds_for_snap(snap):
     """A list of interesting builds.

=== modified file 'lib/lp/snappy/browser/tests/test_snap.py'
--- lib/lp/snappy/browser/tests/test_snap.py	2016-07-18 15:20:59 +0000
+++ lib/lp/snappy/browser/tests/test_snap.py	2016-07-18 17:04:50 +0000
@@ -444,7 +444,7 @@
 
     def test_create_new_snap_display_processors(self):
         branch = self.factory.makeAnyBranch()
-        distroseries = self.setUpDistroSeries()
+        self.setUpDistroSeries()
         browser = self.getViewBrowser(
             branch, view_name="+new-snap", user=self.person)
         processors = browser.getControl(name="field.processors")
@@ -471,7 +471,7 @@
 
     def test_create_new_snap_processors(self):
         branch = self.factory.makeAnyBranch()
-        distroseries = self.setUpDistroSeries()
+        self.setUpDistroSeries()
         browser = self.getViewBrowser(
             branch, view_name="+new-snap", user=self.person)
         processors = browser.getControl(name="field.processors")
@@ -1291,6 +1291,23 @@
             self.setStatus(build, BuildStatus.FULLYBUILT)
         self.assertEqual(list(reversed(builds[1:])), view.builds)
 
+    def test_store_channels_none(self):
+        snap = self.factory.makeSnap()
+        view = create_initialized_view(snap, "+index")
+        self.assertIsNone(view.store_channels)
+
+    def test_store_channels_uses_titles(self):
+        snap_store_client = FakeMethod()
+        snap_store_client.listChannels = FakeMethod(result=[
+            {"name": "stable", "display_name": "Stable"},
+            {"name": "edge", "display_name": "Edge"},
+            ])
+        self.useFixture(
+            ZopeUtilityFixture(snap_store_client, ISnapStoreClient))
+        snap = self.factory.makeSnap(store_channels=["stable", "nonexistent"])
+        view = create_initialized_view(snap, "+index")
+        self.assertEqual("Stable, nonexistent", view.store_channels)
+
 
 class TestSnapRequestBuildsView(BrowserTestCase):
 

=== modified file 'lib/lp/snappy/templates/snap-index.pt'
--- lib/lp/snappy/templates/snap-index.pt	2016-06-30 17:15:26 +0000
+++ lib/lp/snappy/templates/snap-index.pt	2016-07-18 17:04:50 +0000
@@ -104,10 +104,10 @@
           <a tal:replace="structure view/menu:overview/edit/fmt:icon"/>
         </dd>
       </dl>
-      <dl id="store_channels" tal:condition="context/store_channels">
+      <dl id="store_channels" tal:condition="view/store_channels">
         <dt>Store channels:</dt>
         <dd>
-          <span tal:content="context/store_channels"/>
+          <span tal:content="view/store_channels"/>
           <a tal:replace="structure view/menu:overview/edit/fmt:icon"/>
         </dd>
       </dl>


Follow ups