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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 20 20:54:24 CET 2008


Author: bh
Date: 2008-11-20 20:54:24 +0100 (Thu, 20 Nov 2008)
New Revision: 45

Modified:
   trunk/ChangeLog
   trunk/server/osaas/formparser.py
   trunk/server/test/test_formparser.py
Log:
* server/osaas/formparser.py (Record.set_fields): Set missing
optional fields to None in the record.

* server/test/test_formparser.py
(FormParsingTests.test_missing_optional_parameters): New test for
missing optional fields.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-11-20 19:07:19 UTC (rev 44)
+++ trunk/ChangeLog	2008-11-20 19:54:24 UTC (rev 45)
@@ -1,5 +1,14 @@
 2008-11-20  Bernhard Herzog  <bh at intevation.de>
 
+	* server/osaas/formparser.py (Record.set_fields): Set missing
+	optional fields to None in the record.
+
+	* server/test/test_formparser.py
+	(FormParsingTests.test_missing_optional_parameters): New test for
+	missing optional fields.
+
+2008-11-20  Bernhard Herzog  <bh at intevation.de>
+
 	* server/test/test_osasserver.py
 	(OSAASDBServerTests.test_post_with_content_and_filtering): Fix
 	test failure introduced with the preceding changes.

Modified: trunk/server/osaas/formparser.py
===================================================================
--- trunk/server/osaas/formparser.py	2008-11-20 19:07:19 UTC (rev 44)
+++ trunk/server/osaas/formparser.py	2008-11-20 19:54:24 UTC (rev 45)
@@ -53,21 +53,21 @@
                 parsed_form[normalized] = value
 
         for field in fields:
-            value = parsed_form.pop(field.name, None)
-            if value:
+            value = parsed_form.get(field.name)
+            if value is not None:
                 if len(value) == 1:
                     setattr(self, field.name, field.deserialize(value[0]))
                 else:
                     raise FormParserException("only one value allowed"
                                               " for field %r" % field.name)
-        if parsed_form:
-            print "Record.set_fields: ignored fields", parsed_form
+            else:
+                setattr(self, field.name, None)
 
         self._fields.extend(fields)
 
     def validate_fields(self):
         for field in self._fields:
-            if field.required and not hasattr(self, field.name):
+            if field.required and getattr(self, field.name, None) is None:
                 raise FormParserException("formdata is missing required"
                                           " field %r" % field.name)
 

Modified: trunk/server/test/test_formparser.py
===================================================================
--- trunk/server/test/test_formparser.py	2008-11-20 19:07:19 UTC (rev 44)
+++ trunk/server/test/test_formparser.py	2008-11-20 19:54:24 UTC (rev 45)
@@ -111,6 +111,47 @@
                              "formdata is missing required field 'REQUEST'",
                              record.validate_fields)
 
+    def test_missing_optional_parameters(self):
+        # requeststring is missing the optional field "SERVICE"
+        formdata = "&".join(["user=karl", "responsetime=2007-06-01T12:14:16Z",
+                             "wmsidextern=example.com%2Fcgi-bin%2Ffridawms",
+                             "wmsidintern=localhost%2Fcgi-bin%2Fmyfrida",
+                             "requeststring=VERSION=1.1.1%26REQUEST=GetMap"
+                             "%26FORMAT=image%2Fpng%26TRANSPARENT=TRUE"
+                             "%26WIDTH=460%26HEIGHT=348"
+                             "%26EXCEPTIONS=application%2Fvnd.ogc.se_xml"
+                             "%26BGCOLOR=0xffffff%26BBOX=0.0,0.0,460.0,348.0"
+                             "%26LAYERS=gewaesser%26STYLES=%26SRS=EPSG:4326"])
+        record = parse_formdata(formdata)
+        self.check_attributes(parse_formdata(formdata),
+                              user="karl",
+                              responsetime=datetime.datetime(2007, 6, 1,
+                                                             12, 14, 16),
+                              wmsidextern="example.com/cgi-bin/fridawms",
+                              wmsidintern="localhost/cgi-bin/myfrida",
+                              requeststring=("VERSION=1.1.1&REQUEST=GetMap"
+                                             "&FORMAT=image/png"
+                                             "&TRANSPARENT=TRUE"
+                                             "&WIDTH=460&HEIGHT=348"
+                                      "&EXCEPTIONS=application/vnd.ogc.se_xml"
+                                             "&BGCOLOR=0xffffff"
+                                             "&BBOX=0.0,0.0,460.0,348.0"
+                                             "&LAYERS=gewaesser&STYLES="
+                                             "&SRS=EPSG:4326"),
+                              VERSION="1.1.1",
+                              REQUEST="GetMap",
+                              FORMAT="image/png",
+                              TRANSPARENT="TRUE",
+                              WIDTH="460",
+                              HEIGHT="348",
+                              EXCEPTIONS="application/vnd.ogc.se_xml",
+                              BGCOLOR="0xffffff",
+                              BBOX="0.0,0.0,460.0,348.0",
+                              LAYERS="gewaesser",
+                              STYLES="",
+                              SRS="EPSG:4326",
+                              SERVICE=None)
+
     def test_duplicate_parameters(self):
         # The responsetime occurs twice
         formdata = "&".join(["user=karl", "responsetime=2007-06-01T12:14:16Z",



More information about the Osaas-commits mailing list