BIND 10 trac917, updated. bccc91bbd2496b87b408ebff3cd9c6880f952b1c [917] add various testcases and replace literals in the testcases with the constant variable

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Nov 10 09:11:17 UTC 2011


The branch, trac917 has been updated
       via  bccc91bbd2496b87b408ebff3cd9c6880f952b1c (commit)
       via  88147da513fdb22eb4e430390746f36c96304c7e (commit)
       via  567f822d4758d13b84161d67118ac1bce08b4c47 (commit)
       via  e3406364189d62ba54d85c3d23b40cefd02af584 (commit)
      from  489a53541118413b38865c8a3cf84b24b8b7dfe2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bccc91bbd2496b87b408ebff3cd9c6880f952b1c
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Thu Nov 10 09:07:51 2011 +0000

    [917] add various testcases and replace literals in the testcases with
    the constant variable

commit 88147da513fdb22eb4e430390746f36c96304c7e
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Thu Nov 10 09:05:23 2011 +0000

    [917] change the evaluation of the requested URI path

commit 567f822d4758d13b84161d67118ac1bce08b4c47
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Thu Nov 10 07:20:03 2011 +0000

    [917] fix wrong hyper links in anchor tags, add checks of that into the unittest

commit e3406364189d62ba54d85c3d23b40cefd02af584
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Thu Nov 10 05:29:19 2011 +0000

    [917] support conversion of the item_type and item_format in the
    specfile into the date, time and dataTime datatypes in XSD

-----------------------------------------------------------------------

Summary of changes:
 src/bin/stats/stats_httpd.py.in             |   31 ++++++---
 src/bin/stats/tests/b10-stats-httpd_test.py |   91 +++++++++++++++++++++++----
 2 files changed, 99 insertions(+), 23 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in
index 91901bb..8a12d7d 100644
--- a/src/bin/stats/stats_httpd.py.in
+++ b/src/bin/stats/stats_httpd.py.in
@@ -103,14 +103,14 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
             # in case of /bind10/statistics/xxx/YYY/zzz
             if len(path_dirs) >= 5:
                 item_name = path_dirs[4]
-            # in case of /bind10/statistics/xxx/YYY
+            # in case of /bind10/statistics/xxx/YYY ...
             if len(path_dirs) >= 4:
                 module_name = path_dirs[3]
-            if req_path.startswith(XML_URL_PATH):
+            if req_path == '/'.join([XML_URL_PATH] + path_dirs[3:5]):
                 body = self.server.xml_handler(module_name, item_name)
-            elif req_path.startswith(XSD_URL_PATH):
+            elif req_path == '/'.join([XSD_URL_PATH] + path_dirs[3:5]):
                 body = self.server.xsd_handler(module_name, item_name)
-            elif req_path.startswith(XSL_URL_PATH):
+            elif req_path == '/'.join([XSL_URL_PATH] + path_dirs[3:5]):
                 body = self.server.xsl_handler(module_name, item_name)
             else:
                 if req_path == '/' and 'Host' in self.headers.keys():
@@ -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",
@@ -778,10 +790,7 @@ class StatsHttpd:
         xsd_root = xml.etree.ElementTree.Element( # started with xml:template tag
             "xsl:template",
             attrib={'match': "bind10:statistics"})
-        if module_name is not None:
-            stats_spec2xsl(stats_spec, xsd_root, XML_URL_PATH + '/' + module_name)
-        else:
-            stats_spec2xsl(stats_spec, xsd_root)
+        stats_spec2xsl(stats_spec, xsd_root)
         # The coding conversion is tricky. xml..tostring() of Python 3.2
         # returns bytes (not string) regardless of the coding, while
         # tostring() of Python 3.1 returns a string.  To support both
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index 7ded974..b6847bd 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -317,6 +317,10 @@ class TestHttpHandler(unittest.TestCase):
                                 + url_xhtml + 'table/' + url_trans + 'for-each'
                             itm_fe = dict([ (x.attrib['select'], x) for x in mod_fe[mod].findall(xslpath) ])
                             self.assertTrue(k in itm_fe)
+                            xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                                + url_xhtml + 'a'
+                            itm_a = [ x.attrib['href'] for x in itm_fe[k].findall(xslpath) ]
+                            self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + k in itm_a)
                             for itms in v:
                                 xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
                                     + url_xhtml + 'table/' + url_trans + 'for-each'
@@ -334,6 +338,11 @@ class TestHttpHandler(unittest.TestCase):
                                 + url_xhtml + 'td/' + url_trans + 'value-of'
                             itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
                             self.assertTrue(k in itm_vo)
+                            xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                                + url_xhtml + 'table/' + url_xhtml + 'tr/' \
+                                + url_xhtml + 'td/' + url_xhtml + 'a'
+                            itm_a = [ x.attrib['href'] for x in mod_fe[mod].findall(xslpath) ]
+                            self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + k in itm_a)
             elif item is None:
                 xslpath = url_trans + 'template/' + url_xhtml + 'table/' + url_trans + 'for-each'
                 mod_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
@@ -344,6 +353,10 @@ class TestHttpHandler(unittest.TestCase):
                             + url_xhtml + 'table/' + url_trans + 'for-each'
                         itm_fe = dict([ (x.attrib['select'], x) for x in mod_fe[mod].findall(xslpath) ])
                         self.assertTrue(k in itm_fe)
+                        xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                            + url_xhtml + 'a'
+                        itm_a = [ x.attrib['href'] for x in itm_fe[k].findall(xslpath) ]
+                        self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + k in itm_a)
                         for itms in v:
                             xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
                                 + url_xhtml + 'table/' + url_trans + 'for-each'
@@ -361,6 +374,11 @@ class TestHttpHandler(unittest.TestCase):
                             + url_xhtml + 'td/' + url_trans + 'value-of'
                         itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
                         self.assertTrue(k in itm_vo)
+                        xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                            + url_xhtml + 'table/' + url_xhtml + 'tr/' \
+                            + url_xhtml + 'td/' + url_xhtml + 'a'
+                        itm_a = [ x.attrib['href'] for x in mod_fe[mod].findall(xslpath) ]
+                        self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + k in itm_a)
             else:
                 xslpath = url_trans + 'template/' + url_xhtml + 'table/' + url_trans + 'for-each'
                 mod_fe = dict([ (x.attrib['select'], x) for x in root.findall(xslpath) ])
@@ -370,6 +388,10 @@ class TestHttpHandler(unittest.TestCase):
                         + url_xhtml + 'table/' + url_trans + 'for-each'
                     itm_fe = dict([ (x.attrib['select'], x) for x in mod_fe[mod].findall(xslpath) ])
                     self.assertTrue(item in itm_fe)
+                    xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                        + url_xhtml + 'a'
+                    itm_a = [ x.attrib['href'] for x in itm_fe[item].findall(xslpath) ]
+                    self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + item in itm_a)
                     for itms in DUMMY_DATA[mod][item]:
                         xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
                             + url_xhtml + 'table/' + url_trans + 'for-each'
@@ -387,6 +409,11 @@ class TestHttpHandler(unittest.TestCase):
                         + url_xhtml + 'td/' + url_trans + 'value-of'
                     itm_vo = [ x.attrib['select'] for x in mod_fe[mod].findall(xslpath) ]
                     self.assertTrue(item in itm_vo)
+                    xslpath = url_xhtml + 'tr/' + url_xhtml + 'td/' \
+                        + url_xhtml + 'table/' + url_xhtml + 'tr/' \
+                        + url_xhtml + 'td/' + url_xhtml + 'a'
+                    itm_a = [ x.attrib['href'] for x in mod_fe[mod].findall(xslpath) ]
+                    self.assertTrue(stats_httpd.XML_URL_PATH + '/' + mod + '/' + item in itm_a)
 
         # URL is '/bind10/statistics/xsl'
         check_XSL_URL_PATH(mod=None, item=None)
@@ -423,61 +450,83 @@ class TestHttpHandler(unittest.TestCase):
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
+        self.client._http_vsn_str = 'HTTP/1.0'
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + 'Auth') # with no slash
+        self.client.endheaders()
+        response = self.client.getresponse()
+        self.assertEqual(response.status, 404)
+
+        # 200 ok
+        self.client._http_vsn_str = 'HTTP/1.0'
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '/')
+        self.client.endheaders()
+        response = self.client.getresponse()
+        self.assertEqual(response.status, 200)
+        self.client._http_vsn_str = 'HTTP/1.0'
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '#foo')
+        self.client.endheaders()
+        response = self.client.getresponse()
+        self.assertEqual(response.status, 200)
+        self.client._http_vsn_str = 'HTTP/1.0'
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '?foo=bar')
+        self.client.endheaders()
+        response = self.client.getresponse()
+        self.assertEqual(response.status, 200)
 
         # 404 NotFound (too long path)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xml/Boss/boot_time/a')
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '/Boss/boot_time/a')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
 
         # 404 NotFound (nonexistent module name)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xml/Foo')
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '/Foo')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsd/Foo')
+        self.client.putrequest('GET', stats_httpd.XSD_URL_PATH + '/Foo')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsl/Foo')
+        self.client.putrequest('GET', stats_httpd.XSL_URL_PATH + '/Foo')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
 
         # 404 NotFound (nonexistent item name)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xml/Foo/bar')
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '/Foo/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsd/Foo/bar')
+        self.client.putrequest('GET', stats_httpd.XSD_URL_PATH + '/Foo/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsl/Foo/bar')
+        self.client.putrequest('GET', stats_httpd.XSL_URL_PATH + '/Foo/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
 
         # 404 NotFound (existent module but nonexistent item name)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xml/Auth/bar')
+        self.client.putrequest('GET', stats_httpd.XML_URL_PATH + '/Auth/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsd/Auth/bar')
+        self.client.putrequest('GET', stats_httpd.XSD_URL_PATH + '/Auth/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
         self.client._http_vsn_str = 'HTTP/1.0'
-        self.client.putrequest('GET', '/bind10/statistics/xsl/Auth/bar')
+        self.client.putrequest('GET', stats_httpd.XSL_URL_PATH + '/Auth/bar')
         self.client.endheaders()
         response = self.client.getresponse()
         self.assertEqual(response.status, 404)
@@ -932,7 +981,7 @@ class TestStatsHttpd(unittest.TestCase):
                             ] } }
         xml_body1 = self.stats_httpd.open_template(
             stats_httpd.XML_TEMPLATE_LOCATION).substitute(
-            xml_string='<bind10:statistics xmlns:bind10="http://bind10.isc.org/bind10" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://bind10.isc.org/bind10 /bind10/statistics/xsd"><Dummy><foo>bar</foo><foo2><foo2-1><foo2-1-1>bar1</foo2-1-1><foo2-1-2>10</foo2-1-2><foo2-1-3>9</foo2-1-3></foo2-1><foo2-1><foo2-1-1>bar2</foo2-1-1><foo2-1-2>8</foo2-1-2><foo2-1-3>7</foo2-1-3></foo2-1></foo2></Dummy></bind10:statistics>',
+            xml_string='<bind10:statistics xmlns:bind10="http://bind10.isc.org/bind10" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://bind10.isc.org/bind10 ' + stats_httpd.XSD_URL_PATH + '"><Dummy><foo>bar</foo><foo2><foo2-1><foo2-1-1>bar1</foo2-1-1><foo2-1-2>10</foo2-1-2><foo2-1-3>9</foo2-1-3></foo2-1><foo2-1><foo2-1-1>bar2</foo2-1-1><foo2-1-2>8</foo2-1-2><foo2-1-3>7</foo2-1-3></foo2-1></foo2></Dummy></bind10:statistics>',
             xsl_url_path=stats_httpd.XSL_URL_PATH)
         xml_body2 = self.stats_httpd.xml_handler()
         self.assertEqual(type(xml_body1), str)
@@ -1030,6 +1079,15 @@ class TestStatsHttpd(unittest.TestCase):
                         "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",
                         "item_optional": False,
@@ -1083,7 +1141,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"><annot
 ation><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"><ann
 otation><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)
@@ -1099,6 +1157,15 @@ class TestStatsHttpd(unittest.TestCase):
                         "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",
                         "item_optional": False,




More information about the bind10-changes mailing list