summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgengjh <gengjh@cn.ibm.com>2013-04-12 20:44:41 +0800
committergengjh <gengjh@cn.ibm.com>2013-04-13 18:06:02 +0800
commit9b9a3d53a901da7ef2b80f62e7e6a668be161bec (patch)
tree65a0cb401dc6bac514a46a20dc7f6390c9234b99
parenta75e1128f442c0436a3ef669a24c639f74df0f97 (diff)
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
-rw-r--r--keystone/common/serializer.py4
-rw-r--r--tests/test_content_types.py50
-rw-r--r--tests/test_serializer.py23
3 files changed, 77 insertions, 0 deletions
diff --git a/keystone/common/serializer.py b/keystone/common/serializer.py
index 71cca4a5..6b12df3a 100644
--- a/keystone/common/serializer.py
+++ b/keystone/common/serializer.py
@@ -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:
diff --git a/tests/test_content_types.py b/tests/test_content_types.py
index a7000691..9e989c7a 100644
--- a/tests/test_content_types.py
+++ b/tests/test_content_types.py
@@ -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'), "")
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
index b440c815..ebeb3f3e 100644
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -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"}]}