← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/product-code-defaults into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/product-code-defaults into lp:launchpad.

Commit message:
Introduce a Person(Product):+code custom stepto that delegates to either +git or +branches depending on Product.vcs.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/product-code-defaults/+merge/261605

Introduce a Person(Product):+code custom stepto that delegates to either +git or +branches depending on Product.vcs.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/product-code-defaults into lp:launchpad.
=== modified file 'lib/lp/code/browser/configure.zcml'
--- lib/lp/code/browser/configure.zcml	2015-06-05 09:08:50 +0000
+++ lib/lp/code/browser/configure.zcml	2015-06-10 10:36:53 +0000
@@ -962,7 +962,7 @@
     <browser:defaultView
         for="lp.registry.interfaces.personproduct.IPersonProduct"
         layer="lp.code.publisher.CodeLayer"
-        name="+branches" />
+        name="+code" />
 
     <browser:page
         for="lp.registry.interfaces.personproduct.IPersonProduct"

=== added file 'lib/lp/code/browser/tests/test_vcslisting.py'
--- lib/lp/code/browser/tests/test_vcslisting.py	1970-01-01 00:00:00 +0000
+++ lib/lp/code/browser/tests/test_vcslisting.py	2015-06-10 10:36:53 +0000
@@ -0,0 +1,63 @@
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the product view classes and templates."""
+
+__metaclass__ = type
+
+from lp.code.browser.branchlisting import (
+    PersonProductBranchesView,
+    ProductBranchesView,
+    )
+from lp.code.browser.gitlisting import (
+    PersonTargetGitListingView,
+    TargetGitListingView,
+    )
+from lp.registry.enums import VCSType
+from lp.testing import TestCaseWithFactory
+from lp.testing.layers import DatabaseFunctionalLayer
+from lp.testing.publication import test_traverse
+
+
+class TestProductDefaultVCSView(TestCaseWithFactory):
+    """Tests that Product:+code delegates to +git or +branches."""
+
+    layer = DatabaseFunctionalLayer
+
+    def test_default_unset(self):
+        product = self.factory.makeProduct()
+        self.assertIs(None, product.vcs)
+        view = test_traverse('/%s/+code' % product.name)[1]
+        self.assertIsInstance(view, ProductBranchesView)
+
+    def test_default_bzr(self):
+        product = self.factory.makeProduct(vcs=VCSType.BZR)
+        view = test_traverse('/%s/+code' % product.name)[1]
+        self.assertIsInstance(view, ProductBranchesView)
+
+    def test_git(self):
+        product = self.factory.makeProduct(vcs=VCSType.GIT)
+        view = test_traverse('/%s/+code' % product.name)[1]
+        self.assertIsInstance(view, TargetGitListingView)
+
+
+class TestPersonProductDefaultVCSView(TestCaseWithFactory):
+    """Tests that Product:+code delegates to +git or +branches."""
+
+    layer = DatabaseFunctionalLayer
+
+    def assertCodeViewClass(self, vcs, cls):
+        person = self.factory.makePerson()
+        product = self.factory.makeProduct(vcs=vcs)
+        self.assertEqual(vcs, product.vcs)
+        view = test_traverse('/~%s/%s/+code' % (person.name, product.name))[1]
+        self.assertIsInstance(view, cls)
+
+    def test_default_unset(self):
+        self.assertCodeViewClass(None, PersonProductBranchesView)
+
+    def test_default_bzr(self):
+        self.assertCodeViewClass(VCSType.BZR, PersonProductBranchesView)
+
+    def test_git(self):
+        self.assertCodeViewClass(VCSType.GIT, PersonTargetGitListingView)

=== added file 'lib/lp/code/browser/vcslisting.py'
--- lib/lp/code/browser/vcslisting.py	1970-01-01 00:00:00 +0000
+++ lib/lp/code/browser/vcslisting.py	2015-06-10 10:36:53 +0000
@@ -0,0 +1,39 @@
+# Copyright 2015 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""VCS-agnostic view aliases that show the default VCS."""
+
+__metaclass__ = type
+
+from zope.component import getMultiAdapter
+
+from lp.registry.enums import VCSType
+from lp.services.webapp import stepto
+
+
+class TargetDefaultVCSNavigationMixin:
+
+    @stepto("+code")
+    def traverse_code_view(self):
+        if self.context.pillar.vcs in (VCSType.BZR, None):
+            view_name = '+branches'
+        elif self.context.pillar.vcs == VCSType.GIT:
+            view_name = '+git'
+        else:
+            raise AssertionError("Unknown VCS")
+        return getMultiAdapter(
+            (self.context, self.request), name=view_name)
+
+
+class PersonTargetDefaultVCSNavigationMixin:
+
+    @stepto("+code")
+    def traverse_code_view(self):
+        if self.context.product.vcs in (VCSType.BZR, None):
+            view_name = '+branches'
+        elif self.context.product.vcs == VCSType.GIT:
+            view_name = '+git'
+        else:
+            raise AssertionError("Unknown VCS")
+        return getMultiAdapter(
+            (self.context, self.request), name=view_name)

=== modified file 'lib/lp/registry/browser/configure.zcml'
--- lib/lp/registry/browser/configure.zcml	2015-05-03 08:34:51 +0000
+++ lib/lp/registry/browser/configure.zcml	2015-06-10 10:36:53 +0000
@@ -1575,7 +1575,7 @@
         for="lp.registry.interfaces.product.IProduct"
         />
     <browser:defaultView
-        name="+branches"
+        name="+code"
         for="lp.registry.interfaces.product.IProduct"
         layer="lp.code.publisher.CodeLayer"
         />

=== modified file 'lib/lp/registry/browser/personproduct.py'
--- lib/lp/registry/browser/personproduct.py	2014-11-24 01:20:26 +0000
+++ lib/lp/registry/browser/personproduct.py	2015-06-10 10:36:53 +0000
@@ -16,6 +16,7 @@
 from zope.traversing.interfaces import IPathAdapter
 
 from lp.app.errors import NotFoundError
+from lp.code.browser.vcslisting import PersonTargetDefaultVCSNavigationMixin
 from lp.code.interfaces.branchnamespace import get_branch_namespace
 from lp.registry.interfaces.personproduct import IPersonProduct
 from lp.services.webapp import (
@@ -27,7 +28,8 @@
 from lp.services.webapp.interfaces import IMultiFacetedBreadcrumb
 
 
-class PersonProductNavigation(Navigation):
+class PersonProductNavigation(PersonTargetDefaultVCSNavigationMixin,
+                              Navigation):
     """Navigation to branches for this person/product."""
     usedfor = IPersonProduct
 

=== modified file 'lib/lp/registry/browser/product.py'
--- lib/lp/registry/browser/product.py	2015-01-29 16:28:30 +0000
+++ lib/lp/registry/browser/product.py	2015-06-10 10:36:53 +0000
@@ -133,6 +133,7 @@
 from lp.bugs.interfaces.bugtask import RESOLVED_BUGTASK_STATUSES
 from lp.code.browser.branchref import BranchRef
 from lp.code.browser.sourcepackagerecipelisting import HasRecipesMenuMixin
+from lp.code.browser.vcslisting import TargetDefaultVCSNavigationMixin
 from lp.registry.browser import (
     add_subscribe_link,
     BaseRdfView,
@@ -206,7 +207,7 @@
     Navigation, BugTargetTraversalMixin,
     FAQTargetNavigationMixin, HasCustomLanguageCodesTraversalMixin,
     QuestionTargetTraversalMixin, StructuralSubscriptionTargetTraversalMixin,
-    PillarNavigationMixin):
+    PillarNavigationMixin, TargetDefaultVCSNavigationMixin):
 
     usedfor = IProduct
 


Follow ups