1
1
# This same set of tests is also found in django-components, to ensure that
2
2
# this implementation can be replaced with the django-components' pure-python implementation
3
3
4
- from djc_core_html_parser import transform_html
4
+ from djc_core_html_parser import set_html_attributes
5
5
from typing import Dict , List
6
6
7
7
8
8
def test_basic_transformation ():
9
9
html = "<div><p>Hello</p></div>"
10
- result , _ = transform_html (html , ["data-root" ], ["data-all" ])
10
+ result , _ = set_html_attributes (html , ["data-root" ], ["data-all" ])
11
11
expected = '<div data-root="" data-all=""><p data-all="">Hello</p></div>'
12
12
assert result == expected
13
13
14
14
15
15
def test_multiple_roots ():
16
16
html = "<div>First</div><span>Second</span>"
17
- result , _ = transform_html (html , ["data-root" ], ["data-all" ])
17
+ result , _ = set_html_attributes (html , ["data-root" ], ["data-all" ])
18
18
expected = '<div data-root="" data-all="">First</div><span data-root="" data-all="">Second</span>'
19
19
assert result == expected
20
20
@@ -42,7 +42,7 @@ def test_complex_html():
42
42
</footer>
43
43
"""
44
44
45
- result , _ = transform_html (html , ["data-root" ], ["data-all" , "data-v-123" ])
45
+ result , _ = set_html_attributes (html , ["data-root" ], ["data-all" , "data-v-123" ])
46
46
expected = """
47
47
<div class="container" id="main" data-root="" data-all="" data-v-123="">
48
48
<header class="flex" data-all="" data-v-123="">
@@ -76,7 +76,7 @@ def test_void_elements():
76
76
]
77
77
78
78
for input_html , expected in test_cases :
79
- result , _ = transform_html (input_html , ["data-root" ], ["data-v-123" ])
79
+ result , _ = set_html_attributes (input_html , ["data-root" ], ["data-v-123" ])
80
80
assert result == expected
81
81
82
82
@@ -89,7 +89,7 @@ def test_html_head_with_meta():
89
89
<meta name="description" content="Test">
90
90
</head>"""
91
91
92
- result , _ = transform_html (html , ["data-root" ], ["data-v-123" ])
92
+ result , _ = set_html_attributes (html , ["data-root" ], ["data-v-123" ])
93
93
expected = """
94
94
<head data-root="" data-v-123="">
95
95
<meta charset="utf-8" data-v-123=""/>
@@ -110,7 +110,7 @@ def test_watch_attribute():
110
110
111
111
result : str
112
112
captured : Dict [str , List [str ]]
113
- result , captured = transform_html (html , ["data-root" ], ["data-v-123" ], watch_on_attribute = "data-id" )
113
+ result , captured = set_html_attributes (html , ["data-root" ], ["data-v-123" ], watch_on_attribute = "data-id" )
114
114
expected = """
115
115
<div data-id="123" data-root="" data-v-123="">
116
116
<p data-v-123="">Regular element</p>
@@ -140,7 +140,7 @@ def test_whitespace_preservation():
140
140
<span> Text with spaces </span>
141
141
</div>"""
142
142
143
- result , _ = transform_html (html , ["data-root" ], ["data-all" ])
143
+ result , _ = set_html_attributes (html , ["data-root" ], ["data-all" ])
144
144
expected = """<div data-root="" data-all="">
145
145
<p data-all=""> Hello World </p>
146
146
<span data-all=""> Text with spaces </span>
0 commit comments