Browse Source

[trac547] added more tests into test_open_template
- checking the type of object returned from open_template method
- checking the string values replaced by the substitute method in string.Template

Naoki Kambe 14 years ago
parent
commit
b1cb4c4a14
1 changed files with 26 additions and 3 deletions
  1. 26 3
      src/bin/stats/tests/b10-stats-httpd_test.py

+ 26 - 3
src/bin/stats/tests/b10-stats-httpd_test.py

@@ -338,9 +338,32 @@ class TestStatsHttpd(unittest.TestCase):
 
 
     def test_open_template(self):
     def test_open_template(self):
         # successful conditions
         # successful conditions
-        self.stats_httpd.open_template(stats_httpd.XML_TEMPLATE_LOCATION)
-        self.stats_httpd.open_template(stats_httpd.XSD_TEMPLATE_LOCATION)
-        self.stats_httpd.open_template(stats_httpd.XSL_TEMPLATE_LOCATION)
+        tmpl = self.stats_httpd.open_template(stats_httpd.XML_TEMPLATE_LOCATION)
+        self.assertTrue(isinstance(tmpl, string.Template))
+        opts = dict(
+            xml_string="<dummy></dummy>",
+            xsd_namespace="http://host/path/to/",
+            xsd_url_path="/path/to/",
+            xsl_url_path="/path/to/")
+        lines = tmpl.substitute(opts)
+        for n in opts:
+            self.assertTrue(lines.find(opts[n])>0)
+        tmpl = self.stats_httpd.open_template(stats_httpd.XSD_TEMPLATE_LOCATION)
+        self.assertTrue(isinstance(tmpl, string.Template))
+        opts = dict(
+            xsd_string="<dummy></dummy>",
+            xsd_namespace="http://host/path/to/")
+        lines = tmpl.substitute(opts)
+        for n in opts:
+            self.assertTrue(lines.find(opts[n])>0)
+        tmpl = self.stats_httpd.open_template(stats_httpd.XSL_TEMPLATE_LOCATION)
+        self.assertTrue(isinstance(tmpl, string.Template))
+        opts = dict(
+            xsl_string="<dummy></dummy>",
+            xsd_namespace="http://host/path/to/")
+        lines = tmpl.substitute(opts)
+        for n in opts:
+            self.assertTrue(lines.find(opts[n])>0)
         # unsuccessful condition
         # unsuccessful condition
         self.assertRaises(
         self.assertRaises(
             IOError,
             IOError,