Exemple #1
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])
Exemple #2
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')
Exemple #3
0
    def test_render_container_item02(self):
        "No icon"
        context = self.build_context()

        label = 'Contacts'
        icon = 'contact'
        icon_label = 'Contact'
        parent = ContainerItem('persons', label=label, icon=icon, icon_label=icon_label) \
                    .add(URLItem('home', url='/persons/contacts', label='List of contacts'))

        render = parent.render(context, level=1)
        elt = html5lib.parse(render, namespaceHTMLElements=False)

        # ElementTree.dump(elt) >>>
        # <html><head /><body>
        #         <img alt="Contact" class="header-menu-icon"
        #              src="/static_media/icecream/images/contact_16-....png" title="Contact" width="16px" />
        #         Contacts
        #         <ul>
        #             <li class="ui-creme-navigation-item-level2 ui-creme-navigation-item-id_home">
        #                  <a href="/persons/contacts">List of contacts</a>
        #             </li>
        #         </ul>
        # </body>
        img_node = elt.find('.//img')
        self.assertIsNotNone(img_node, 'No <img> tag.')
        self.assertEqual('header-menu-icon', img_node.get('class'))
        self.assertEqual(icon_label, img_node.get('alt'))
        self.assertEqual(icon_label, img_node.get('title'))
        self.assertIn(icon, img_node.get('src', ''))
        self.assertIn(label, img_node.tail)

        ul_node = elt.find('.//ul')
        self.assertIsNotNone(ul_node, 'No <ul> tag.')
        self.assertHTMLEqual(
            '<ul>'
            '<li class="ui-creme-navigation-item-id_home ui-creme-navigation-item-level2">'
            '<a href="/persons/contacts">List of contacts</a>'
            '</li>'
            '</ul>',
            ElementTree.tostring(ul_node).decode())
Exemple #4
0
    def test_render_container_item01(self):
        "No icon"
        context = self.build_context()

        label = 'Creations'
        container = ContainerItem('persons', label=label) \
                        .add(URLItem('contacts', url='/persons/contacts',      label='List of contacts'),
                             URLItem('orgas',    url='/persons/organisations', label='List of organisations'),
                            )

        render = container.render(context)
        self.assertTrue(render.startswith(label))
        self.assertHTMLEqual(
            '<ul>'
            '<li class="ui-creme-navigation-item-id_contacts ui-creme-navigation-item-level1">'
            '<a href="/persons/contacts">List of contacts</a>'
            '</li>'
            '<li class="ui-creme-navigation-item-id_orgas ui-creme-navigation-item-level1">'
            '<a href="/persons/organisations">List of organisations</a>'
            '</li>'
            '</ul>', render[len(label):])