Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_render_menu(self):
     menu = Menu().add(URLItem('contacts', url='/persons/contacts',      label='List of contacts'),
                       URLItem('orgas',    url='/persons/organisations', label='List of organisations'),
                      )
     self.assertHTMLEqual('<ul class="ui-creme-navigation">'
                              '<li class="ui-creme-navigation-item-level0 ui-creme-navigation-item-id_contacts">'
                                  '<a href="/persons/contacts">List of contacts</a>'
                              '</li>'
                              '<li class="ui-creme-navigation-item-level0 ui-creme-navigation-item-id_orgas">'
                                  '<a href="/persons/organisations">List of organisations</a>'
                              '</li>'
                          '</ul>',
                          menu.render(self.build_context())
                         )
Exemplo n.º 4
0
    def test_get_or_create(self):
        menu = Menu()

        id_ = 'analysis'
        label = u'Analysis'
        container1 = menu.get_or_create(ContainerItem, id_, priority=5,
                                        defaults={'label': label},
                                       )
        self.assertIsInstance(container1, ContainerItem)
        self.assertEqual(id_,   container1.id)
        self.assertEqual(label, container1.label)

        container2 = menu.get_or_create(ContainerItem, id_, priority=5,
                                        defaults={'label': label + ' #2'},
                                       )
        self.assertIs(container1, container2)
        self.assertEqual(label, container2.label)
        self.assertEqual([container1], list(menu))

        with self.assertRaises(ValueError):
            menu.get_or_create(ItemGroup, id_, priority=5,
                               defaults={'label': label},
                              )

        # defaults is None
        gid = 'my_group'
        group = menu.get_or_create(ItemGroup, gid, priority=5,
                                        # defaults={'label': label},
                                  )
        self.assertIsInstance(group, ItemGroup)
        self.assertEqual(gid, group.id)
        self.assertFalse(group.label)
Exemplo n.º 5
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)
Exemplo n.º 6
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')