Commit e3406364 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] support conversion of the item_type and item_format in the

specfile into the date, time and dataTime datatypes in XSD
parent 489a5354
......@@ -575,13 +575,25 @@ class StatsHttpd:
elem.append(complextype)
xsd_elem.append(elem)
else:
# determine the datatype of XSD
# TODO: Should consider other item_format types
datatype = stats_spec["item_type"] \
if stats_spec["item_type"].lower() != 'real' \
else 'float'
if "item_format" in stats_spec:
item_format = stats_spec["item_format"]
if datatype.lower() == 'string' \
and item_format.lower() == 'date-time':
datatype = 'dateTime'
elif datatype.lower() == 'string' \
and (item_format.lower() == 'date' \
or item_format.lower() == 'time'):
datatype = item_format.lower()
elem = xml.etree.ElementTree.Element(
"element",
attrib={
'name' : stats_spec["item_name"],
'type' : stats_spec["item_type"] \
if stats_spec["item_type"].lower() != 'real' \
else 'float',
'type' : datatype,
'minOccurs' : "0" \
if stats_spec["item_optional"] \
else "1",
......
......@@ -1029,6 +1029,15 @@ class TestStatsHttpd(unittest.TestCase):
"item_description": "foo is bar",
"item_title": "Foo"
},
{
"item_name": "hoo_time",
"item_type": "string",
"item_optional": False,
"item_default": "2011-01-01T01:01:01Z",
"item_description": "hoo time",
"item_title": "Hoo Time",
"item_format": "date-time"
},
{
"item_name": "foo2",
"item_type": "list",
......@@ -1083,7 +1092,7 @@ class TestStatsHttpd(unittest.TestCase):
}
xsd_body1 = self.stats_httpd.open_template(
stats_httpd.XSD_TEMPLATE_LOCATION).substitute(
xsd_string='<schema targetNamespace="' + stats_httpd.XSD_NAMESPACE + '" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:bind10="' + stats_httpd.XSD_NAMESPACE + '"><annotation><documentation>XML schema of the statistics data in BIND 10</documentation></annotation><element name="statistics"><annotation><documentation>A set of statistics data</documentation></annotation><complexType><all><element name="Dummy"><complexType><all><element maxOccurs="1" minOccurs="1" name="foo" type="string"><annotation><appinfo>Foo</appinfo><documentation>foo is bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2"><complexType><sequence><element maxOccurs="unbounded" minOccurs="1" name="foo2-1"><complexType><all><element maxOccurs="1" minOccurs="1" name="foo2-1-1" type="string"><annotation><appinfo>Foo2 1 1</appinfo><documentation>Foo bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2-1-2" type="integer"><annotation><appinfo>Foo2 1 2</appinfo><documentation>Foo bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2-1-3" type="integer"><annotation><appinfo>Foo2 1 3</appinfo><documentation>Foo bar</documentation></annotation></element></all></complexType></element></sequence></complexType></element></all></complexType></element></all></complexType></element></schema>')
xsd_string='<schema targetNamespace="' + stats_httpd.XSD_NAMESPACE + '" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:bind10="' + stats_httpd.XSD_NAMESPACE + '"><annotation><documentation>XML schema of the statistics data in BIND 10</documentation></annotation><element name="statistics"><annotation><documentation>A set of statistics data</documentation></annotation><complexType><all><element name="Dummy"><complexType><all><element maxOccurs="1" minOccurs="1" name="foo" type="string"><annotation><appinfo>Foo</appinfo><documentation>foo is bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="hoo_time" type="dateTime"><annotation><appinfo>Hoo Time</appinfo><documentation>hoo time</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2"><complexType><sequence><element maxOccurs="unbounded" minOccurs="1" name="foo2-1"><complexType><all><element maxOccurs="1" minOccurs="1" name="foo2-1-1" type="string"><annotation><appinfo>Foo2 1 1</appinfo><documentation>Foo bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2-1-2" type="integer"><annotation><appinfo>Foo2 1 2</appinfo><documentation>Foo bar</documentation></annotation></element><element maxOccurs="1" minOccurs="1" name="foo2-1-3" type="integer"><annotation><appinfo>Foo2 1 3</appinfo><documentation>Foo bar</documentation></annotation></element></all></complexType></element></sequence></complexType></element></all></complexType></element></all></complexType></element></schema>')
xsd_body2 = self.stats_httpd.xsd_handler()
self.assertEqual(type(xsd_body1), str)
self.assertEqual(type(xsd_body2), str)
......@@ -1098,6 +1107,15 @@ class TestStatsHttpd(unittest.TestCase):
"item_description": "bar is foo",
"item_title": "bar"
},
{
"item_name": "boo_time",
"item_type": "string",
"item_optional": False,
"item_default": "2012-02-02T02:02:02Z",
"item_description": "boo time",
"item_title": "Boo Time",
"item_format": "date-time"
},
{
"item_name": "foo2",
"item_type": "list",
......
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