Ejemplo n.º 1
0
    def test_item_label(self):
        self.assertEqual('',
                         ViewableItem('add_contact').label)  # TODO: None ??

        my_label = 'Add a contact'
        self.assertEqual(my_label,
                         ViewableItem('add_contact', label=my_label).label)
Ejemplo n.º 2
0
    def test_add_items_to_group03(self):
        "Several items at once"
        group = ItemGroup('persons')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')

        group.add(item2, item1)
        self.assertListEqual([item2, item1], [*group])
Ejemplo n.º 3
0
    def test_container_get01(self):
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        group.add(item1).add(item2)

        self.assertEqual(item1, group.get(item1.id))
        self.assertEqual(item2, group.get(item2.id))
        self.assertRaises(KeyError, group.get, 'unknown_id')
Ejemplo n.º 4
0
    def test_add_items_to_group04(self):
        "First has priority"
        group = ItemGroup('persons')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')

        group.add(item1, priority=10)
        group.add(item2, priority=1)
        self.assertListEqual([item2, item1], [*group])
Ejemplo n.º 5
0
    def test_add_items_to_group01(self):
        group = ItemGroup('persons')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')

        group.add(item1)
        group.add(item2)

        self.assertListEqual([item1, item2], [*group])
Ejemplo n.º 6
0
    def test_change_priority_group(self):
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        item3 = ViewableItem('add_event')
        group.add(item1, priority=2).add(item2, priority=3).add(item3, priority=4)

        group.change_priority(1, item3.id, item2.id)
        self.assertEqual([item3, item2, item1], list(group))
Ejemplo n.º 7
0
    def test_container_item(self):
        my_label = 'Creations...'
        container = ContainerItem('persons', label=my_label)
        self.assertEqual(my_label, container.label)

        child1 = ViewableItem('persons-add_contact')
        child2 = ViewableItem('persons-add_orga')

        container.add(child2, child1)
        self.assertListEqual([child2, child1], [*container])
Ejemplo n.º 8
0
    def test_item_id(self):
        item_id = 'persons-add_contact'
        self.assertEqual(item_id, ViewableItem(item_id).id)

        # Invalid id
        with self.assertRaises(ValueError):
            ViewableItem('persons-add_"contact"')  # " char is forbidden

        with self.assertRaises(ValueError):
            ViewableItem("persons-add_'contact'")  # ' char is forbidden
Ejemplo n.º 9
0
    def test_clear_group(self):
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')

        group.add(item1).add(item2)
        group.clear()
        self.assertFalse([*group])

        with self.assertNoException():
            group.add(item1)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def test_pop_group(self):
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        group.add(item1, priority=2).add(item2, priority=3)

        item2b = group.pop(item2.id)
        self.assertEqual(item2, item2b)
        self.assertListEqual([item1], [*group])

        self.assertRaises(KeyError, group.pop, item2.id)

        group.add(item2b, priority=1)
        self.assertListEqual([item2b, item1], [*group])
Ejemplo n.º 14
0
 def test_item_icon02(self):
     my_icon = 'contact'
     my_icon_label = 'Contact'
     item = ViewableItem('add_contact',
                         icon=my_icon,
                         icon_label=my_icon_label)
     self.assertEqual(my_icon, item.icon)
     self.assertEqual(my_icon_label, item.icon_label)
Ejemplo n.º 15
0
    def test_remove_items_from_group(self):
        group = ItemGroup('creations')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        item3 = ViewableItem('add_event')
        item4 = ViewableItem('add_activity')
        group.add(item1, item2, item3, item4)

        group.remove(item2.id)
        self.assertListEqual([item1, item3, item4], [*group])

        group.remove(item1.id, item4.id)
        self.assertListEqual([item3], [*group])

        group.remove('unknown_id')  # TODO: exception ?? boolean ??

        with self.assertNoException():
            group.add(item1)
Ejemplo n.º 16
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')
Ejemplo n.º 17
0
    def test_add_items_to_group02(self):
        "Priority"
        group = ItemGroup('persons')
        item1 = ViewableItem('add_contact')
        item2 = ViewableItem('add_orga')
        item3 = ViewableItem('add_address')
        item4 = ViewableItem('add_customer')
        item5 = ViewableItem('add_shipping_addr')
        item6 = ViewableItem('add_billing_addr')

        group.add(item1)
        group.add(item2, priority=1)
        self.assertEqual([item1, item2], list(group))

        group.add(item3, priority=3)
        group.add(item4, priority=2)
        self.assertEqual([item1, item2, item4, item3], list(group))
        self.assertEqual(3, item3.priority)

        # Not property => end
        group.add(item5)
        group.add(item6, priority=2)  # priority of previous has been set
        self.assertEqual([item1, item2, item4, item6, item3, item5], list(group))
Ejemplo n.º 18
0
 def test_item_icon03(self):
     "No icon_label => use label"
     my_label = 'Contact'
     item = ViewableItem('add_contact', icon='contact', label=my_label)
     self.assertEqual(my_label, item.icon_label)
Ejemplo n.º 19
0
 def test_item_icon01(self):
     item = ViewableItem('add_contact')
     self.assertIsNone(item.icon)
     self.assertEqual('', item.icon_label)
Ejemplo n.º 20
0
    def test_item_perm(self):
        self.assertIsNone(ViewableItem('add_contact').perm)

        my_perm = 'persons.add_contact'
        self.assertEqual(my_perm,
                         ViewableItem('add_contact', perm=my_perm).perm)