Skip to content

Instantly share code, notes, and snippets.

@cerivera
Created October 22, 2014 02:43
Show Gist options
  • Save cerivera/f197bfb2212de568429b to your computer and use it in GitHub Desktop.
Save cerivera/f197bfb2212de568429b to your computer and use it in GitHub Desktop.
Testing an XML request with custom attributes (required)
def _uglify_xml(xml_output):
ugly = xml_output.replace(" ", "").replace("\n", "")
return ugly
def test_xml_basic_building():
d = {
'EAI': '11111111',
'DBHost': 'BISTEST',
'ReferenceId': 'user12345',
'Request xmlns="http://www.example.com/WebDelivery" version="1.0"': {
'Products': {
'PremierProfile': {
'Subscriber': {
'OpInitials': 'CR',
'SubCode': '0123456'
},
'OutputType': {
'XML': {
'Verbose': 'Y'
}
}
}
}
}
}
xml_out = dicttoxml.dicttoxml(d, attr_type=False, custom_root='NetRequest xmlns="http://www.example.com/NetRequest" xmlns:xsi="http://www.example.org/2001/XMLSchema" xsi:schemaLocation="http://www.example.com/NetRequest NetRequest.xsd"')
assert xml_out == _uglify_xml("""
<?xml version="1.0" encoding="UTF-8" ?>
<NetRequest xmlns="http://www.example.com/NetRequest" xmlns:xsi="http://www.example.org/2001/XMLSchema" xsi:schemaLocation="http://www.example.com/NetRequest NetRequest.xsd">
<EAI>11111111</EAI>
<DBHost>BISTEST</DBHost>
<ReferenceId>user12345</ReferenceId>
<Request xmlns="http://www.example.com/WebDelivery" version="1.0">
<Products>
<PremierProfile>
<Subscriber>
<SubCode>0123456</SubCode>
<OpInitials>CR</OpInitials>
</Subscriber>
<OutputType>
<XML>
<Verbose>Y</Verbose>
</XML>
</OutputType>
</PremierProfile>
</Products>
</Request>
</NetRequest>""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment