test(api): API Metadata test cases for navigation menu rendering
ref: #412 #415
This commit is contained in:
@ -489,7 +489,6 @@ class MetadataAttributesFunctional:
|
||||
assert type(response.data['urls']['self']) is str
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason='to be written')
|
||||
def test_method_options_no_field_is_generic(self):
|
||||
"""Test HTTP/Options Method
|
||||
@ -500,3 +499,359 @@ class MetadataAttributesFunctional:
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class MetaDataNavigationEntriesFunctional:
|
||||
""" Test cases for the Navigation menu
|
||||
|
||||
Navigation menu is rendered as part of the API when a HTTP/OPTIONS
|
||||
request has been made. Each menu entry requires that a user has View
|
||||
permissions for that entry to be visible.
|
||||
|
||||
**No** menu entry is to be returned for **any** user whom does not
|
||||
have the corresponding view permission.
|
||||
|
||||
These test cases are for any model that has a navigation menu entry.
|
||||
|
||||
## Tests
|
||||
|
||||
- Ensure add user does not have menu entry
|
||||
- Ensure change user does not have menu entry
|
||||
- Ensure delete user does not have menu entry
|
||||
- Ensure the view user has menu entry
|
||||
- No menu to return without pages for add user
|
||||
- No menu to return without pages for change user
|
||||
- No menu to return without pages for delete user
|
||||
- No menu to return without pages for view user
|
||||
"""
|
||||
|
||||
menu_id: str = None
|
||||
""" Name of the Menu entry
|
||||
|
||||
Match for .navigation[i][name]
|
||||
"""
|
||||
|
||||
menu_entry_id: str = None
|
||||
"""Name of the menu entry
|
||||
|
||||
Match for .navigation[i][pages][i][name]
|
||||
"""
|
||||
|
||||
app_namespace:str = None
|
||||
"""application namespace"""
|
||||
|
||||
url_name: str = None
|
||||
"""url name"""
|
||||
|
||||
url_kwargs: dict = None
|
||||
"""View URL kwargs"""
|
||||
|
||||
add_user = None
|
||||
""" User with add permission"""
|
||||
|
||||
change_user = None
|
||||
""" User with change permission"""
|
||||
|
||||
delete_user = None
|
||||
""" User with delete permission"""
|
||||
|
||||
view_user = None
|
||||
""" User with view permission"""
|
||||
|
||||
|
||||
|
||||
def test_navigation_entry_add_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with add permission, does not
|
||||
have the menu entry within navigation
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.add_user)
|
||||
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_menu_entry_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if nav_menu['name'] == self.menu_id:
|
||||
|
||||
for menu_entry in nav_menu['pages']:
|
||||
|
||||
if menu_entry['name'] == self.menu_entry_id:
|
||||
|
||||
no_menu_entry_found = False
|
||||
|
||||
assert no_menu_entry_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_no_empty_menu_add_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with add permission, does not
|
||||
have any nave menu without pages
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.add_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_empty_menu_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if len(nav_menu['pages']) == 0:
|
||||
|
||||
no_empty_menu_found = False
|
||||
|
||||
assert no_empty_menu_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_entry_change_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with change permission, does not
|
||||
have the menu entry within navigation
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.change_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_menu_entry_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if nav_menu['name'] == self.menu_id:
|
||||
|
||||
for menu_entry in nav_menu['pages']:
|
||||
|
||||
if menu_entry['name'] == self.menu_entry_id:
|
||||
|
||||
no_menu_entry_found = False
|
||||
|
||||
assert no_menu_entry_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_no_empty_menu_change_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with change permission, does not
|
||||
have any nave menu without pages
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.change_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_empty_menu_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if len(nav_menu['pages']) == 0:
|
||||
|
||||
no_empty_menu_found = False
|
||||
|
||||
assert no_empty_menu_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_entry_delete_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with delete permission, does not
|
||||
have the menu entry within navigation
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.delete_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_menu_entry_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if nav_menu['name'] == self.menu_id:
|
||||
|
||||
for menu_entry in nav_menu['pages']:
|
||||
|
||||
if menu_entry['name'] == self.menu_entry_id:
|
||||
|
||||
no_menu_entry_found = False
|
||||
|
||||
assert no_menu_entry_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_no_empty_menu_delete_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with delete permission, does not
|
||||
have any nave menu without pages
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.delete_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_empty_menu_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if len(nav_menu['pages']) == 0:
|
||||
|
||||
no_empty_menu_found = False
|
||||
|
||||
assert no_empty_menu_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_entry_view_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with view permission,
|
||||
has the menu entry within navigation
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.view_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
menu_entry_found: bool = False
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if nav_menu['name'] == self.menu_id:
|
||||
|
||||
for menu_entry in nav_menu['pages']:
|
||||
|
||||
if menu_entry['name'] == self.menu_entry_id:
|
||||
|
||||
menu_entry_found = True
|
||||
|
||||
assert menu_entry_found
|
||||
|
||||
|
||||
|
||||
def test_navigation_no_empty_menu_view_user(self):
|
||||
"""Test HTTP/Options Method Navigation Entry
|
||||
|
||||
Ensure that a user with view permission, does not
|
||||
have any nave menu without pages
|
||||
"""
|
||||
|
||||
client = Client()
|
||||
client.force_login(self.view_user)
|
||||
|
||||
if getattr(self, 'url_kwargs', None):
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list', kwargs = self.url_kwargs)
|
||||
|
||||
else:
|
||||
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-list')
|
||||
|
||||
response = client.options(
|
||||
url,
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
no_empty_menu_found: bool = True
|
||||
|
||||
for nav_menu in response.data['navigation']:
|
||||
|
||||
if len(nav_menu['pages']) == 0:
|
||||
|
||||
no_empty_menu_found = False
|
||||
|
||||
assert no_empty_menu_found
|
||||
|
@ -40,6 +40,10 @@ Views are used with Centurion ERP to Fetch the data for rendering.
|
||||
|
||||
- _Functional test cases_ `from api.tests.abstract.api_permissions_viewset import APIPermission`
|
||||
|
||||
- _Functional test cases_ (Only required if model has an API endpoint)_`from api.tests.abstract.test_metadata_functional import MetadataAttributesFunctional`
|
||||
|
||||
- _Functional test cases_ _(Only required if model has nav menu entry)_`from api.tests.abstract.test_metadata_functional import MetaDataNavigationEntriesFunctional`
|
||||
|
||||
- View Added to Navigation
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user