~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/text_markup/test_service.py -rw-r--r-- 3.1 KiB
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params

from byceps.services.text_markup.service import render_html


def test_auto_url_linking():
    text = 'before http://example.com/index.html after'
    expected = 'before <a href="http://example.com/index.html">http://example.com/index.html</a> after'
    assert render_html(text) == expected


def test_explicit_url_linking():
    text = 'before [url]http://example.com/index.html[/url] after'
    expected = 'before <a href="http://example.com/index.html">http://example.com/index.html</a> after'
    assert render_html(text) == expected


def test_labeled_url_linking():
    text = 'before [url=http://example.com/index.html]Example[/url] after'
    expected = 'before <a href="http://example.com/index.html">Example</a> after'
    assert render_html(text) == expected


def test_image():
    text = 'before [img]http://example.com/image.png[/img] after'
    expected = 'before <img src="http://example.com/image.png"> after'
    assert render_html(text) == expected


def test_linked_image():
    text = 'before [url=http://example.com/index.html][img]http://example.com/image.png[/img][/url] after'
    expected = 'before <a href="http://example.com/index.html"><img src="http://example.com/image.png"></a> after'
    assert render_html(text) == expected


def test_quote_without_author():
    text = '[quote]All your base are belong to us.[/quote]'
    expected = '<blockquote>All your base are belong to us.</blockquote>'
    assert render_html(text) == expected


def test_quote_with_author():
    text = '[quote author="CATS"]All your base are belong to us.[/quote]'
    expected = '<p class="quote-intro"><cite>CATS</cite> schrieb:</p>\n<blockquote>All your base are belong to us.</blockquote>'
    assert render_html(text) == expected


@params(
    (
        '[quote author="foo]bar"]blah[/quote]',
        '<p class="quote-intro"><cite>foo]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="foo[bar"]blah[/quote]',
        '<p class="quote-intro"><cite>foo[bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="foo][bar"]blah[/quote]',
        '<p class="quote-intro"><cite>foo][bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="foo[]bar"]blah[/quote]',
        '<p class="quote-intro"><cite>foo[]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="[foobar]"]blah[/quote]',
        '<p class="quote-intro"><cite>[foobar]</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="]foobar["]blah[/quote]',
        '<p class="quote-intro"><cite>]foobar[</cite> schrieb:</p>\n<blockquote>blah</blockquote>',
    ),
    (
        '[quote author="<AngleBracketeer>"]careful.[/quote]',
        '<p class="quote-intro"><cite>&lt;AngleBracketeer&gt;</cite> schrieb:</p>\n<blockquote>careful.</blockquote>',
    ),
)
def test_quote_with_author_whose_name_contains_square_brackets(text, expected):
    assert render_html(text) == expected