Beispiel #1
0
    def test_add_items02(self):
        "Duplicated ID."
        menu = Menu()
        id_ = 'add_contact'
        item1 = ViewableItem(id_)
        item2 = ViewableItem(id_)

        menu.add(item1)

        with self.assertRaises(ValueError):
            menu.add(item2)
Beispiel #2
0
    def test_add_items01(self):
        menu = Menu()
        item1 = ViewableItem('add_contact')
        self.assertIsNone(item1.priority)

        item2 = ViewableItem('add_orga')

        menu.add(item1).add(item2)
        self.assertListEqual([item1, item2], [*menu])

        self.assertEqual(1, item1.priority)
Beispiel #3
0
    def test_add_groups(self):
        menu = Menu()
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        item3 = ViewableItem('add_activity')

        group.add(item2).add(item3)
        menu.add(item1).add(group)
        self.assertListEqual([item1, item2, item3], [*menu])

        # Add an Item already added
        with self.assertRaises(ValueError):
            group.add(item2)
Beispiel #4
0
    def test_container_get02(self):
        menu = Menu()
        container1 = ContainerItem('creations')
        container2 = ContainerItem('editions')
        group1 = ItemGroup('add_persons')
        group2 = ItemGroup('add_tickets')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        item3 = ViewableItem('add_ticket')

        menu.add(container1.add(group1.add(item1).add(item2)).add(group2.add(item3))) \
            .add(container2)

        self.assertEqual(group1, menu.get(container1.id, group1.id))
        self.assertEqual(item1,  menu.get(container1.id, group1.id, item1.id))
        self.assertEqual(item3,  menu.get(container1.id, group2.id, item3.id))
        self.assertRaises(KeyError, menu.get, container2.id, group1.id)
        self.assertRaises(KeyError, menu.get, container1.id, group1.id, 'unknown_id')
        # 'item1' is not a container
        self.assertRaises(KeyError, menu.get, container1.id, group1.id, item1.id, 'whatever')