Merge "Corrected dash.can_access call to take context"

This commit is contained in:
Jenkins 2014-09-15 12:38:08 +00:00 committed by Gerrit Code Review
commit 9041432629
3 changed files with 28 additions and 1 deletions

View File

@ -82,7 +82,7 @@ def horizon_main_nav(context):
current_dashboard = context['request'].horizon.get('dashboard', None)
dashboards = []
for dash in Horizon.get_dashboards():
if dash.can_access(context['request']):
if dash.can_access(context):
if callable(dash.nav) and dash.nav(context):
dashboards.append(dash)
elif dash.nav:

View File

@ -491,6 +491,11 @@ class RbacHorizonTests(test.TestCase):
base.Horizon = base.HorizonSite()
# Reload the convenience references to Horizon stored in __init__
reload(import_module("horizon"))
# Reset Cats and Dogs default_panel to default values
Cats.default_panel = 'kittens'
Dogs.default_panel = 'puppies'
# Re-register our original dashboards and panels.
# This is necessary because autodiscovery only works on the first
# import, and calling reload introduces innumerable additional

View File

@ -24,6 +24,10 @@ from django.template import Template # noqa
from django.utils.text import normalize_newlines # noqa
from horizon.test import helpers as test
from horizon.test.test_dashboards.cats.dashboard import Cats # noqa
from horizon.test.test_dashboards.cats.kittens.panel import Kittens # noqa
from horizon.test.test_dashboards.dogs.dashboard import Dogs # noqa
from horizon.test.test_dashboards.dogs.puppies.panel import Puppies # noqa
def single_line(text):
@ -106,3 +110,21 @@ class TemplateTagTests(test.TestCase):
template_text=text,
context={'test': ctx_string})
self.assertEqual(expected, rendered_str)
def test_horizon_main_nav(self):
text = "{% horizon_main_nav %}"
expected = """
<div class='clearfix'>
<ul class=\"nav nav-tabs\">
<li>
<a href=\"/cats/\" tabindex='1'>Cats</a>
</li>
<li>
<a href=\"/dogs/\" tabindex='1'>Dogs</a>
</li>
</ul></div>"""
rendered_str = self.render_template(tag_require='horizon',
template_text=text,
context={'request': self.request})
self.assertEqual(single_line(rendered_str), single_line(expected))