launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #00600
[Merge] lp:~salgado/launchpad/vostok-traverse-package into lp:launchpad/devel
Guilherme Salgado has proposed merging lp:~salgado/launchpad/vostok-traverse-package into lp:launchpad/devel with lp:~salgado/launchpad/layer-specific-navigation as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
This branch adds a custom navigation for IDistribution on the vostok layer so that it's only possible to traverse to distro series and source packages on the vostok.dev vhost.
It also moves the contents of lib/lp/vostok/tests/test_navigation.py to lib/lp/vostok/browser/tests/test_navigation.py and changes lib/lp/vostok/browser/configure.zcml to use relative paths.
--
https://code.launchpad.net/~salgado/launchpad/vostok-traverse-package/+merge/32599
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~salgado/launchpad/vostok-traverse-package into lp:launchpad/devel.
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-08-12 19:47:01 +0000
+++ lib/lp/testing/factory.py 2010-08-13 15:42:48 +0000
@@ -1221,7 +1221,7 @@
# We can't have a series task without a distribution task.
self.makeBugTask(bug, distribution_package)
- return bug.addTask(owner, target)
+ return removeSecurityProxy(bug).addTask(owner, target)
def makeBugTracker(self, base_url=None, bugtrackertype=None):
"""Make a new bug tracker."""
=== modified file 'lib/lp/vostok/browser/configure.zcml'
--- lib/lp/vostok/browser/configure.zcml 2010-08-10 20:59:34 +0000
+++ lib/lp/vostok/browser/configure.zcml 2010-08-13 15:42:48 +0000
@@ -6,18 +6,23 @@
i18n_domain="launchpad">
<browser:defaultView
- for="lp.vostok.publisher.IVostokRoot"
- name="+index"
- />
+ for="..publisher.IVostokRoot"
+ name="+index"
+ />
<browser:page
- for="lp.vostok.publisher.IVostokRoot"
- name="+index"
- class="lp.vostok.browser.root.VostokRootView"
- template="../templates/root.pt"
- permission="zope.Public"
- layer="lp.vostok.publisher.VostokLayer"
- />
+ for="..publisher.IVostokRoot"
+ name="+index"
+ class=".root.VostokRootView"
+ template="../templates/root.pt"
+ permission="zope.Public"
+ layer="..publisher.VostokLayer"
+ />
+
+ <browser:navigation
+ module=".distribution"
+ classes="DistributionNavigation"
+ layer="..publisher.VostokLayer" />
<browser:navigation
module="lp.vostok.publisher"
=== added file 'lib/lp/vostok/browser/distribution.py'
--- lib/lp/vostok/browser/distribution.py 1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/distribution.py 2010-08-13 15:42:48 +0000
@@ -0,0 +1,24 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Browser views for distributions."""
+
+__metaclass__ = type
+
+__all__ = [
+ 'DistributionNavigation',
+ ]
+
+from canonical.launchpad.webapp import GetitemNavigation, stepthrough
+
+from lp.registry.interfaces.distribution import IDistribution
+
+
+class DistributionNavigation(GetitemNavigation):
+
+ usedfor = IDistribution
+
+ @stepthrough('+source')
+ def traverse_sources(self, name):
+ return self.context.getSourcePackage(name)
+
=== added file 'lib/lp/vostok/browser/tests/test_navigation.py'
--- lib/lp/vostok/browser/tests/test_navigation.py 1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/tests/test_navigation.py 2010-08-13 15:42:48 +0000
@@ -0,0 +1,67 @@
+# Copyright 2010 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for Vostok's navigation classes."""
+
+__metaclass__ = type
+
+from zope.publisher.interfaces import NotFound
+from zope.security.proxy import removeSecurityProxy
+
+from canonical.launchpad.webapp import canonical_url, urlparse
+from canonical.testing.layers import DatabaseFunctionalLayer
+
+from lp.testing import TestCaseWithFactory
+from lp.testing.publication import test_traverse
+
+
+class TestRootNavigation(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_traverse_to_distributions(self):
+ # We can traverse to a distribution by name from the vostok
+ # root.
+ distro = self.factory.makeDistribution()
+ obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
+ self.assertEqual(distro, obj)
+
+ def test_traverse_to_distribution_aliases(self):
+ # When we traverse to a distribution using one of its aliases, we're
+ # redirected to the distribution's page on the vostok vhost.
+ distro = self.factory.makeDistribution(aliases=['f00'])
+ obj, view, request = test_traverse('http://vostok.dev/f00')
+ naked_view = removeSecurityProxy(view)
+ parse_result = urlparse(naked_view.target)
+ self.assertEqual('vostok.dev', parse_result.netloc)
+ self.assertEqual('/' + distro.name, parse_result.path)
+
+ def test_can_not_traverse_to_projects(self):
+ # We cannot traverse to a project from the vostok root.
+ path = self.factory.makeProject().name
+ self.assertRaises(
+ NotFound, test_traverse, 'http://vostok.dev/' + path)
+
+
+class TestDistributionNavigation(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_traverse_to_source_package(self):
+ # We can traverse to a source package by name from a distribution on
+ # the vostok vhost.
+ source_package = self.factory.makeDistributionSourcePackage()
+ obj, view, request = test_traverse(
+ canonical_url(source_package, rootsite='vostok'))
+ self.assertEqual(source_package, obj)
+
+ def test_traverse_to_distroseries(self):
+ distroseries = self.factory.makeDistroSeries()
+ obj, view, request = test_traverse(
+ canonical_url(distroseries, rootsite='vostok'))
+ self.assertEqual(distroseries, obj)
+
+ def test_can_not_traverse_to_bug(self):
+ bug = self.factory.makeBugTask(target=self.factory.makeDistribution())
+ url = canonical_url(bug, rootsite='vostok')
+ self.assertRaises(NotFound, test_traverse, url)
=== removed file 'lib/lp/vostok/tests/test_navigation.py'
--- lib/lp/vostok/tests/test_navigation.py 2010-08-06 18:13:00 +0000
+++ lib/lp/vostok/tests/test_navigation.py 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for vostok's root navigation."""
-
-__metaclass__ = type
-
-from zope.publisher.interfaces import NotFound
-from zope.security.proxy import removeSecurityProxy
-
-from canonical.launchpad.webapp import urlparse
-from canonical.testing.layers import DatabaseFunctionalLayer
-
-from lp.testing import TestCaseWithFactory
-from lp.testing.publication import test_traverse
-
-
-class TestRootNavigation(TestCaseWithFactory):
-
- layer = DatabaseFunctionalLayer
-
- def test_traverse_to_distributions(self):
- # We can traverse to a distribution by name from the vostok
- # root.
- distro = self.factory.makeDistribution()
- obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
- self.assertEqual(distro, obj)
-
- def test_traverse_to_distribution_aliases(self):
- # When we traverse to a distribution using one of its aliases, we're
- # redirected to the distribution's page on the vostok vhost.
- distro = self.factory.makeDistribution(aliases=['f00'])
- obj, view, request = test_traverse('http://vostok.dev/f00')
- naked_view = removeSecurityProxy(view)
- parse_result = urlparse(naked_view.target)
- self.assertEqual('vostok.dev', parse_result.netloc)
- self.assertEqual('/' + distro.name, parse_result.path)
-
- def test_can_not_traverse_to_projects(self):
- # We cannot traverse to a project from the vostok root.
- path = self.factory.makeProject().name
- self.assertRaises(
- NotFound, test_traverse, 'http://vostok.dev/' + path)