Completed
Push — main ( dda81c...348db2 )
by Jochen
05:17
created

tests.unit.services.text_markup.test_service   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 9

9 Functions

Rating   Name   Duplication   Size   Complexity  
A test_auto_url_linking() 0 4 1
A test_quote_without_author() 0 4 1
A test_explicit_url_linking() 0 4 1
A test_code_block() 0 4 1
A test_linked_image() 0 4 1
A test_quote_with_author() 0 4 1
A test_quote_with_author_whose_name_contains_square_brackets() 0 32 1
A test_labeled_url_linking() 0 4 1
A test_image() 0 4 1
1
"""
2
:Copyright: 2006-2020 Jochen Kupperschmidt
3
:License: Modified BSD, see LICENSE for details.
4
"""
5
6
import pytest
7
8
from byceps.services.text_markup.service import render_html
9
10
11
def test_auto_url_linking():
12
    text = 'before http://example.com/index.html after'
13
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">http://example.com/index.html</a> after'
14
    assert render_html(text) == expected
15
16
17
def test_code_block():
18
    text = 'Use the source, Luke!\n[code]Do not replace ... with an ellipsis character![/code]\nSweet!'
19
    expected = 'Use the source, Luke!<br /><pre><code class="block">Do not replace ... with an ellipsis character!</code></pre><br />Sweet!'
20
    assert render_html(text) == expected
21
22
23
def test_explicit_url_linking():
24
    text = 'before [url]http://example.com/index.html[/url] after'
25
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">http://example.com/index.html</a> after'
26
    assert render_html(text) == expected
27
28
29
def test_labeled_url_linking():
30
    text = 'before [url=http://example.com/index.html]Example[/url] after'
31
    expected = 'before <a rel="nofollow" href="http://example.com/index.html">Example</a> after'
32
    assert render_html(text) == expected
33
34
35
def test_image():
36
    text = 'before [img]http://example.com/image.png[/img] after'
37
    expected = 'before <img src="http://example.com/image.png"> after'
38
    assert render_html(text) == expected
39
40
41
def test_linked_image():
42
    text = 'before [url=http://example.com/index.html][img]http://example.com/image.png[/img][/url] after'
43
    expected = 'before <a rel="nofollow" href="http://example.com/index.html"><img src="http://example.com/image.png"></a> after'
44
    assert render_html(text) == expected
45
46
47
def test_quote_without_author():
48
    text = '[quote]All your base are belong to us.[/quote]'
49
    expected = '<blockquote>All your base are belong to us.</blockquote>'
50
    assert render_html(text) == expected
51
52
53
def test_quote_with_author():
54
    text = '[quote author="CATS"]All your base are belong to us.[/quote]'
55
    expected = '<p class="quote-intro"><cite>CATS</cite> schrieb:</p>\n<blockquote>All your base are belong to us.</blockquote>'
56
    assert render_html(text) == expected
57
58
59
@pytest.mark.parametrize('text, expected', [
60
    (
61
        '[quote author="foo]bar"]blah[/quote]',
62
        '<p class="quote-intro"><cite>foo]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
63
    ),
64
    (
65
        '[quote author="foo[bar"]blah[/quote]',
66
        '<p class="quote-intro"><cite>foo[bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
67
    ),
68
    (
69
        '[quote author="foo][bar"]blah[/quote]',
70
        '<p class="quote-intro"><cite>foo][bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
71
    ),
72
    (
73
        '[quote author="foo[]bar"]blah[/quote]',
74
        '<p class="quote-intro"><cite>foo[]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
75
    ),
76
    (
77
        '[quote author="[foobar]"]blah[/quote]',
78
        '<p class="quote-intro"><cite>[foobar]</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
79
    ),
80
    (
81
        '[quote author="]foobar["]blah[/quote]',
82
        '<p class="quote-intro"><cite>]foobar[</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
83
    ),
84
    (
85
        '[quote author="<AngleBracketeer>"]careful.[/quote]',
86
        '<p class="quote-intro"><cite>&lt;AngleBracketeer&gt;</cite> schrieb:</p>\n<blockquote>careful.</blockquote>',
87
    ),
88
])
89
def test_quote_with_author_whose_name_contains_square_brackets(text, expected):
90
    assert render_html(text) == expected
91