Skip to content

Commit

Permalink
Add test for plugin menu registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Sep 28, 2022
1 parent d046524 commit 3fbd514
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion netbox/extras/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def register_template_extensions(class_list):
#

class PluginMenu:
icon_class = 'mdi-puzzle'
icon_class = 'mdi mdi-puzzle'

def __init__(self, label, groups, icon_class=None):
self.label = label
Expand Down
10 changes: 8 additions & 2 deletions netbox/extras/tests/dummy_plugin/navigation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from extras.plugins import PluginMenuButton, PluginMenuItem
from extras.plugins import PluginMenu, PluginMenuButton, PluginMenuItem


menu_items = (
items = (
PluginMenuItem(
link='plugins:dummy_plugin:dummy_models',
link_text='Item 1',
Expand All @@ -23,3 +23,9 @@
link_text='Item 2',
),
)

menu = PluginMenu(
label='Dummy',
groups=(('Group 1', items),),
)
menu_items = items
11 changes: 10 additions & 1 deletion netbox/extras/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.test import Client, TestCase, override_settings
from django.urls import reverse

from extras.plugins import PluginMenu
from extras.registry import registry
from extras.tests.dummy_plugin import config as dummy_config
from netbox.graphql.schema import Query
Expand Down Expand Up @@ -58,9 +59,17 @@ def test_api_views(self):
response = client.get(url)
self.assertEqual(response.status_code, 200)

def test_menu(self):
"""
Check menu registration.
"""
menu = registry['plugins']['menus'][0]
self.assertIsInstance(menu, PluginMenu)
self.assertEqual(menu.label, 'Dummy')

def test_menu_items(self):
"""
Check that plugin MenuItems and MenuButtons are registered.
Check menu_items registration.
"""
self.assertIn('Dummy plugin', registry['plugins']['menu_items'])
menu_items = registry['plugins']['menu_items']['Dummy plugin']
Expand Down

0 comments on commit 3fbd514

Please sign in to comment.