Example #1
0
    def test_add_menu_item(self):
        menu = Menu()
        menu.add_item('/test', 'test')
        items = menu.get_menu_items()

        self.assertEquals(len(items), 1)
        self.assertEquals(items[0].name, 'test')
Example #2
0
    def test_regex_menu_item_active(self):
        menu = Menu()
        menu.add_item('regex', 'regex', active_regex=r'/test.+/')
        item = menu.get_menu_items()[0]

        self.assertFalse(item.is_active('/test/'))
        self.assertTrue(item.is_active('/test123/'))
Example #3
0
    def test_root_menu_item_active(self):
        menu = Menu()
        menu.add_item('root', 'root', url='/')
        item = menu.get_menu_items()[0]

        self.assertTrue(item.is_active('/'))
        self.assertFalse(item.is_active('/path/'))
Example #4
0
    def test_add_sub_menu_path(self):
        menu = Menu()
        menu.add_item('/test/sub', 'sub')
        items = menu.get_menu_items()

        # Test first item
        self.assertEquals(len(items), 1)
        self.assertEquals(items[0].name, 'Test')
        self.assertEquals(items[0].path, '/test')
        self.assertEquals(len(items[0].childs), 1)

        # Test sub item
        self.assertEquals(items[0].childs[0].name, 'sub')
        self.assertEquals(items[0].childs[0].path, '/test/sub')
Example #5
0
    def test_add_menu_item_order(self):
        menu = Menu()
        menu.add_item('/first', 'first', order=10)
        menu.add_item('/third', 'third')
        menu.add_item('/second', 'second', order=20)
        items = menu.get_menu_items()

        self.assertEquals(len(items), 3)
        self.assertEquals(items[0].name, 'first')
        self.assertEquals(items[1].name, 'second')
        self.assertEquals(items[2].name, 'third')
Example #6
0
    def test_add_menu_merge(self):
        menu = Menu()
        menu.add_item('/test', 'test')
        menu.add_item('/test', 'New name', order=10)
        items = menu.get_menu_items()

        self.assertEquals(len(items), 1)
        self.assertEquals(items[0].name, 'New name')
        self.assertEquals(items[0].path, '/test')
        self.assertEquals(items[0].order, 10)
Example #7
0
    def test_menu_item_active(self):
        menu = Menu()
        menu.add_item('/item', 'item', url='/item/')
        menu.add_item('/item/subitem', 'item', url='/item/subitem/')
        item = menu.get_menu_items()[0]

        self.assertFalse(item.is_active('/'))
        self.assertFalse(item.is_active('/items/'))
        self.assertTrue(item.is_active('/item/'))
        self.assertTrue(item.is_active('/item/subitem/'))