From b0d766343bf618398df45cc1d5b4444255d986bc Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Mon, 3 Jun 2013 17:12:38 -0500 Subject: Version response compatible with Folsom This change adds elements to the element in the version response to be compatible with the response given by the Keystone server in the Folsom release. Fixes bug 1187101 Change-Id: Ida71e2dbe3cf432d429fb739e68a83d7e009ca40 --- keystone/common/serializer.py | 12 ++++++++++++ tests/test_serializer.py | 45 +++++++++++++++++++++++++++++++++++++++++++ tests/test_versions.py | 5 +++++ 3 files changed, 62 insertions(+) diff --git a/keystone/common/serializer.py b/keystone/common/serializer.py index 6b12df3a..597fbfd8 100644 --- a/keystone/common/serializer.py +++ b/keystone/common/serializer.py @@ -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) diff --git a/tests/test_serializer.py b/tests/test_serializer.py index ba162955..2024949b 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -250,3 +250,48 @@ class XmlSerializerTestCase(test.TestCase): """ 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 = """ + + + + + + + + + + + + """ + self.assertEqualXML(serializer.to_xml(d), xml) diff --git a/tests/test_versions.py b/tests/test_versions.py index 2a53952f..a6c7086b 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -281,6 +281,11 @@ vnd.openstack.identity-v2.0+xml"/> + + + """ -- cgit