Skip to content

Commit

Permalink
Markdown: add markup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dwaynebailey committed Jul 21, 2017
1 parent 3b33f4a commit aa61bcb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/core/markup/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) Pootle contributors.
#
# This file is a part of the Pootle project. It is distributed under the GPL3
# or later license. See the LICENSE file for a copy of the license and the
# AUTHORS file for copyright and authorship information.

import pytest

from pootle.core.markup.filters import apply_markup_filter


@pytest.mark.parametrize('markdown_text, expected_html', [
# Standard markdown
('Paragraph', '<p>Paragraph</p>'),
('## Header', '<h2>Header</h2>'),
('* List', '<ul><li>List</li></ul>'),
('<hr>', '<hr>'),
# Accept img tags since markdown is rubbish at images
('Show icon <img alt="image" src="pic.png">',
'<p>Show icon <img alt="image" src="pic.png"></p>'),
# Accept span and class=
('Use <span class="allcaps">All Caps</span> for headers.',
'<p>Use <span class="allcaps">All Caps</span> for headers.</p>'),
# Escape a <script> tag
('Bad hacker <script>alert("Bang!")</script>',
'<p>Bad hacker &lt;script&gt;alert("Bang!")&lt;/script&gt;</p>'),
])
def test_apply_markup_filter(settings, markdown_text, expected_html):
settings.POOTLE_MARKUP_FILTER = ('markdown', {})
output_html = apply_markup_filter(markdown_text)
output_html = output_html[5:-6] # Remove surrounding <div>...</div>
output_html = output_html.replace('\n', '') # Remove pretty print newlines
assert output_html == expected_html

0 comments on commit aa61bcb

Please sign in to comment.