34 lines
724 B
Python
34 lines
724 B
Python
import xml.etree.ElementTree as ET
|
|
|
|
from passerelle.utils.xml import to_json, text_content
|
|
|
|
|
|
def test_text_content():
|
|
root = ET.fromstring('<root>aa<b>bb</b>cc</root>')
|
|
assert text_content(root) == 'aabbcc'
|
|
|
|
|
|
def test_to_json():
|
|
root = ET.fromstring('''<root>
|
|
<text1>1</text1>
|
|
<text2>2</text2>
|
|
<enfants>
|
|
<enfant>
|
|
<text3>3</text3>
|
|
</enfant>
|
|
<enfant>
|
|
<text3>4</text3>
|
|
</enfant>
|
|
<zob/>
|
|
</enfants>
|
|
<zob/>
|
|
</root>''')
|
|
assert to_json(root) == {
|
|
'text1': '1',
|
|
'text2': '2',
|
|
'enfants': [
|
|
{'text3': '3'},
|
|
{'text3': '4'},
|
|
]
|
|
}
|