Commit 7e962271 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] add missing checking the XSD and XSL paths in the XML document

parent 6d5f3400
......@@ -457,9 +457,15 @@ class StatsHttpd:
stats_spec = self.get_stats_spec(module_name, item_name)
stats_data = self.get_stats_data(module_name, item_name)
# make the path xxx/module/item if specified respectively
path_info = ''
if module_name is not None and item_name is not None:
path_info = '/' + module_name + '/' + item_name
elif module_name is not None:
path_info = '/' + module_name
xml_elem = xml.etree.ElementTree.Element(
'bind10:statistics',
attrib={ 'xsi:schemaLocation' : XSD_NAMESPACE + ' ' + XSD_URL_PATH,
attrib={ 'xsi:schemaLocation' : XSD_NAMESPACE + ' ' + XSD_URL_PATH + path_info,
'xmlns:bind10' : XSD_NAMESPACE,
'xmlns:xsi' : "http://www.w3.org/2001/XMLSchema-instance" })
stats_data2xml(stats_spec, stats_data, xml_elem)
......@@ -473,7 +479,7 @@ class StatsHttpd:
encoding='us-ascii')
self.xml_body = self.open_template(XML_TEMPLATE_LOCATION).substitute(
xml_string=xml_string,
xsl_url_path=XSL_URL_PATH)
xsl_url_path=XSL_URL_PATH + path_info)
assert self.xml_body is not None
return self.xml_body
......
......@@ -146,12 +146,23 @@ class TestHttpHandler(unittest.TestCase):
self.assertEqual(response.getheader("Content-type"), "text/xml")
self.assertTrue(int(response.getheader("Content-Length")) > 0)
self.assertEqual(response.status, 200)
xml_doctype = response.readline().decode()
xsl_doctype = response.readline().decode()
self.assertTrue(len(xml_doctype) > 0)
self.assertTrue(len(xsl_doctype) > 0)
root = xml.etree.ElementTree.parse(response).getroot()
self.assertTrue(root.tag.find('statistics') > 0)
for (k,v) in root.attrib.items():
if k.find('schemaLocation') > 0:
self.assertEqual(v, stats_httpd.XSD_NAMESPACE + ' ' + stats_httpd.XSD_URL_PATH)
schema_loc = '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'
if item is None and mod is None:
# check the path of XSD
self.assertEqual(root.attrib[schema_loc],
stats_httpd.XSD_NAMESPACE + ' '
+ stats_httpd.XSD_URL_PATH)
# check the path of XSL
self.assertTrue(xsl_doctype.startswith(
'<?xml-stylesheet type="text/xsl" href="' +
stats_httpd.XSL_URL_PATH
+ '"?>'))
for m in DUMMY_DATA:
for k in DUMMY_DATA[m].keys():
self.assertIsNotNone(root.find(m + '/' + k))
......@@ -161,6 +172,15 @@ class TestHttpHandler(unittest.TestCase):
for i in v:
self.assertIsNotNone(itm.find('zones/' + i))
elif item is None:
# check the path of XSD
self.assertEqual(root.attrib[schema_loc],
stats_httpd.XSD_NAMESPACE + ' '
+ stats_httpd.XSD_URL_PATH + '/' + mod)
# check the path of XSL
self.assertTrue(xsl_doctype.startswith(
'<?xml-stylesheet type="text/xsl" href="'
+ stats_httpd.XSL_URL_PATH + '/' + mod
+ '"?>'))
for k in DUMMY_DATA[mod].keys():
self.assertIsNotNone(root.find(k))
itm = root.find(k)
......@@ -169,6 +189,15 @@ class TestHttpHandler(unittest.TestCase):
for i in v:
self.assertIsNotNone(itm.find('zones/' + i))
else:
# check the path of XSD
self.assertEqual(root.attrib[schema_loc],
stats_httpd.XSD_NAMESPACE + ' '
+ stats_httpd.XSD_URL_PATH + '/' + mod + '/' + item)
# check the path of XSL
self.assertTrue(xsl_doctype.startswith(
'<?xml-stylesheet type="text/xsl" href="'
+ stats_httpd.XSL_URL_PATH + '/' + mod + '/' + item
+ '"?>'))
self.assertIsNotNone(root.find(item))
# URL is '/bind10/statistics/xml'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment