diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-04-23 03:35:15 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-04-23 03:35:15 +0000 |
| commit | 19f60323209f4e04b8a764ebcbc648c5f623168b (patch) | |
| tree | aeb80312f1b0140e9ee9493460e64aefdf90723a | |
| parent | 92e40cee9d222b22e892ad1f1662020d8963315b (diff) | |
| parent | 9b9a3d53a901da7ef2b80f62e7e6a668be161bec (diff) | |
| download | keystone-19f60323209f4e04b8a764ebcbc648c5f623168b.tar.gz keystone-19f60323209f4e04b8a764ebcbc648c5f623168b.tar.xz keystone-19f60323209f4e04b8a764ebcbc648c5f623168b.zip | |
Merge "Set empty element to """
| -rw-r--r-- | keystone/common/serializer.py | 4 | ||||
| -rw-r--r-- | tests/test_content_types.py | 50 | ||||
| -rw-r--r-- | tests/test_serializer.py | 23 |
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"}]} |
