46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import unittest
|
|
from random import shuffle
|
|
|
|
from raven.plugins.domain.menucontribution import MenuContribution, sort_menu_contributions
|
|
|
|
|
|
class MyTestCase(unittest.TestCase):
|
|
def test_sort(self):
|
|
items = [
|
|
MenuContribution("menuId", action_id="a", after=None),
|
|
MenuContribution("menuId", action_id="b", after="a"),
|
|
MenuContribution("menuId", action_id="c", after="a"),
|
|
MenuContribution("menuId", action_id="d", after="b"),
|
|
MenuContribution("menuId", action_id="e", after="d"),
|
|
]
|
|
shuffle(items)
|
|
|
|
actual = sort_menu_contributions(items)
|
|
ordered_ids = ""
|
|
for a in actual:
|
|
ordered_ids = ordered_ids + a.action_id
|
|
self.assertEqual("abcde", ordered_ids)
|
|
|
|
def test_sort_with_cycle(self):
|
|
"""
|
|
There is a cycle between a and b. This is resolved, because neither is set in the recursive
|
|
part of the method. After the recursive part the remaining items are added in order of
|
|
their action_id.
|
|
:return:
|
|
"""
|
|
items = [
|
|
MenuContribution("menuId", action_id="a", after="b"),
|
|
MenuContribution("menuId", action_id="b", after="a"),
|
|
]
|
|
shuffle(items)
|
|
|
|
actual = sort_menu_contributions(items)
|
|
ordered_ids = ""
|
|
for a in actual:
|
|
ordered_ids = ordered_ids + a.action_id
|
|
self.assertEqual("ab", ordered_ids)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|