Merge "Version response compatible with Folsom"

This commit is contained in:
Jenkins 2013-06-24 18:08:21 +00:00 committed by Gerrit Code Review
commit 95cf4704d2
3 changed files with 62 additions and 0 deletions

View File

@ -300,6 +300,18 @@ class XmlSerializer(object):
self._populate_sequence(element, value)
elif isinstance(value, dict):
self._populate_tree(element, value)
# NOTE(blk-u): For compatibility with Folsom, when serializing the
# v2.0 version element also add the links to the base element.
if (value.get('id') == 'v2.0' and
value.get('status') == 'stable' and
value.get('updated') == '2013-03-06T00:00:00Z'):
for item in value['links']:
child = etree.Element('link')
self.populate_element(child, item)
element.append(child)
elif isinstance(value, basestring):
element.text = unicode(value)

View File

@ -250,3 +250,48 @@ class XmlSerializerTestCase(test.TestCase):
</object>
"""
self.assertSerializeDeserialize(d, xml)
def test_v2_links_special_case(self):
# There's special-case code (for backward compatibility) where if the
# data is the v2 version data, the link elements are also added to the
# main element.
d = {
"object": {
"id": "v2.0",
"status": "stable",
"updated": "2013-03-06T00:00:00Z",
"links": [{"href": "http://localhost:5000/v2.0/",
"rel": "self"},
{"href": "http://docs.openstack.org/api/openstack-"
"identity-service/2.0/content/",
"type": "text/html", "rel": "describedby"},
{"href": "http://docs.openstack.org/api/openstack-"
"identity-service/2.0/"
"identity-dev-guide-2.0.pdf",
"type": "application/pdf", "rel": "describedby"}]
}}
xml = """
<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="http://docs.openstack.org/identity/api/v2.0"
id="v2.0" status="stable" updated="2013-03-06T00:00:00Z">
<links>
<link rel="self" href="http://localhost:5000/v2.0/"/>
<link rel="describedby"
href="http://docs.openstack.org/api/openstack-\
identity-service/2.0/content/" type="text/html"/>
<link rel="describedby"
href="http://docs.openstack.org/api/openstack-\
identity-service/2.0/identity-dev-guide-2.0.pdf" type="application/pdf"/>
</links>
<link rel="self" href="http://localhost:5000/v2.0/"/>
<link rel="describedby"
href="http://docs.openstack.org/api/openstack-\
identity-service/2.0/content/" type="text/html"/>
<link rel="describedby"
href="http://docs.openstack.org/api/openstack-\
identity-service/2.0/identity-dev-guide-2.0.pdf" type="application/pdf"/>
</object>
"""
self.assertEqualXML(serializer.to_xml(d), xml)

View File

@ -282,6 +282,11 @@ vnd.openstack.identity-v2.0+xml"/>
<link href="http://docs.openstack.org/api/openstack-identity-service/\
2.0/identity-dev-guide-2.0.pdf" type="application/pdf" rel="describedby"/>
</links>
<link href="http://localhost:%%(port)s/v2.0/" rel="self"/>
<link href="http://docs.openstack.org/api/openstack-identity-service/\
2.0/content/" type="text/html" rel="describedby"/>
<link href="http://docs.openstack.org/api/openstack-identity-service/\
2.0/identity-dev-guide-2.0.pdf" type="application/pdf" rel="describedby"/>
</version>
"""