[Osaas-commits] r13 - in trunk: . server/osaas server/test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 28 16:08:00 CEST 2007


Author: bh
Date: 2007-08-28 16:07:59 +0200 (Tue, 28 Aug 2007)
New Revision: 13

Modified:
   trunk/ChangeLog
   trunk/server/osaas/config.py
   trunk/server/test/test_config.py
Log:
* server/osaas/config.py (read_database_rules): New function to
read the database rules
(read_config_file): Read the database rules and store then into
opts.db-rules

* server/test/test_config.py (TestConfigParsing_DBRules.config):
Tests for reading the database rules from the config file


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-08-28 13:56:11 UTC (rev 12)
+++ trunk/ChangeLog	2007-08-28 14:07:59 UTC (rev 13)
@@ -1,5 +1,15 @@
 2007-08-28  Bernhard Herzog  <bh at intevation.de>
 
+	* server/osaas/config.py (read_database_rules): New function to
+	read the database rules
+	(read_config_file): Read the database rules and store then into
+	opts.db-rules
+
+	* server/test/test_config.py (TestConfigParsing_DBRules.config):
+	Tests for reading the database rules from the config file
+
+2007-08-28  Bernhard Herzog  <bh at intevation.de>
+
 	* server/osaas/dbbackend.py (DBField, Insertion, DBBackend): New
 	classes implementing the backend.
 	(dbhandler): Removed this dummy implementation

Modified: trunk/server/osaas/config.py
===================================================================
--- trunk/server/osaas/config.py	2007-08-28 13:56:11 UTC (rev 12)
+++ trunk/server/osaas/config.py	2007-08-28 14:07:59 UTC (rev 13)
@@ -9,6 +9,9 @@
 import optparse
 from xml.dom.minidom import parse
 
+from dbbackend import DBField, Insertion
+
+
 class OSAASOption(optparse.Option):
 
     ATTRS = optparse.Option.ATTRS[:]
@@ -42,6 +45,22 @@
                                  " content" % path)
     return value_node.data
 
+def read_database_rules(node):
+    dbnode = find_xml_path_node(node, "OSAASConfig/DBRules/insert")
+    if dbnode is None:
+        return []
+    value_nodes = [node for node in dbnode.childNodes
+                        if node.nodeType == node.ELEMENT_NODE
+                           and node.nodeName == "value"]
+    def asciiattr(node, attr):
+        return node.getAttribute(attr).encode("ascii")
+    return [Insertion(asciiattr(dbnode, "table"),
+                      [DBField(asciiattr(n, "param"),
+                               asciiattr(n, "column"),
+                               asciiattr(n, "type"))
+                       for n in value_nodes])]
+
+
 def read_config_file(filename, opts):
     dom = parse(filename)
     for option in opts.option_list:
@@ -50,3 +69,4 @@
             if value is not None:
                 opts.set_file_option(option.dest,
                                      option.check_value(option.xml_path, value))
+    opts.set_file_option("db_rules", read_database_rules(dom))

Modified: trunk/server/test/test_config.py
===================================================================
--- trunk/server/test/test_config.py	2007-08-28 13:56:11 UTC (rev 12)
+++ trunk/server/test/test_config.py	2007-08-28 14:07:59 UTC (rev 13)
@@ -99,3 +99,46 @@
         self.assertEquals(opts.db_user, "owsdbuser")
         self.assertEquals(opts.db_password, "secret")
         self.assertEquals(opts.db_dsn, "mydsn")
+
+
+class TestConfigParsing_DBRules(ConfigParserTest):
+
+    config = """\
+<?xml version='1.0'?>
+<OSAASConfig>
+  <ErrorLog>/var/log/osaas-error.log</ErrorLog>
+  <DBRules>
+    <insert table='MyOWSAccounting'>
+      <value param='SERVICE' column='service' type='character varying(10)'/>
+      <value param='REQUEST' column='req' type='character varying(10)'/>
+      <value param='BBOX' column='bbox' type='character varying(100)'/>
+      <value param='WIDTH' column='width' type='int'/>
+      <value param='HEIGHT' column='height' type='int'/>
+    </insert>
+  </DBRules>
+</OSAASConfig>
+"""
+
+    def test(self):
+        prog = OSAASServerProgram()
+        opts, rest = prog.parse_options(["--config-file=%s" % self.filename])
+        rules = opts.db_rules
+        self.assertEquals(len(rules), 1)
+        rule = rules[0]
+        # in addition to checking the values, we also check the types
+        # because cx_Oracle is very picky and does not accept unicode
+        # objects as statements even when they only contain ascii
+        # characters
+        self.assertEquals(rule.table, "MyOWSAccounting")
+        self.failUnless(isinstance(rule.table, str))
+        self.assertEquals([(f.parameter, f.column, f.column_type)
+                           for f in rule.fields],
+                          [("SERVICE", "service", "character varying(10)"),
+                           ("REQUEST", "req", "character varying(10)"),
+                           ("BBOX", "bbox", "character varying(100)"),
+                           ("WIDTH", "width", "int"),
+                           ("HEIGHT", "height", "int")])
+        self.assertEquals([(type(f.parameter), type(f.column),
+                            type(f.column_type))
+                           for f in rule.fields],
+                          [(str, str, str)] * 5)



More information about the Osaas-commits mailing list