~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/vostok/browser/tests/test_navigation.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-08-16 20:07:06 UTC
  • mfrom: (7675.782.4 vostok-traverse-package)
  • Revision ID: launchpad@pqm.canonical.com-20100816200706-40pwtx4y737bdsm7
[r=leonardr][ui=none][no-qa] 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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
8
from zope.publisher.interfaces import NotFound
 
9
from zope.security.proxy import removeSecurityProxy
 
10
 
 
11
from canonical.launchpad.webapp import canonical_url, urlparse
 
12
from canonical.testing.layers import DatabaseFunctionalLayer
 
13
 
 
14
from lp.testing import TestCaseWithFactory
 
15
from lp.testing.publication import test_traverse
 
16
 
 
17
 
 
18
class 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
 
 
46
class 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)