def test_custom_decorator_mention(self):
        """
        check custom decorator ‘mention‘ returns expected html
        """
        self.assertEqual(
            DOM.render(
                DOM.create_element(mention,
                                   {"mention": {
                                       "name": "Jo",
                                       "user": "******"
                                   }})),
            '<a class="mention" href="/forum/member/profile/3/">' +
            '<span class="mention">@Jo</span></a>',
        )
        # Check data not valid then nothing appears
        self.assertEqual(
            DOM.render(
                DOM.create_element(mention,
                                   {"mention": {
                                       "name": "",
                                       "user": ""
                                   }})),
            "",
        )

        # Check data not valid then nothing appears
        self.assertEqual(
            DOM.render(DOM.create_element(mention, {"mention": {}})), "")
Example #2
0
 def test_create_element_none(self):
     self.assertEqual(
         DOM.render(
             DOM.create_element('a', {}, None,
                                DOM.create_element('span', {},
                                                   'Test test'))),
         '<a><span>Test test</span></a>')
Example #3
0
 def test_render(self):
     self.assertEqual(
         DOM.render(
             DOM.create_element(br,
                                {'block': {
                                    'type': BLOCK_TYPES.UNSTYLED
                                }}, '\n')), '<br/>')
Example #4
0
    def render(self, content_state=None):
        """
        Starts the export process on a given piece of content state.
        """
        if content_state is None:
            content_state = {}

        wrapper_state = WrapperState(self.block_map)
        document = DOM.create_element()
        entity_map = content_state.get('entityMap', {})
        min_depth = 0

        for block in content_state.get('blocks', []):
            depth = block['depth']
            elt = self.render_block(block, entity_map, wrapper_state)

            if depth > min_depth:
                min_depth = depth

            # At level 0, append the element to the document.
            if depth == 0:
                DOM.append_child(document, elt)

        # If there is no block at depth 0, we need to add the wrapper that contains the whole tree to the document.
        if min_depth > 0 and wrapper_state.stack.length() != 0:
            DOM.append_child(document, wrapper_state.stack.tail().elt)

        return DOM.render(document)
Example #5
0
    def render(self, content_state=None):
        """
        Starts the export process on a given piece of content state.
        """
        if content_state is None:
            content_state = {}

        blocks = content_state.get('blocks', [])
        wrapper_state = WrapperState(self.block_map, blocks)
        document = DOM.create_element()
        entity_map = content_state.get('entityMap', {})
        min_depth = 0

        for block in blocks:
            depth = block['depth']
            elt = self.render_block(block, entity_map, wrapper_state)

            if depth > min_depth:
                min_depth = depth

            # At level 0, append the element to the document.
            if depth == 0:
                DOM.append_child(document, elt)

        # If there is no block at depth 0, we need to add the wrapper that contains the whole tree to the document.
        if min_depth > 0 and wrapper_state.stack.length() != 0:
            DOM.append_child(document, wrapper_state.stack.tail().elt)

        return DOM.render(document)
    def test_render_www(self):
        match = next(LINKIFY_DECORATOR['strategy'].finditer('test www.example.com'))

        self.assertEqual(DOM.render(DOM.create_element(LINKIFY_DECORATOR['component'], {
            'block': {'type': BLOCK_TYPES.UNSTYLED},
            'match': match,
        }, match.group(0))), '<a href="http://www.example.com">www.example.com</a>')
Example #7
0
 def test_internal_link_href_fallback(self):
     """Test if the fallback href is used when the page does not exist."""
     input_props = {
         'linkType': 'page',
         'id': 999,
     }
     output = DOM.render(DOM.create_element(Link, input_props))
     self.assertEqual(output, '<a href="{0}"></a>'.format(MISSING_RESOURCE_URL))
Example #8
0
 def test_internal_link(self):
     """Test if the page URL is set."""
     input_props = {
         'linkType': 'page',
         'id': self.page.pk
     }
     output = DOM.render(DOM.create_element(Link, input_props))
     self.assertEqual(output, '<a href="{0}"></a>'.format(self.page.url))
Example #9
0
 def test_render(self):
     self.assertEqual(
         DOM.render(
             DOM.create_element(hashtag,
                                {'block': {
                                    'type': BLOCK_TYPES.UNSTYLED
                                }}, '#hashtagtest')),
         '<span class="hashtag">#hashtagtest</span>')
Example #10
0
 def test_with_children(self):
     """Test if child content is rendered."""
     input_props = {
         'linkType': 'page',
         'id': self.page.pk,
     }
     output = DOM.render(DOM.create_element(Link, input_props, 'anchor content'))
     self.assertEqual(output, '<a href="{0}">anchor content</a>'.format(self.page.url))
Example #11
0
 def test_external_link(self):
     """Test if external links are passed as such."""
     input_props = {
         'linkType': 'external',
         'url': 'http://test.test',
     }
     output = DOM.render(DOM.create_element(Link, input_props))
     self.assertEqual(output, '<a href="http://test.test"></a>')
Example #12
0
 def test_with_title(self):
     """Test if title attribute is set."""
     input_props = {
         'linkType': 'external',
         'url': 'http://test.test',
         'title': 'Test title'
     }
     output = DOM.render(DOM.create_element(Link, input_props))
     self.assertEqual(output, '<a href="http://test.test" title="Test title"></a>')
Example #13
0
 def test_render(self):
     self.assertEqual(
         DOM.render(
             DOM.create_element(
                 image, {
                     'src': 'http://example.com/example.png',
                     'width': 320,
                     'height': 580,
                 })),
         '<img height="580" src="http://example.com/example.png" width="320"/>'
     )
Example #14
0
    def test_render_www(self):
        match = next(LINKIFY_RE.finditer('test www.example.com'))

        self.assertEqual(
            DOM.render(
                DOM.create_element(linkify, {
                    'block': {
                        'type': BLOCK_TYPES.UNSTYLED
                    },
                    'match': match,
                }, match.group(0))),
            '<a href="http://www.example.com">www.example.com</a>')
 def test_render(self):
     self.assertEqual(DOM.render(DOM.create_element(BR_DECORATOR['component'], {'block': {'type': BLOCK_TYPES.UNSTYLED}}, '\n')), '<br/>')
 def test_render(self):
     self.assertEqual(DOM.render(DOM.create_element(HASHTAG_DECORATOR['component'], {'block': {'type': BLOCK_TYPES.UNSTYLED}}, '#hashtagtest')), '<span class="hashtag">#hashtagtest</span>')
 def test_render(self):
     self.assertEqual(DOM.render(DOM.create_element(link, {
         'url': 'http://example.com',
     }, 'wow')), '<a href="http://example.com">wow</a>')
 def test_render_with_icon(self):
     self.assertEqual(DOM.render(DOM.create_element(button, {
         'href': 'http://example.com',
         'icon': 'rocket',
         'text': 'Launch',
     })), '<a class="icon-text" href="http://example.com"><svg class="icon"><use xlink:href="#icon-rocket"></use></svg><span class="icon-text__text">Launch</span></a>')
 def test_render_without_icon(self):
     self.assertEqual(DOM.render(DOM.create_element(button, {
         'href': 'http://example.com',
         'text': 'Launch',
     })), '<a href="http://example.com">Launch</a>')
 def test_render_decorators_single(self):
     self.assertEqual(DOM.render(render_decorators([LINKIFY_DECORATOR], 'test https://www.example.com#hash #hashtagtest', {'type': BLOCK_TYPES.UNSTYLED, 'depth': 0}, [])), 'test <a href="https://www.example.com#hash">https://www.example.com#hash</a> #hashtagtest')
 def test_render(self):
     self.assertEqual(DOM.render(DOM.create_element(image, {
         'src': 'http://example.com/example.png',
         'width': 320,
         'height': 580,
     })), '<img height="580" src="http://example.com/example.png" width="320"/>')
 def test_render_decorators_conflicting_order_two(self):
     self.assertEqual(DOM.render(render_decorators([HASHTAG_DECORATOR, LINKIFY_DECORATOR], 'test https://www.example.com#hash #hashtagtest', {'type': BLOCK_TYPES.UNSTYLED, 'depth': 0}, [])), 'test https://www.example.com<span class="hashtag">#hash</span> <span class="hashtag">#hashtagtest</span>')
 def test_render(self):
     self.assertEqual(DOM.render(DOM.create_element(icon, {'name': 'rocket'})), '<svg class="icon"><use xlink:href="#icon-rocket"></use></svg>')