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 browsing the root of the vostok skin."""
10
from zope.publisher.defaultview import getDefaultViewName
12
from canonical.launchpad.testing.pages import (
16
from lp.app.browser.tales import IMainTemplateFile
17
from canonical.testing.layers import (
18
DatabaseFunctionalLayer,
21
from lp.testing import (
25
from lp.testing.views import create_initialized_view
26
from lp.vostok.browser.root import VostokRootView
27
from lp.vostok.browser.tests.request import VostokTestRequest
28
from lp.vostok.publisher import (
34
class TestRootRegistrations(TestCase):
35
"""Test the registration of views for `VostokRoot`."""
37
layer = FunctionalLayer
39
def test_root_default_view_name(self):
40
# The default view for the vostok root object is called "+index".
41
view_name = getDefaultViewName(VostokRoot(), VostokTestRequest())
42
self.assertEquals('+index', view_name)
44
def test_root_index_view(self):
45
# VostokRootView is registered as the view for the VostokRoot object.
46
view = create_initialized_view(
47
VostokRoot(), name='+index', layer=VostokLayer)
48
self.assertIsInstance(view, VostokRootView)
51
class TestRootView(TestCaseWithFactory):
52
"""Tests for `VostokRootView`."""
54
layer = DatabaseFunctionalLayer
57
return create_initialized_view(
58
VostokRoot(), name='+index', layer=VostokLayer)
60
def test_distributions(self):
61
# VostokRootView.distributions is an iterable of all registered
63
root_view = self.view()
64
new_distro = self.factory.makeDistribution()
65
self.assertIn(new_distro, list(root_view.distributions))
68
class TestRootTemplate(TestCaseWithFactory):
69
"""Tests for the templates used by views of `VostokRoot`."""
71
layer = DatabaseFunctionalLayer
73
def test_distribution_list(self):
74
# The element with id 'distro-list' on the root page contains a list
75
# of links to all registered distributions.
76
v = create_initialized_view(
77
VostokRoot(), name='+index', layer=VostokLayer)
79
link_list = find_tag_by_id(contents, 'distro-list')('a')
80
distro_list = list(v.distributions)
81
self.assertEqual(len(link_list), len(distro_list))
82
for distro, link in zip(distro_list, link_list):
83
self.assertEqual(distro.displayname, extract_text(link))
86
class TestVostokLayerToMainTemplateAdapter(TestCase):
88
layer = FunctionalLayer
91
main_template_path = IMainTemplateFile(VostokTestRequest()).path
92
self.assertIn('lp/vostok', main_template_path)
93
self.assertTrue(os.path.isfile(main_template_path))