summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wolf <throughnothing@gmail.com>2011-07-26 11:30:58 -0400
committerWilliam Wolf <throughnothing@gmail.com>2011-07-26 11:30:58 -0400
commitbde063a98dad2ce75be1016b39a2c3f08759d4f6 (patch)
treeaaa99dc91047dc528a8ff9dc211098592ca1602b
parentcdcc860cd5d513638c9d85b692f4b46b5e2832ef (diff)
got rid of string comparisons in serializer tests
-rw-r--r--nova/api/openstack/versions.py9
-rw-r--r--nova/tests/api/openstack/test_versions.py67
2 files changed, 26 insertions, 50 deletions
diff --git a/nova/api/openstack/versions.py b/nova/api/openstack/versions.py
index 03b99f342..40c187607 100644
--- a/nova/api/openstack/versions.py
+++ b/nova/api/openstack/versions.py
@@ -205,6 +205,7 @@ class VersionsXMLSerializer(wsgi.XMLDictSerializer):
# in the base class (XMLDictSerializer), which I plan to do in
# another branch
def to_xml_string(self, node, has_atom=False):
+ print "TOXML"
self._add_xmlns(node, has_atom)
return node.toxml(encoding='UTF-8')
@@ -273,6 +274,14 @@ class VersionsXMLSerializer(wsgi.XMLDictSerializer):
class VersionsAtomSerializer(wsgi.XMLDictSerializer):
+ #TODO(wwolf): this is temporary until we get rid of toprettyxml
+ # in the base class (XMLDictSerializer), which I plan to do in
+ # another branch
+ def to_xml_string(self, node, has_atom=False):
+ print "TOXML"
+ self._add_xmlns(node, has_atom)
+ return node.toxml(encoding='UTF-8')
+
def __init__(self, metadata=None, xmlns=None):
self.metadata = metadata or {}
if not xmlns:
diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py
index 448a69c07..b8c985e4d 100644
--- a/nova/tests/api/openstack/test_versions.py
+++ b/nova/tests/api/openstack/test_versions.py
@@ -531,47 +531,9 @@ class VersionsTest(test.TestCase):
]
}
- expected = """
- <feed xmlns="http://www.w3.org/2005/Atom">
- <title type="text">
- Available API Versions
- </title>
- <updated>
- 2011-07-20T11:40:00Z
- </updated>
- <id>
- http://test/
- </id>
- <author>
- <name>
- Rackspace
- </name>
- <uri>
- http://www.rackspace.com/
- </uri>
- </author>
- <link href="http://test/" rel="self"/>
- <entry>
- <id>
- http://test/2.9.8
- </id>
- <title type="text">
- Version 2.9.8
- </title>
- <updated>
- 2011-07-20T11:40:00Z
- </updated>
- <link href="http://test/2.9.8" rel="self"/>
- <content type="text">
- Version 2.9.8 CURRENT (2011-07-20T11:40:00Z)
- </content>
- </entry>
- </feed>""".replace(" ", "").replace("\n", "")
-
serializer = versions.VersionsAtomSerializer()
response = serializer.index(versions_data)
- response = response.replace(" ", "").replace("\n", "")
- self.assertEqual(expected, response)
+ print response
root = xml.etree.ElementTree.XML(response)
self.assertEqual(root.tag.split('}')[1], "feed")
@@ -608,18 +570,23 @@ class VersionsTest(test.TestCase):
entry_children = list(entry)
entry_id = entry_children[0]
entry_title = entry_children[1]
- entry_updated = entry_children[1]
- entry_link = entry_children[1]
- entry_content = entry_children[1]
+ entry_updated = entry_children[2]
+ entry_link = entry_children[3]
+ entry_content = entry_children[4]
+ self.assertEqual(entry_id.tag.split('}')[1], "id")
self.assertEqual(entry_id.text, "http://test/2.9.8")
-
-
-
- #self.assertEqual(media_types.tag.split('}')[1], 'media-types')
- #for i, media_node in enumerate(media_type_nodes):
- #self.assertEqual(media_node.tag.split('}')[1], 'media-type')
- #for key, val in version_data['version']['media-types'][i].items():
- #self.assertEqual(val, media_node.get(key))
+ self.assertEqual(entry_title.tag.split('}')[1], "title")
+ self.assertEqual(entry_title.get('type'), "text")
+ self.assertEqual(entry_title.text, "Version 2.9.8")
+ self.assertEqual(entry_updated.tag.split('}')[1], "updated")
+ self.assertEqual(entry_updated.text, "2011-07-20T11:40:00Z")
+ self.assertEqual(entry_link.tag.split('}')[1], "link")
+ self.assertEqual(entry_link.get('href'), "http://test/2.9.8")
+ self.assertEqual(entry_link.get('rel'), "self")
+ self.assertEqual(entry_content.tag.split('}')[1], "content")
+ self.assertEqual(entry_content.get('type'), "text")
+ self.assertEqual(entry_content.text,
+ "Version 2.9.8 CURRENT (2011-07-20T11:40:00Z)")
def test_version_detail_atom_serializer(self):
versions_data = {