File: test_callbacks.py

package info (click to toggle)
python-bleach 3.1.2-0%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,320 kB
  • sloc: python: 13,477; makefile: 130; sh: 47
file content (63 lines) | stat: -rw-r--r-- 1,865 bytes parent folder | download
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
from bleach.callbacks import nofollow, target_blank


class TestNofollowCallback:
    def test_blank(self):
        attrs = {}
        assert nofollow(attrs) == attrs

    def test_no_href(self):
        attrs = {'_text': 'something something'}
        assert nofollow(attrs) == attrs

    def test_basic(self):
        attrs = {(None, 'href'): 'http://example.com'}
        assert (
            nofollow(attrs) ==
            {(None, 'href'): 'http://example.com', (None, 'rel'): 'nofollow'}
        )

    def test_mailto(self):
        attrs = {(None, 'href'): 'mailto:joe@example.com'}
        assert nofollow(attrs) == attrs

    def test_has_nofollow_already(self):
        attrs = {
            (None, 'href'): 'http://example.com',
            (None, 'rel'): 'nofollow',
        }
        assert nofollow(attrs) == attrs

    def test_other_rel(self):
        attrs = {
            (None, 'href'): 'http://example.com',
            (None, 'rel'): 'next',
        }
        assert (
            nofollow(attrs) ==
            {(None, 'href'): 'http://example.com', (None, 'rel'): 'next nofollow'}
        )


class TestTargetBlankCallback:
    def test_empty(self):
        attrs = {}
        assert target_blank(attrs) == attrs

    def test_mailto(self):
        attrs = {(None, u'href'): u'mailto:joe@example.com'}
        assert target_blank(attrs) == attrs

    def test_add_target(self):
        attrs = {(None, u'href'): u'http://example.com'}
        assert (
            target_blank(attrs) ==
            {(None, u'href'): u'http://example.com', (None, u'target'): u'_blank'}
        )

    def test_stomp_target(self):
        attrs = {(None, u'href'): u'http://example.com', (None, u'target'): u'foo'}
        assert (
            target_blank(attrs) ==
            {(None, u'href'): 'http://example.com', (None, u'target'): u'_blank'}
        )