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
1=== modified file 'lib/lp/testing/factory.py'
2--- lib/lp/testing/factory.py 2010-08-12 19:47:01 +0000
3+++ lib/lp/testing/factory.py 2010-08-13 15:43:19 +0000
4@@ -1221,7 +1221,7 @@
5 # We can't have a series task without a distribution task.
6 self.makeBugTask(bug, distribution_package)
7
8- return bug.addTask(owner, target)
9+ return removeSecurityProxy(bug).addTask(owner, target)
10
11 def makeBugTracker(self, base_url=None, bugtrackertype=None):
12 """Make a new bug tracker."""
13
14=== modified file 'lib/lp/vostok/browser/configure.zcml'
15--- lib/lp/vostok/browser/configure.zcml 2010-08-10 20:59:34 +0000
16+++ lib/lp/vostok/browser/configure.zcml 2010-08-13 15:43:19 +0000
17@@ -6,18 +6,23 @@
18 i18n_domain="launchpad">
19
20 <browser:defaultView
21- for="lp.vostok.publisher.IVostokRoot"
22- name="+index"
23- />
24+ for="..publisher.IVostokRoot"
25+ name="+index"
26+ />
27
28 <browser:page
29- for="lp.vostok.publisher.IVostokRoot"
30- name="+index"
31- class="lp.vostok.browser.root.VostokRootView"
32- template="../templates/root.pt"
33- permission="zope.Public"
34- layer="lp.vostok.publisher.VostokLayer"
35- />
36+ for="..publisher.IVostokRoot"
37+ name="+index"
38+ class=".root.VostokRootView"
39+ template="../templates/root.pt"
40+ permission="zope.Public"
41+ layer="..publisher.VostokLayer"
42+ />
43+
44+ <browser:navigation
45+ module=".distribution"
46+ classes="DistributionNavigation"
47+ layer="..publisher.VostokLayer" />
48
49 <browser:navigation
50 module="lp.vostok.publisher"
51
52=== added file 'lib/lp/vostok/browser/distribution.py'
53--- lib/lp/vostok/browser/distribution.py 1970-01-01 00:00:00 +0000
54+++ lib/lp/vostok/browser/distribution.py 2010-08-13 15:43:19 +0000
55@@ -0,0 +1,24 @@
56+# Copyright 2010 Canonical Ltd. This software is licensed under the
57+# GNU Affero General Public License version 3 (see the file LICENSE).
58+
59+"""Browser views for distributions."""
60+
61+__metaclass__ = type
62+
63+__all__ = [
64+ 'DistributionNavigation',
65+ ]
66+
67+from canonical.launchpad.webapp import GetitemNavigation, stepthrough
68+
69+from lp.registry.interfaces.distribution import IDistribution
70+
71+
72+class DistributionNavigation(GetitemNavigation):
73+
74+ usedfor = IDistribution
75+
76+ @stepthrough('+source')
77+ def traverse_sources(self, name):
78+ return self.context.getSourcePackage(name)
79+
80
81=== added file 'lib/lp/vostok/browser/tests/test_navigation.py'
82--- lib/lp/vostok/browser/tests/test_navigation.py 1970-01-01 00:00:00 +0000
83+++ lib/lp/vostok/browser/tests/test_navigation.py 2010-08-13 15:43:19 +0000
84@@ -0,0 +1,67 @@
85+# Copyright 2010 Canonical Ltd. This software is licensed under the
86+# GNU Affero General Public License version 3 (see the file LICENSE).
87+
88+"""Tests for Vostok's navigation classes."""
89+
90+__metaclass__ = type
91+
92+from zope.publisher.interfaces import NotFound
93+from zope.security.proxy import removeSecurityProxy
94+
95+from canonical.launchpad.webapp import canonical_url, urlparse
96+from canonical.testing.layers import DatabaseFunctionalLayer
97+
98+from lp.testing import TestCaseWithFactory
99+from lp.testing.publication import test_traverse
100+
101+
102+class TestRootNavigation(TestCaseWithFactory):
103+
104+ layer = DatabaseFunctionalLayer
105+
106+ def test_traverse_to_distributions(self):
107+ # We can traverse to a distribution by name from the vostok
108+ # root.
109+ distro = self.factory.makeDistribution()
110+ obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
111+ self.assertEqual(distro, obj)
112+
113+ def test_traverse_to_distribution_aliases(self):
114+ # When we traverse to a distribution using one of its aliases, we're
115+ # redirected to the distribution's page on the vostok vhost.
116+ distro = self.factory.makeDistribution(aliases=['f00'])
117+ obj, view, request = test_traverse('http://vostok.dev/f00')
118+ naked_view = removeSecurityProxy(view)
119+ parse_result = urlparse(naked_view.target)
120+ self.assertEqual('vostok.dev', parse_result.netloc)
121+ self.assertEqual('/' + distro.name, parse_result.path)
122+
123+ def test_can_not_traverse_to_projects(self):
124+ # We cannot traverse to a project from the vostok root.
125+ path = self.factory.makeProject().name
126+ self.assertRaises(
127+ NotFound, test_traverse, 'http://vostok.dev/' + path)
128+
129+
130+class TestDistributionNavigation(TestCaseWithFactory):
131+
132+ layer = DatabaseFunctionalLayer
133+
134+ def test_traverse_to_source_package(self):
135+ # We can traverse to a source package by name from a distribution on
136+ # the vostok vhost.
137+ source_package = self.factory.makeDistributionSourcePackage()
138+ obj, view, request = test_traverse(
139+ canonical_url(source_package, rootsite='vostok'))
140+ self.assertEqual(source_package, obj)
141+
142+ def test_traverse_to_distroseries(self):
143+ distroseries = self.factory.makeDistroSeries()
144+ obj, view, request = test_traverse(
145+ canonical_url(distroseries, rootsite='vostok'))
146+ self.assertEqual(distroseries, obj)
147+
148+ def test_can_not_traverse_to_bug(self):
149+ bug = self.factory.makeBugTask(target=self.factory.makeDistribution())
150+ url = canonical_url(bug, rootsite='vostok')
151+ self.assertRaises(NotFound, test_traverse, url)
152
153=== removed file 'lib/lp/vostok/tests/test_navigation.py'
154--- lib/lp/vostok/tests/test_navigation.py 2010-08-06 18:13:00 +0000
155+++ lib/lp/vostok/tests/test_navigation.py 1970-01-01 00:00:00 +0000
156@@ -1,43 +0,0 @@
157-# Copyright 2010 Canonical Ltd. This software is licensed under the
158-# GNU Affero General Public License version 3 (see the file LICENSE).
159-
160-"""Tests for vostok's root navigation."""
161-
162-__metaclass__ = type
163-
164-from zope.publisher.interfaces import NotFound
165-from zope.security.proxy import removeSecurityProxy
166-
167-from canonical.launchpad.webapp import urlparse
168-from canonical.testing.layers import DatabaseFunctionalLayer
169-
170-from lp.testing import TestCaseWithFactory
171-from lp.testing.publication import test_traverse
172-
173-
174-class TestRootNavigation(TestCaseWithFactory):
175-
176- layer = DatabaseFunctionalLayer
177-
178- def test_traverse_to_distributions(self):
179- # We can traverse to a distribution by name from the vostok
180- # root.
181- distro = self.factory.makeDistribution()
182- obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
183- self.assertEqual(distro, obj)
184-
185- def test_traverse_to_distribution_aliases(self):
186- # When we traverse to a distribution using one of its aliases, we're
187- # redirected to the distribution's page on the vostok vhost.
188- distro = self.factory.makeDistribution(aliases=['f00'])
189- obj, view, request = test_traverse('http://vostok.dev/f00')
190- naked_view = removeSecurityProxy(view)
191- parse_result = urlparse(naked_view.target)
192- self.assertEqual('vostok.dev', parse_result.netloc)
193- self.assertEqual('/' + distro.name, parse_result.path)
194-
195- def test_can_not_traverse_to_projects(self):
196- # We cannot traverse to a project from the vostok root.
197- path = self.factory.makeProject().name
198- self.assertRaises(
199- NotFound, test_traverse, 'http://vostok.dev/' + path)