Set empty element to ""
When serializer xml formatter response need set empty element to "" to align with JSON formatter. Fix bug 1168317 Change-Id: I4985791095f43eac88fe42ec16f6a78bbf77ec07
This commit is contained in:
parent
a75e1128f4
commit
9b9a3d53a9
@ -153,6 +153,10 @@ class XmlDeserializer(object):
|
||||
else:
|
||||
values = dict(values.items() + child.items())
|
||||
|
||||
# set empty and none-list element to None to align with JSON
|
||||
if not values:
|
||||
values = ""
|
||||
|
||||
d = {XmlDeserializer._tag_name(element.tag, namespace): values}
|
||||
|
||||
if links:
|
||||
|
@ -904,3 +904,53 @@ class XmlTestCase(RestfulTestCase, CoreApiTests):
|
||||
</auth>
|
||||
""",
|
||||
expected_status=400)
|
||||
|
||||
def test_add_tenant_xml(self):
|
||||
"""
|
||||
verify create a tenant without providing description field
|
||||
"""
|
||||
token = self.get_scoped_token()
|
||||
r = self.request(
|
||||
port=self._admin_port(),
|
||||
method='POST',
|
||||
path='/v2.0/tenants',
|
||||
headers={
|
||||
'Content-Type': 'application/xml',
|
||||
'X-Auth-Token': token
|
||||
},
|
||||
body="""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tenant xmlns="http://docs.openstack.org/identity/api/v2.0"
|
||||
enabled="true" name="ACME Corp">
|
||||
<description></description>
|
||||
</tenant>
|
||||
""")
|
||||
self._from_content_type(r, 'json')
|
||||
self.assertIsNotNone(r.body.get('tenant'))
|
||||
self.assertValidTenant(r.body['tenant'])
|
||||
self.assertEqual(r.body['tenant'].get('description'), "")
|
||||
|
||||
def test_add_tenant_json(self):
|
||||
"""
|
||||
verify create a tenant without providing description field
|
||||
"""
|
||||
token = self.get_scoped_token()
|
||||
r = self.request(
|
||||
port=self._admin_port(),
|
||||
method='POST',
|
||||
path='/v2.0/tenants',
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Token': token
|
||||
},
|
||||
body="""
|
||||
{"tenant":{
|
||||
"name":"test1",
|
||||
"description":"",
|
||||
"enabled":"true"}
|
||||
}
|
||||
""")
|
||||
self._from_content_type(r, 'json')
|
||||
self.assertIsNotNone(r.body.get('tenant'))
|
||||
self.assertValidTenant(r.body['tenant'])
|
||||
self.assertEqual(r.body['tenant'].get('description'), "")
|
||||
|
@ -154,6 +154,29 @@ class XmlSerializerTestCase(test.TestCase):
|
||||
|
||||
self.assertSerializeDeserialize(d, xml)
|
||||
|
||||
def test_tenant_crud_no_description(self):
|
||||
d = {
|
||||
"tenant": {
|
||||
"id": "1234",
|
||||
"name": "ACME corp",
|
||||
"description": "",
|
||||
"enabled": True
|
||||
}
|
||||
}
|
||||
|
||||
xml = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tenant
|
||||
xmlns="http://docs.openstack.org/identity/api/v2.0"
|
||||
enabled="true"
|
||||
id="1234"
|
||||
name="ACME corp">
|
||||
<description></description>
|
||||
</tenant>
|
||||
"""
|
||||
|
||||
self.assertSerializeDeserialize(d, xml)
|
||||
|
||||
def test_policy_list(self):
|
||||
d = {"policies": [{"id": "ab12cd"}]}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user