Skip to content

Commit

Permalink
Corrected dash.can_access call to take context
Browse files Browse the repository at this point in the history
horizon_main_nav makes a call to dash.can_access which should take
context but was being passed the request, this patch corrects that.
Unit test added to prevent regression, and fix added to RbacHorizonTests
to clean up changes to Cats and Dogs test dashboards, as it was
affecting any test that followed.

Change-Id: I46d9880ba3ac46c23a8253a4afcf2c169d6f4dc8
Closes-Bug: 1368673
  • Loading branch information
Tehsmash committed Sep 12, 2014
1 parent 354c0c1 commit fa94e79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion horizon/templatetags/horizon.py
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions horizon/test/tests/base.py
Expand Up @@ -491,6 +491,11 @@ def tearDown(self):
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
Expand Down
22 changes: 22 additions & 0 deletions horizon/test/tests/templatetags.py
Expand Up @@ -24,6 +24,10 @@
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):
Expand Down Expand Up @@ -106,3 +110,21 @@ def test_quota_filter(self):
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))

0 comments on commit fa94e79

Please sign in to comment.