Example #1
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])
Example #2
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')
Example #3
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])
Example #4
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])
Example #5
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))
Example #6
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)
Example #7
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])
Example #8
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)
Example #9
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)
Example #10
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')
Example #11
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))