-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_tag.py
67 lines (52 loc) · 1.3 KB
/
test_tag.py
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
import pytest
from django.template.loader import render_to_string
from includecontents.templatetags.includecontents import Attrs
def test_basic():
assert render_to_string("test_tag/basic.html") == (
"""<div class="outer">
<div class="inner" id="">
inner content
</div>
</div>
"""
)
def test_with_attr():
assert render_to_string("test_tag/with_attr.html", {"inner_id": "hello"}) == (
"""<div class="outer">
<div class="inner" id="hello">
inner content
</div>
</div>
"""
)
def test_attrs_class():
attrs = Attrs()
attrs.update({"test": 1, "me-out": 2})
# Unknown keys raise KeyError
with pytest.raises(KeyError):
attrs["unknown"]
# Basic lookup works
assert attrs["test"] == 1
# Kebab case works
assert attrs["me-out"] == 2
# Camel case is converted to kebab case
assert attrs["meOut"] == 2
assert attrs["MeOut"] == 2
def test_context():
assert render_to_string("test_tag/basic.html", {"id": "seen"}) == (
"""<div class="outer">
<div class="inner" id="seen">
inner content
</div>
</div>
"""
)
def test_context_only():
assert render_to_string("test_tag/basic_only.html", {"id": "unseen"}) == (
"""<div class="outer">
<div class="inner" id="">
inner content
</div>
</div>
"""
)