Пример #1
0
    def _get_lv_content(self, response):
        page_tree = html5lib.parse(response.content, namespaceHTMLElements=False)

        content_node = page_tree.find(".//form[@widget='ui-creme-listview']//table[@data-total-count]")
        self.assertIsNotNone(content_node, 'The table listviews is not found.')

        tbody = content_node.find(".//tbody")
        self.assertIsNotNone(tbody)

        content = []

        for tr_node in tbody.findall('tr'):
            for td_node in tr_node.findall('td'):
                class_attr = td_node.attrib.get('class')

                if class_attr:
                    classes = class_attr.split()

                    if 'lv-cell-content' in classes:
                        div_node = td_node.find(".//div")

                        if div_node is not None:
                            content.append(div_node.text.strip())

        return content
Пример #2
0
    def test_render_url_item04(self):
        "Perm is callable"
        self.login(is_superuser=False)

        url = '/creme/add_contact'
        item = URLItem('home',
                       url=url,
                       label='Create contact',
                       perm=lambda user: user.is_superuser)

        elt = html5lib.parse(item.render(self.build_context()),
                             namespaceHTMLElements=False)
        span_node = elt.find('.//span')
        self.assertEqual('ui-creme-navigation-text-entry forbidden',
                         span_node.get('class'))

        # ---
        item.perm = lambda user: True
        elt = html5lib.parse(item.render(self.build_context()),
                             namespaceHTMLElements=False)
        self.assertIsNone(elt.find('.//span'))

        a_node = elt.find('.//a')
        self.assertEqual(url, a_node.get('href'))
Пример #3
0
    def test_render_url_item02(self):
        "URLItem with icon and label"
        icon = 'creme'
        my_label = 'HOME'
        item = URLItem(
            'home',
            url='/',
            label=my_label,
            icon=icon,
            icon_label='Home',
            perm='creme_core',
        )

        elt = html5lib.parse(item.render(self.build_context()),
                             namespaceHTMLElements=False)
        img_node = elt.find('.//a/img')
        self.assertEqual('header-menu-icon', img_node.get('class'))
        self.assertEqual(my_label, img_node.tail)
Пример #4
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())
Пример #5
0
    def test_render_url_item01(self):
        "URLItem with icon"
        url = '/'
        icon = 'creme'
        label = 'Home'
        item = URLItem('home', url=url, icon=icon, icon_label=label)

        elt = html5lib.parse(item.render(self.build_context()),
                             namespaceHTMLElements=False)
        a_node = elt.find('.//a')
        self.assertEqual(url, a_node.get('href'))

        children = [*a_node]
        self.assertEqual(1, len(children))

        img_node = children[0]
        self.assertEqual('img', img_node.tag)
        self.assertEqual('header-menu-icon', img_node.get('class'))
        self.assertEqual(label, img_node.get('alt'))
        self.assertEqual(label, img_node.get('title'))
        self.assertIn(icon, img_node.get('src', ''))
        self.assertFalse(img_node.tail)
Пример #6
0
    def test_render_url_item03(self):
        "Not allowed (string perm)"
        self.login(is_superuser=False, allowed_apps=['creme_core'])

        icon = 'creme'
        my_label = 'HOME'
        item = URLItem(
            'home',
            url='/',
            label=my_label,
            icon=icon,
            icon_label='Home',
            perm='creme_core.add_fakecontact',
        )

        elt = html5lib.parse(item.render(self.build_context()),
                             namespaceHTMLElements=False)
        span_node = elt.find('.//span')
        self.assertEqual('ui-creme-navigation-text-entry forbidden',
                         span_node.get('class'))

        children = [*span_node]
        self.assertEqual(1, len(children))
        self.assertEqual('img', children[0].tag)
Пример #7
0
 def get_html_tree(self, content):
     return html5lib.parse(content, namespaceHTMLElements=False)