Cleanup XML for api samples tests for Nova REST API

In I5a580fc323c3809790b4a68a9f8f8129ecdc2cf0 we switched off XML support.
This patch cleanup xml related code in the api sample tests.

Change-Id: I1cf2c37b2004cdefd6cc1393f31eed8ebe688dd8
This commit is contained in:
He Jie Xu
2015-01-07 22:36:10 +08:00
parent e66a3b36a0
commit dc95bd563a
2 changed files with 8 additions and 34 deletions

View File

@@ -16,7 +16,6 @@
import os
import re
from lxml import etree
from oslo.serialization import jsonutils
from oslo.utils import importutils
import six
@@ -36,40 +35,16 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
extension_name = None
def _pretty_data(self, data):
if self.ctype == 'json':
data = jsonutils.dumps(jsonutils.loads(data), sort_keys=True,
indent=4)
else:
if data is None:
# Likely from missing XML file.
return ""
xml = etree.XML(data)
data = etree.tostring(xml, encoding="UTF-8",
xml_declaration=True, pretty_print=True)
data = jsonutils.dumps(jsonutils.loads(data), sort_keys=True,
indent=4)
return '\n'.join(line.rstrip() for line in data.split('\n')).strip()
def _objectify(self, data):
if not data:
return {}
if self.ctype == 'json':
# NOTE(vish): allow non-quoted replacements to survive json
data = re.sub(r'([^"])%\((.+)\)s([^"])', r'\1"%(int:\2)s"\3', data)
return jsonutils.loads(data)
else:
def to_dict(node):
ret = {}
if node.items():
ret.update(dict(node.items()))
if node.text:
ret['__content__'] = node.text
if node.tag:
ret['__tag__'] = node.tag
for element in node:
ret.setdefault(node.tag, [])
ret[node.tag].append(to_dict(element))
return ret
return to_dict(etree.fromstring(data))
# NOTE(vish): allow non-quoted replacements to survive json
data = re.sub(r'([^"])%\((.+)\)s([^"])', r'\1"%(int:\2)s"\3', data)
return jsonutils.loads(data)
@classmethod
def _get_sample_path(cls, name, dirname, suffix=''):