bh: thuban/test test_postgis_db.py,1.18,1.19

cvs@intevation.de cvs at intevation.de
Mon May 9 20:12:14 CEST 2005


Author: bh

Update of /thubanrepository/thuban/test
In directory doto:/tmp/cvs-serv3514/test

Modified Files:
	test_postgis_db.py 
Log Message:
* Thuban/Model/postgisdb.py (PostGISConnection.connect): Set the
connection to autoconnect.  Fixes RT#3148.

* test/test_postgis_db.py
(TestPostGISSpecialCases.test_simple_error_handling): New test
that attempts to reproduce RT#3148.


Index: test_postgis_db.py
===================================================================
RCS file: /thubanrepository/thuban/test/test_postgis_db.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- test_postgis_db.py	16 Dec 2004 15:18:57 -0000	1.18
+++ test_postgis_db.py	9 May 2005 18:12:11 -0000	1.19
@@ -1,4 +1,4 @@
-# Copyright (C) 2003, 2004 by Intevation GmbH
+# Copyright (C) 2003, 2004, 2005 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -346,6 +346,45 @@
         self.assertEquals([s.ShapeID()
                            for s in store.ShapesInRegion((0, 0, 100,100))],
                           [1])
+
+
+    def test_simple_error_handling(self):
+        """Test some simple error handling.
+
+        If an error happens in, say the SimpleQuery method, a subsequent
+        ReadValue call should still succeed.
+        """
+        conn = psycopg.connect("dbname=%s " % self.dbname
+                               + self.server.connection_string("admin"))
+        cursor = conn.cursor()
+        cursor.execute("CREATE TABLE some_table"
+                       " (gid INTEGER PRIMARY KEY, length float);"
+                       "INSERT INTO some_table VALUES (1, 3.5);")
+        cursor.execute("GRANT SELECT ON some_table TO PUBLIC;")
+        conn.commit()
+        conn.close()
+
+        db = PostGISConnection(dbname = self.dbname,
+                               **self.server.connection_params("user"))
+        table = PostGISTable(db, "some_table", id_column = "gid")
+
+        # trying to compare the length to a string should fail with an
+        # exception.
+        self.assertRaises(psycopg.ProgrammingError,
+                          table.SimpleQuery,
+                          table.Column("length"), "<=", "abc")
+
+        # After the exception, doing a query on the same table should
+        # work. Since it's the same database connection as before, it
+        # can fail if no rollback has been done or the connection isn't
+        # in autocommit mode.  Typical error message is
+        #
+        #     ERROR: current transaction is aborted, commands ignored
+        #     until end of transaction block
+        try:
+            self.assertEquals(table.ReadValue(1, "length"), 3.5)
+        except psycopg.ProgrammingError, val:
+            self.fail("table didn't handle exception properly (%s)" % val)
 
 
 class PostGISStaticTests(unittest.TestCase, support.FloatComparisonMixin):





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)