Skip to content

Commit

Permalink
adds additional unit tests to the menu items for user
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Oct 4, 2018
1 parent 9fccd5f commit 5226543
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
4 changes: 2 additions & 2 deletions opal/core/plugins.py
Expand Up @@ -64,5 +64,5 @@ def get_javascripts(klass):
return [j for j in klass.javascripts]

@classmethod
def get_menu_items(self, user=None):
return [i for i in self.menuitems if i.for_user(user)]
def get_menu_items(cls, user=None):
return [i for i in cls.menuitems if i.for_user(user)]
23 changes: 22 additions & 1 deletion opal/tests/test_core_application.py
Expand Up @@ -65,7 +65,28 @@ def test_get_javascripts_updating_side_effects(self):
def test_get_menu_items(self):
self.assertEqual(
application.OpalApplication.menuitems,
application.OpalApplication.get_menu_items())
application.OpalApplication.get_menu_items()
)

def test_get_menu_items_for_user(self):
class MenuItemIncluded(menus.MenuItem):
pass

class MenuItemNotIncluded(menus.MenuItem):
def for_user(self, user):
return False

menu_item_included = MenuItemIncluded()
menu_item_not_included = MenuItemNotIncluded()

self.app.menuitems = [
menu_item_included, menu_item_not_included
]

self.assertEqual(
[menu_item_included],
list(self.app.get_menu_items())
)

def test_get_menu_items_includes_logout_for_authenticated_users(self):
user = self.user
Expand Down
24 changes: 23 additions & 1 deletion opal/tests/test_core_plugins.py
Expand Up @@ -8,6 +8,7 @@

from opal.core.test import OpalTestCase
from opal.core import menus
from opal.utils import AbstractBase

from opal.core import plugins

Expand All @@ -18,7 +19,7 @@ class TestPlugin1(plugins.OpalPlugin):
javascripts = ['js/test/notreal.js']
stylesheets = ['css/test/notreal.css']
head_extra = ['notareal_template.html']
menuitems = [ menus.MenuItem(display='test') ]
menuitems = [menus.MenuItem(display='test') ]
angular_module_deps = ['js/test.angular.mod.js']

class TestPlugin2(plugins.OpalPlugin):
Expand Down Expand Up @@ -74,3 +75,24 @@ def test_get_javascripts_side_effects(self):
js_orig = copy.copy(js)
js.append('icanhazcheezburgerify.js')
self.assertEqual(js_orig, self.plugin1.get_javascripts())

def test_get_menu_items(self):
class MenuItemIncluded(menus.MenuItem):
pass

class MenuItemNotIncluded(menus.MenuItem):
def for_user(self, user):
return False

menu_item_included = MenuItemIncluded()
menu_item_not_included = MenuItemNotIncluded()

class TestPlugin(plugins.OpalPlugin, AbstractBase):
menuitems = [
menu_item_included, menu_item_not_included
]

self.assertEqual(
[menu_item_included],
list(TestPlugin.get_menu_items())
)

0 comments on commit 5226543

Please sign in to comment.