File: test_callbacks.py

package info (click to toggle)
python-bleach 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,356 kB
  • sloc: python: 14,626; sh: 61; makefile: 51
file content (63 lines) | stat: -rw-r--r-- 1,846 bytes parent folder | download | duplicates (3)
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, "href"): "mailto:joe@example.com"}
        assert target_blank(attrs) == attrs

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

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