Skip to content

Commit

Permalink
[feature] Added menu items #37
Browse files Browse the repository at this point in the history
Added menu items (openwisp-utils menu) for Subnet and IpAdress models.
Added test for menu items in test_admin.py
Also updated openwisp-utils and openwisp-users dependency in requirements files.

Closes #37
  • Loading branch information
codesankalp committed Dec 30, 2020
1 parent 921be06 commit b130a44
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
13 changes: 10 additions & 3 deletions openwisp_ipam/apps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.apps import AppConfig
from openwisp_utils.api.apps import ApiAppConfig
from openwisp_utils.utils import register_menu_items
from swapper import get_model_name

from .compat import patch_ipaddress_lib


class OpenWispIpamConfig(AppConfig):
class OpenWispIpamConfig(ApiAppConfig):
name = 'openwisp_ipam'
verbose_name = 'IPAM'

def ready(self):
def ready(self, *args, **kwargs):
patch_ipaddress_lib()
items = [
{'model': get_model_name('openwisp_ipam', 'Subnet')},
{'model': get_model_name('openwisp_ipam', 'IpAddress')},
]
register_menu_items(items, name_menu='OPENWISP_DEFAULT_ADMIN_MENU_ITEMS')
18 changes: 18 additions & 0 deletions openwisp_ipam/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,21 @@ def test_operator_group_permission(self):
perms = list(operator.permissions.values_list('codename', flat=True))
for p in operator_permissions:
self.assertIn(p, perms)

def test_admin_menu_items(self):
# Test menu items (openwisp-utils menu) for Subnet and IpAddress models
response = self.client.get(reverse('admin:index'))
self.assertContains(
response,
'<a href="{}" class="subnet">subnets</a>'.format(
reverse(f'admin:{self.app_label}_subnet_changelist')
),
html=True,
)
self.assertContains(
response,
'<a href="{}" class="ipaddress">ip addresss</a>'.format(
reverse(f'admin:{self.app_label}_ipaddress_changelist')
),
html=True,
)
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
coveralls
django-extensions>=2.0.7
openwisp-utils[qa]~=0.6.0
openwisp-utils[qa]~=0.7.2
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
openwisp-users~=0.4.1
openwisp-utils[rest]~=0.6.0
openwisp-users~=0.5.1
openwisp-utils[rest]~=0.7.2
django>=2.2,<3.2
swapper~=1.1
xlrd~=1.1
Expand Down
1 change: 1 addition & 0 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'openwisp_utils.admin_theme.context_processor.menu_items',
],
},
},
Expand Down

0 comments on commit b130a44

Please sign in to comment.