1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for Vostok's navigation classes."""
8
from zope.publisher.interfaces import NotFound
9
from zope.security.proxy import removeSecurityProxy
11
from canonical.launchpad.webapp import canonical_url, urlparse
12
from canonical.testing.layers import DatabaseFunctionalLayer
14
from lp.testing import TestCaseWithFactory
15
from lp.testing.publication import test_traverse
18
class TestRootNavigation(TestCaseWithFactory):
20
layer = DatabaseFunctionalLayer
22
def test_traverse_to_distributions(self):
23
# We can traverse to a distribution by name from the vostok
25
distro = self.factory.makeDistribution()
26
obj, view, request = test_traverse('http://vostok.dev/' + distro.name)
27
self.assertEqual(distro, obj)
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)
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
43
NotFound, test_traverse, 'http://vostok.dev/' + path)
46
class TestDistributionNavigation(TestCaseWithFactory):
48
layer = DatabaseFunctionalLayer
50
def test_traverse_to_source_package(self):
51
# We can traverse to a source package by name from a distribution on
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)
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)
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)