mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
templatetags: Convert tests to pytest style
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
67539e05fc
commit
7bfa3aa3b9
@ -18,49 +18,45 @@
|
|||||||
Test module for custom Django template tags.
|
Test module for custom Django template tags.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from plinth.templatetags import plinth_extras
|
from plinth.templatetags import plinth_extras
|
||||||
|
|
||||||
|
|
||||||
class TestShowSubSubMenu(unittest.TestCase):
|
def _assert_active_url(menu, url):
|
||||||
"""Verify that the highlighting of the subsubmenu is working correctly"""
|
"""Verify that only the given url is set as 'active' in the menu"""
|
||||||
|
for item in menu:
|
||||||
|
if item['url'] == url:
|
||||||
|
assert item['active']
|
||||||
|
else:
|
||||||
|
assert not item['active']
|
||||||
|
|
||||||
def assert_active_url(self, menu, url):
|
|
||||||
"""Verify that only the given url is set as 'active' in the menu"""
|
|
||||||
for item in menu:
|
|
||||||
if item['url'] == url:
|
|
||||||
self.assertTrue(item['active'])
|
|
||||||
else:
|
|
||||||
self.assertFalse(item['active'])
|
|
||||||
|
|
||||||
@staticmethod
|
def _verify_active_menuitems(menu):
|
||||||
def _verify_active_menuitems(menu):
|
"""Verify that one and only one menuitem is marked as active"""
|
||||||
"""Verify that one and only one menuitem is marked as active"""
|
return sum([item['active'] for item in menu]) == 1
|
||||||
return sum([item['active'] for item in menu]) == 1
|
|
||||||
|
|
||||||
def test_highlighting(self):
|
|
||||||
"""Test detection of active subsubmenu items using request.path"""
|
|
||||||
menu = [{
|
|
||||||
'url': '/abc/123/abc/',
|
|
||||||
'text': 'abc'
|
|
||||||
}, {
|
|
||||||
'url': '/abc/123/',
|
|
||||||
'text': 'overview'
|
|
||||||
}, {
|
|
||||||
'url': '/abc/123/crunch/',
|
|
||||||
'text': 'crunch'
|
|
||||||
}, {
|
|
||||||
'url': '/abc/123/create/',
|
|
||||||
'text': 'create'
|
|
||||||
}]
|
|
||||||
|
|
||||||
tests = [['/abc/123/crunch/new/', '/abc/123/crunch/'], [
|
def test_highlighting():
|
||||||
'/abc/123/create/', '/abc/123/create/'
|
"""Test detection of active subsubmenu items using request.path"""
|
||||||
], ['/abc/123/nolink/', '/abc/123/'], ['/abc/123/abx/', '/abc/123/'],
|
menu = [{
|
||||||
['/abc/123/ab/', '/abc/123/'], ['/abc/123/', '/abc/123/']]
|
'url': '/abc/123/abc/',
|
||||||
|
'text': 'abc'
|
||||||
|
}, {
|
||||||
|
'url': '/abc/123/',
|
||||||
|
'text': 'overview'
|
||||||
|
}, {
|
||||||
|
'url': '/abc/123/crunch/',
|
||||||
|
'text': 'crunch'
|
||||||
|
}, {
|
||||||
|
'url': '/abc/123/create/',
|
||||||
|
'text': 'create'
|
||||||
|
}]
|
||||||
|
|
||||||
for check_path, expected_active_path in tests:
|
tests = [['/abc/123/crunch/new/', '/abc/123/crunch/'], [
|
||||||
menu = plinth_extras.mark_active_menuitem(menu, check_path)
|
'/abc/123/create/', '/abc/123/create/'
|
||||||
self.assert_active_url(menu, expected_active_path)
|
], ['/abc/123/nolink/', '/abc/123/'], ['/abc/123/abx/', '/abc/123/'],
|
||||||
self.assertTrue(self._verify_active_menuitems(menu))
|
['/abc/123/ab/', '/abc/123/'], ['/abc/123/', '/abc/123/']]
|
||||||
|
|
||||||
|
for check_path, expected_active_path in tests:
|
||||||
|
menu = plinth_extras.mark_active_menuitem(menu, check_path)
|
||||||
|
_assert_active_url(menu, expected_active_path)
|
||||||
|
assert _verify_active_menuitems(menu)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user