Ensure we render tag text properly in Subsonic XML

This commit is contained in:
Eliot Berriot 2019-07-19 07:53:37 +02:00
parent 9376f808e9
commit 904a482698
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
2 changed files with 9 additions and 3 deletions

View File

@ -52,6 +52,9 @@ def dict_to_xml_tree(root_tag, d, parent=None):
elif isinstance(value, list): elif isinstance(value, list):
for obj in value: for obj in value:
root.append(dict_to_xml_tree(key, obj, parent=root)) root.append(dict_to_xml_tree(key, obj, parent=root))
else:
if key == "value":
root.text = str(value)
else: else:
root.set(key, str(value)) root.set(key, str(value))
return root return root

View File

@ -67,9 +67,12 @@ def test_json_renderer():
def test_xml_renderer_dict_to_xml(): def test_xml_renderer_dict_to_xml():
payload = {"hello": "world", "item": [{"this": 1}, {"some": "node"}]} payload = {
"hello": "world",
"item": [{"this": 1, "value": "text"}, {"some": "node"}],
}
expected = """<?xml version="1.0" encoding="UTF-8"?> expected = """<?xml version="1.0" encoding="UTF-8"?>
<key hello="world"><item this="1" /><item some="node" /></key>""" <key hello="world"><item this="1">text</item><item some="node" /></key>"""
result = renderers.dict_to_xml_tree("key", payload) result = renderers.dict_to_xml_tree("key", payload)
exp = ET.fromstring(expected) exp = ET.fromstring(expected)
assert ET.tostring(result) == ET.tostring(exp) assert ET.tostring(result) == ET.tostring(exp)