Merge lp:~salgado/launchpad/vostok-traverse-package into lp:launchpad

Proposed by Guilherme Salgado
Status: Merged
Approved by: Leonard Richardson
Approved revision: no longer in the source branch.
Merged at revision: 11355
Proposed branch: lp:~salgado/launchpad/vostok-traverse-package
Merge into: lp:launchpad
Prerequisite: lp:~salgado/launchpad/layer-specific-navigation
Diff against target: 199 lines (+107/-54)
5 files modified
lib/lp/testing/factory.py (+1/-1)
lib/lp/vostok/browser/configure.zcml (+15/-10)
lib/lp/vostok/browser/distribution.py (+24/-0)
lib/lp/vostok/browser/tests/test_navigation.py (+67/-0)
lib/lp/vostok/tests/test_navigation.py (+0/-43)
To merge this branch: bzr merge lp:~salgado/launchpad/vostok-traverse-package
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+32599@code.launchpad.net

Commit message

Add a custom navigation for IDistribution on the vostok layer so that it's possible to traverse only to distro series and source packages on the vostok.dev vhost.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:43:19 +0000
@@ -1221,7 +1221,7 @@
1221 # We can't have a series task without a distribution task.1221 # We can't have a series task without a distribution task.
1222 self.makeBugTask(bug, distribution_package)1222 self.makeBugTask(bug, distribution_package)
12231223
1224 return bug.addTask(owner, target)1224 return removeSecurityProxy(bug).addTask(owner, target)
12251225
1226 def makeBugTracker(self, base_url=None, bugtrackertype=None):1226 def makeBugTracker(self, base_url=None, bugtrackertype=None):
1227 """Make a new bug tracker."""1227 """Make a new bug tracker."""
12281228
=== 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:43:19 +0000
@@ -6,18 +6,23 @@
6 i18n_domain="launchpad">6 i18n_domain="launchpad">
77
8 <browser:defaultView8 <browser:defaultView
9 for="lp.vostok.publisher.IVostokRoot"9 for="..publisher.IVostokRoot"
10 name="+index"10 name="+index"
11 />11 />
1212
13 <browser:page13 <browser:page
14 for="lp.vostok.publisher.IVostokRoot"14 for="..publisher.IVostokRoot"
15 name="+index"15 name="+index"
16 class="lp.vostok.browser.root.VostokRootView"16 class=".root.VostokRootView"
17 template="../templates/root.pt"17 template="../templates/root.pt"
18 permission="zope.Public"18 permission="zope.Public"
19 layer="lp.vostok.publisher.VostokLayer"19 layer="..publisher.VostokLayer"
20 />20 />
21
22 <browser:navigation
23 module=".distribution"
24 classes="DistributionNavigation"
25 layer="..publisher.VostokLayer" />
2126
22 <browser:navigation27 <browser:navigation
23 module="lp.vostok.publisher"28 module="lp.vostok.publisher"
2429
=== 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:43:19 +0000
@@ -0,0 +1,24 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Browser views for distributions."""
5
6__metaclass__ = type
7
8__all__ = [
9 'DistributionNavigation',
10 ]
11
12from canonical.launchpad.webapp import GetitemNavigation, stepthrough
13
14from lp.registry.interfaces.distribution import IDistribution
15
16
17class DistributionNavigation(GetitemNavigation):
18
19 usedfor = IDistribution
20
21 @stepthrough('+source')
22 def traverse_sources(self, name):
23 return self.context.getSourcePackage(name)
24
025
=== 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:43:19 +0000
@@ -0,0 +1,67 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for Vostok's navigation classes."""
5
6__metaclass__ = type
7
8from zope.publisher.interfaces import NotFound
9from zope.security.proxy import removeSecurityProxy
10
11from canonical.launchpad.webapp import canonical_url, urlparse
12from canonical.testing.layers import DatabaseFunctionalLayer
13
14from lp.testing import TestCaseWithFactory
15from lp.testing.publication import test_traverse
16
17
18class TestRootNavigation(TestCaseWithFactory):
19
20 layer = DatabaseFunctionalLayer
21
22 def test_traverse_to_distributions(self):
23 # We can traverse to a distribution by name from the vostok
24 # root.
25 distro = self.factory.makeDistribution()
26 obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
27 self.assertEqual(distro, obj)
28
29 def test_traverse_to_distribution_aliases(self):
30 # When we traverse to a distribution using one of its aliases, we're
31 # redirected to the distribution's page on the vostok vhost.
32 distro = self.factory.makeDistribution(aliases=['f00'])
33 obj, view, request = test_traverse('http://vostok.dev/f00')
34 naked_view = removeSecurityProxy(view)
35 parse_result = urlparse(naked_view.target)
36 self.assertEqual('vostok.dev', parse_result.netloc)
37 self.assertEqual('/' + distro.name, parse_result.path)
38
39 def test_can_not_traverse_to_projects(self):
40 # We cannot traverse to a project from the vostok root.
41 path = self.factory.makeProject().name
42 self.assertRaises(
43 NotFound, test_traverse, 'http://vostok.dev/' + path)
44
45
46class TestDistributionNavigation(TestCaseWithFactory):
47
48 layer = DatabaseFunctionalLayer
49
50 def test_traverse_to_source_package(self):
51 # We can traverse to a source package by name from a distribution on
52 # the vostok vhost.
53 source_package = self.factory.makeDistributionSourcePackage()
54 obj, view, request = test_traverse(
55 canonical_url(source_package, rootsite='vostok'))
56 self.assertEqual(source_package, obj)
57
58 def test_traverse_to_distroseries(self):
59 distroseries = self.factory.makeDistroSeries()
60 obj, view, request = test_traverse(
61 canonical_url(distroseries, rootsite='vostok'))
62 self.assertEqual(distroseries, obj)
63
64 def test_can_not_traverse_to_bug(self):
65 bug = self.factory.makeBugTask(target=self.factory.makeDistribution())
66 url = canonical_url(bug, rootsite='vostok')
67 self.assertRaises(NotFound, test_traverse, url)
068
=== 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 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for vostok's root navigation."""
5
6__metaclass__ = type
7
8from zope.publisher.interfaces import NotFound
9from zope.security.proxy import removeSecurityProxy
10
11from canonical.launchpad.webapp import urlparse
12from canonical.testing.layers import DatabaseFunctionalLayer
13
14from lp.testing import TestCaseWithFactory
15from lp.testing.publication import test_traverse
16
17
18class TestRootNavigation(TestCaseWithFactory):
19
20 layer = DatabaseFunctionalLayer
21
22 def test_traverse_to_distributions(self):
23 # We can traverse to a distribution by name from the vostok
24 # root.
25 distro = self.factory.makeDistribution()
26 obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
27 self.assertEqual(distro, obj)
28
29 def test_traverse_to_distribution_aliases(self):
30 # When we traverse to a distribution using one of its aliases, we're
31 # redirected to the distribution's page on the vostok vhost.
32 distro = self.factory.makeDistribution(aliases=['f00'])
33 obj, view, request = test_traverse('http://vostok.dev/f00')
34 naked_view = removeSecurityProxy(view)
35 parse_result = urlparse(naked_view.target)
36 self.assertEqual('vostok.dev', parse_result.netloc)
37 self.assertEqual('/' + distro.name, parse_result.path)
38
39 def test_can_not_traverse_to_projects(self):
40 # We cannot traverse to a project from the vostok root.
41 path = self.factory.makeProject().name
42 self.assertRaises(
43 NotFound, test_traverse, 'http://vostok.dev/' + path)