本文整理汇总了Python中nova.api.openstack.xmlutil.validate_schema函数的典型用法代码示例。如果您正苦于以下问题:Python validate_schema函数的具体用法?Python validate_schema怎么用?Python validate_schema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate_schema函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create
def test_create(self):
serializer = common.MetadataTemplate()
fixture = {
'metadata': {
'key9': 'value9',
'key2': 'value2',
'key1': 'value1',
},
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, 'metadata')
metadata_dict = fixture['metadata']
metadata_elems = root.findall('{0}meta'.format(NS))
self.assertEqual(len(metadata_elems), 3)
for i, metadata_elem in enumerate(metadata_elems):
(meta_key, meta_value) = metadata_dict.items()[i]
self.assertEqual(str(metadata_elem.get('key')), str(meta_key))
self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
actual = minidom.parseString(output.replace(" ", ""))
expected = minidom.parseString("""
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="key2">value2</meta>
<meta key="key9">value9</meta>
<meta key="key1">value1</meta>
</metadata>
""".replace(" ", "").replace("\n", ""))
self.assertEqual(expected.toxml(), actual.toxml())
示例2: test_create
def test_create(self):
serializer = common.MetadataXMLSerializer()
fixture = {"metadata": {"key9": "value9", "key2": "value2", "key1": "value1"}}
output = serializer.serialize(fixture, "create")
print output
root = etree.XML(output)
xmlutil.validate_schema(root, "metadata")
metadata_dict = fixture["metadata"]
metadata_elems = root.findall("{0}meta".format(NS))
self.assertEqual(len(metadata_elems), 3)
for i, metadata_elem in enumerate(metadata_elems):
(meta_key, meta_value) = metadata_dict.items()[i]
self.assertEqual(str(metadata_elem.get("key")), str(meta_key))
self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
actual = minidom.parseString(output.replace(" ", ""))
expected = minidom.parseString(
"""
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="key2">value2</meta>
<meta key="key9">value9</meta>
<meta key="key1">value1</meta>
</metadata>
""".replace(
" ", ""
).replace(
"\n", ""
)
)
self.assertEqual(expected.toxml(), actual.toxml())
示例3: test_list_extensions_xml
def test_list_extensions_xml(self):
app = v2.APIRouter()
ext_midware = extensions.ExtensionMiddleware(app)
ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
request = webob.Request.blank("/123/extensions")
request.accept = "application/xml"
response = request.get_response(ser_midware)
self.assertEqual(200, response.status_int)
print response.body
root = etree.XML(response.body)
self.assertEqual(root.tag.split('extensions')[0], NS)
# Make sure we have all the extensions.
exts = root.findall('{0}extension'.format(NS))
self.assertEqual(len(exts), len(self.ext_list))
# Make sure that at least Fox in Sox is correct.
(fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
self.assertEqual(fox_ext.get('namespace'),
'http://www.fox.in.socks/api/ext/pie/v1.0')
self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
'The Fox In Socks Extension')
xmlutil.validate_schema(root, 'extensions')
示例4: test_get_version_2_detail_atom
def test_get_version_2_detail_atom(self):
req = webob.Request.blank('/v2/')
req.accept = "application/atom+xml"
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 200)
self.assertEqual("application/atom+xml", res.content_type)
xmlutil.validate_schema(etree.XML(res.body), 'atom')
f = feedparser.parse(res.body)
self.assertEqual(f.feed.title, 'About This Version')
self.assertEqual(f.feed.updated, '2011-01-21T11:33:21Z')
self.assertEqual(f.feed.id, 'http://localhost/v2/')
self.assertEqual(f.feed.author, 'Rackspace')
self.assertEqual(f.feed.author_detail.href,
'http://www.rackspace.com/')
self.assertEqual(f.feed.links[0]['href'], 'http://localhost/v2/')
self.assertEqual(f.feed.links[0]['rel'], 'self')
self.assertEqual(len(f.entries), 1)
entry = f.entries[0]
self.assertEqual(entry.id, 'http://localhost/v2/')
self.assertEqual(entry.title, 'Version v2.0')
self.assertEqual(entry.updated, '2011-01-21T11:33:21Z')
self.assertEqual(len(entry.content), 1)
self.assertEqual(entry.content[0].value,
'Version v2.0 CURRENT (2011-01-21T11:33:21Z)')
self.assertEqual(len(entry.links), 2)
self.assertEqual(entry.links[0]['href'], 'http://localhost/v2/')
self.assertEqual(entry.links[0]['rel'], 'self')
self.assertEqual(entry.links[1], {
'href': EXP_LINKS['v2.0']['html'],
'type': 'text/html',
'rel': 'describedby'})
示例5: test_serialize_extensions
def test_serialize_extensions(self):
serializer = base_extensions.ExtensionsTemplate()
data = {
"extensions": [
{
"name": "Public Image Extension",
"namespace": "http://foo.com/api/ext/pie/v1.0",
"alias": "RS-PIE",
"updated": "2011-01-22T13:25:27-06:00",
"description": "Adds the capability to share an image.",
"links": [
{
"rel": "describedby",
"type": "application/pdf",
"type": "application/vnd.sun.wadl+xml",
"href": "http://foo.com/api/ext/cs-pie.pdf",
},
{
"rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
"href": "http://foo.com/api/ext/cs-pie.wadl",
},
],
},
{
"name": "Cloud Block Storage",
"namespace": "http://foo.com/api/ext/cbs/v1.0",
"alias": "RS-CBS",
"updated": "2011-01-12T11:22:33-06:00",
"description": "Allows mounting cloud block storage.",
"links": [
{"rel": "describedby", "type": "application/pdf", "href": "http://foo.com/api/ext/cs-cbs.pdf"},
{
"rel": "describedby",
"type": "application/vnd.sun.wadl+xml",
"href": "http://foo.com/api/ext/cs-cbs.wadl",
},
],
},
]
}
xml = serializer.serialize(data)
root = etree.XML(xml)
ext_elems = root.findall("{0}extension".format(NS))
self.assertEqual(len(ext_elems), 2)
for i, ext_elem in enumerate(ext_elems):
ext_dict = data["extensions"][i]
self.assertEqual(ext_elem.findtext("{0}description".format(NS)), ext_dict["description"])
for key in ["name", "namespace", "alias", "updated"]:
self.assertEqual(ext_elem.get(key), ext_dict[key])
link_nodes = ext_elem.findall("{0}link".format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(ext_dict["links"]):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
xmlutil.validate_schema(root, "extensions")
示例6: test_serialize_extension
def test_serialize_extension(self):
serializer = base_extensions.ExtensionTemplate()
data = {'extension': {
'name': 'ext1',
'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
'alias': 'RS-PIE',
'updated': '2011-01-22T13:25:27-06:00',
'description': 'Adds the capability to share an image.',
'links': [{'rel': 'describedby',
'type': 'application/pdf',
'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
{'rel': 'describedby',
'type': 'application/vnd.sun.wadl+xml',
'href': 'http://docs.rack.com/servers/api/ext/cs.wadl'}]}}
xml = serializer.serialize(data)
root = etree.XML(xml)
ext_dict = data['extension']
self.assertEqual(root.findtext('{0}description'.format(NS)),
ext_dict['description'])
for key in ['name', 'namespace', 'alias', 'updated']:
self.assertEqual(root.get(key), ext_dict[key])
link_nodes = root.findall('{0}link'.format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(ext_dict['links']):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
xmlutil.validate_schema(root, 'extension')
示例7: test_versions_list_xml_serializer
def test_versions_list_xml_serializer(self):
versions_data = {
"versions": [
{
"id": "2.7",
"updated": "2011-07-18T11:30:00Z",
"status": "DEPRECATED",
"links": [{"rel": "self", "href": "http://test/v2"}],
}
]
}
serializer = versions.VersionsTemplate()
response = serializer.serialize(versions_data)
root = etree.XML(response)
xmlutil.validate_schema(root, "versions")
self.assertTrue(root.xpath("/ns:versions", namespaces=NS))
version_elems = root.xpath("ns:version", namespaces=NS)
self.assertEqual(len(version_elems), 1)
version = version_elems[0]
self.assertEqual(version.get("id"), versions_data["versions"][0]["id"])
self.assertEqual(version.get("status"), versions_data["versions"][0]["status"])
(link,) = version.xpath("atom:link", namespaces=NS)
self.assertTrue(
common.compare_links(link, [{"rel": "self", "href": "http://test/v2", "type": "application/atom+xml"}])
)
示例8: test_get_version_3_detail_atom
def test_get_version_3_detail_atom(self):
req = webob.Request.blank("/v3/")
req.accept = "application/atom+xml"
res = req.get_response(fakes.wsgi_app_v3())
self.assertEqual(res.status_int, 200)
self.assertEqual("application/atom+xml", res.content_type)
xmlutil.validate_schema(etree.XML(res.body), "atom")
f = feedparser.parse(res.body)
self.assertEqual(f.feed.title, "About This Version")
self.assertEqual(f.feed.updated, "2013-07-23T11:33:21Z")
self.assertEqual(f.feed.id, "http://localhost/v3/")
self.assertEqual(f.feed.author, "Rackspace")
self.assertEqual(f.feed.author_detail.href, "http://www.rackspace.com/")
self.assertEqual(f.feed.links[0]["href"], "http://localhost/v3/")
self.assertEqual(f.feed.links[0]["rel"], "self")
self.assertEqual(len(f.entries), 1)
entry = f.entries[0]
self.assertEqual(entry.id, "http://localhost/v3/")
self.assertEqual(entry.title, "Version v3.0")
self.assertEqual(entry.updated, "2013-07-23T11:33:21Z")
self.assertEqual(len(entry.content), 1)
self.assertEqual(entry.content[0].value, "Version v3.0 EXPERIMENTAL (2013-07-23T11:33:21Z)")
self.assertEqual(len(entry.links), 3)
self.assertEqual(entry.links[0]["href"], "http://localhost/v3/")
self.assertEqual(entry.links[0]["rel"], "self")
self.assertEqual(
entry.links[1], {"href": EXP_LINKS["v3.0"]["pdf"], "type": "application/pdf", "rel": "describedby"}
)
self.assertEqual(
entry.links[2],
{"href": EXP_LINKS["v3.0"]["wadl"], "type": "application/vnd.sun.wadl+xml", "rel": "describedby"},
)
示例9: test_show_image_no_metadata_key
def test_show_image_no_metadata_key(self):
serializer = images.ImageTemplate()
fixture = {
'image': {
'id': 1,
'name': 'Image1',
'created': self.TIMESTAMP,
'updated': self.TIMESTAMP,
'status': 'ACTIVE',
'server': {
'id': self.SERVER_UUID,
'links': [
{
'href': self.SERVER_HREF,
'rel': 'self',
},
{
'href': self.SERVER_BOOKMARK,
'rel': 'bookmark',
},
],
},
'links': [
{
'href': self.IMAGE_HREF % 1,
'rel': 'self',
},
{
'href': self.IMAGE_BOOKMARK % 1,
'rel': 'bookmark',
},
],
},
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, 'image')
image_dict = fixture['image']
for key in ['name', 'id', 'updated', 'created', 'status']:
self.assertEqual(root.get(key), str(image_dict[key]))
link_nodes = root.findall('{0}link'.format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(image_dict['links']):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
meta_nodes = root.findall('{0}meta'.format(ATOMNS))
self.assertEqual(len(meta_nodes), 0)
server_root = root.find('{0}server'.format(NS))
self.assertEqual(server_root.get('id'), image_dict['server']['id'])
link_nodes = server_root.findall('{0}link'.format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(image_dict['server']['links']):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
示例10: test_index
def test_index(self):
serializer = flavors.MinimalFlavorsTemplate()
fixture = {
"flavors": [
next(self.flavors),
next(self.flavors),
],
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, 'flavors_index')
flavor_elems = root.findall('{0}flavor'.format(NS))
self.assertEqual(len(flavor_elems), 2)
for i, flavor_elem in enumerate(flavor_elems):
flavor_dict = fixture['flavors'][i]
for key in ['name', 'id']:
self.assertEqual(flavor_elem.get(key), str(flavor_dict[key]))
link_nodes = flavor_elem.findall('{0}link'.format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(flavor_dict['links']):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
示例11: test_show_handles_integers
def test_show_handles_integers(self):
serializer = flavors.FlavorTemplate()
fixture = {
"flavor": {
"id": 12,
"name": "asdf",
"ram": 256,
"disk": 10,
"vcpus": "",
"links": [
{"rel": "self", "href": "http://localhost/v2/fake/flavors/12"},
{"rel": "bookmark", "href": "http://localhost/fake/flavors/12"},
],
}
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, "flavor")
flavor_dict = fixture["flavor"]
for key in ["name", "id", "ram", "disk"]:
self.assertEqual(root.get(key), str(flavor_dict[key]))
link_nodes = root.findall("{0}link".format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(flavor_dict["links"]):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
示例12: test_detail
def test_detail(self):
serializer = flavors.FlavorsTemplate()
fixture = {
"flavors": [
{
"id": "23",
"name": "flavor 23",
"ram": "512",
"disk": "20",
"vcpus": "",
'extra_specs': {'ecus_per_vcpu:': '1', 'nbs': 'true'},
"links": [
{
"rel": "self",
"href": "http://localhost/v2/fake/flavors/23",
},
{
"rel": "bookmark",
"href": "http://localhost/fake/flavors/23",
},
],
},
{
"id": "13",
"name": "flavor 13",
"ram": "256",
"disk": "10",
"vcpus": "",
'extra_specs': {'ecus_per_vcpu:': '1', 'nbs': 'true'},
"links": [
{
"rel": "self",
"href": "http://localhost/v2/fake/flavors/13",
},
{
"rel": "bookmark",
"href": "http://localhost/fake/flavors/13",
},
],
},
],
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, 'flavors')
flavor_elems = root.findall('{0}flavor'.format(NS))
self.assertEqual(len(flavor_elems), 2)
for i, flavor_elem in enumerate(flavor_elems):
flavor_dict = fixture['flavors'][i]
for key in ['name', 'id', 'ram', 'disk']:
self.assertEqual(flavor_elem.get(key), str(flavor_dict[key]))
link_nodes = flavor_elem.findall('{0}link'.format(ATOMNS))
self.assertEqual(len(link_nodes), 2)
for i, link in enumerate(flavor_dict['links']):
for key, value in link.items():
self.assertEqual(link_nodes[i].get(key), value)
示例13: test_index
def test_index(self):
serializer = limits.LimitsTemplate()
fixture = {
"limits": {
"rate": [
{
"uri": "*",
"regex": ".*",
"limit": [
{
"value": 10,
"verb": "POST",
"remaining": 2,
"unit": "MINUTE",
"next-available": "2011-12-15T22:42:45Z",
}
],
},
{
"uri": "*/servers",
"regex": "^/servers",
"limit": [
{
"value": 50,
"verb": "POST",
"remaining": 10,
"unit": "DAY",
"next-available": "2011-12-15T22:42:45Z",
}
],
},
],
"absolute": {"maxServerMeta": 1, "maxImageMeta": 1, "maxPersonality": 5, "maxPersonalitySize": 10240},
}
}
output = serializer.serialize(fixture)
root = etree.XML(output)
xmlutil.validate_schema(root, "limits")
# verify absolute limits
absolutes = root.xpath("ns:absolute/ns:limit", namespaces=NS)
self.assertEqual(len(absolutes), 4)
for limit in absolutes:
name = limit.get("name")
value = limit.get("value")
self.assertEqual(value, str(fixture["limits"]["absolute"][name]))
# verify rate limits
rates = root.xpath("ns:rates/ns:rate", namespaces=NS)
self.assertEqual(len(rates), 2)
for i, rate in enumerate(rates):
for key in ["uri", "regex"]:
self.assertEqual(rate.get(key), str(fixture["limits"]["rate"][i][key]))
rate_limits = rate.xpath("ns:limit", namespaces=NS)
self.assertEqual(len(rate_limits), 1)
for j, limit in enumerate(rate_limits):
for key in ["verb", "value", "remaining", "unit", "next-available"]:
self.assertEqual(limit.get(key), str(fixture["limits"]["rate"][i]["limit"][j][key]))
示例14: test_index_zero_images
def test_index_zero_images(self):
serializer = images.MinimalImagesTemplate()
del self.fixture_dict['images']
output = serializer.serialize(self.fixture_dict)
root = etree.XML(output)
xmlutil.validate_schema(root, 'images_index')
image_elems = root.findall('{0}image'.format(NS))
self.assertEqual(len(image_elems), 0)
示例15: test_validate_schema
def test_validate_schema(self):
xml = '''<?xml version='1.0' encoding='UTF-8'?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="key6">value6</meta><meta key="key4">value4</meta>
</metadata>
'''
xmlutil.validate_schema(xml, 'metadata')
# No way to test the return value of validate_schema.
# It just raises an exception when something is wrong.
self.assertTrue(True)