Code

- Optimisation: Late evaluation of Multilinks (only in rdbms backends):
[roundup.git] / test / test_postgresql.py
index 81ce5dcb5b4b439c697231ddb778ca839c4e0882..eb7104105de465b57ae04e77ac3db8a33ddbffd1 100644 (file)
 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-# 
-# $Id: test_postgresql.py,v 1.6 2004-03-18 01:58:46 richard Exp $ 
+#
+# $Id: test_postgresql.py,v 1.13 2006-08-23 12:57:10 schlatterbeck Exp $
 
 import unittest
 
 from roundup.hyperdb import DatabaseError
 
 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
+from db_test_base import ConcurrentDBTest, FilterCacheTest
 
-# Postgresql connection data
-# NOTE: THIS MUST BE A LOCAL DATABASE
-config.POSTGRESQL_DATABASE = {'database': 'rounduptest'}
-
-from roundup import backends
-from roundup.backends.back_postgresql import db_nuke, db_create, db_exists
+from roundup.backends import get_backend, have_backend
 
 class postgresqlOpener:
-    if hasattr(backends, 'postgresql'):
-        from roundup.backends import postgresql as module
+    if have_backend('postgresql'):
+        module = get_backend('postgresql')
 
     def setUp(self):
-        #db_nuke(config, 1)
         pass
 
     def tearDown(self):
@@ -43,7 +38,7 @@ class postgresqlOpener:
 
     def nuke_database(self):
         # clear out the database - easiest way is to nuke and re-create it
-        db_nuke(config)
+        self.module.db_nuke(config)
 
 class postgresqlDBTest(postgresqlOpener, DBTest):
     def setUp(self):
@@ -54,15 +49,6 @@ class postgresqlDBTest(postgresqlOpener, DBTest):
         DBTest.tearDown(self)
         postgresqlOpener.tearDown(self)
 
-    def testFilteringIntervalSort(self):
-        # PostgreSQL sorts NULLs differently to other databases (others
-        # treat it as lower than real values, PG treats it as higher)
-        ae, filt = self.filteringSetup()
-        # ascending should sort None, 1:10, 1d
-        ae(filt(None, {}, ('+','foo'), (None,None)), ['4', '1', '2', '3'])
-        # descending should sort 1d, 1:10, None
-        ae(filt(None, {}, ('-','foo'), (None,None)), ['3', '2', '1', '4'])
-
 class postgresqlROTest(postgresqlOpener, ROTest):
     def setUp(self):
         postgresqlOpener.setUp(self)
@@ -72,6 +58,26 @@ class postgresqlROTest(postgresqlOpener, ROTest):
         ROTest.tearDown(self)
         postgresqlOpener.tearDown(self)
 
+class postgresqlConcurrencyTest(postgresqlOpener, ConcurrentDBTest):
+    backend = 'postgresql'
+    def setUp(self):
+        postgresqlOpener.setUp(self)
+        ConcurrentDBTest.setUp(self)
+
+    def tearDown(self):
+        ConcurrentDBTest.tearDown(self)
+        postgresqlOpener.tearDown(self)
+
+class postgresqlFilterCacheTest(postgresqlOpener, FilterCacheTest):
+    backend = 'postgresql'
+    def setUp(self):
+        postgresqlOpener.setUp(self)
+        FilterCacheTest.setUp(self)
+
+    def tearDown(self):
+        FilterCacheTest.tearDown(self)
+        postgresqlOpener.tearDown(self)
+
 class postgresqlSchemaTest(postgresqlOpener, SchemaTest):
     def setUp(self):
         postgresqlOpener.setUp(self)
@@ -83,7 +89,6 @@ class postgresqlSchemaTest(postgresqlOpener, SchemaTest):
 
 class postgresqlClassicInitTest(postgresqlOpener, ClassicInitTest):
     backend = 'postgresql'
-    extra_config = "POSTGRESQL_DATABASE = {'database': 'rounduptest'}"
     def setUp(self):
         postgresqlOpener.setUp(self)
         ClassicInitTest.setUp(self)
@@ -103,11 +108,13 @@ class postgresqlSessionTest(postgresqlOpener, RDBMSTest):
 
 def test_suite():
     suite = unittest.TestSuite()
-    if not hasattr(backends, 'postgresql'):
+    if not have_backend('postgresql'):
+        print "Skipping postgresql tests"
         return suite
 
     # make sure we start with a clean slate
-    db_nuke(config, 1)
+    if postgresqlOpener.module.db_exists(config):
+        postgresqlOpener.module.db_nuke(config, 1)
 
     # TODO: Check if we can run postgresql tests
     print 'Including postgresql tests'
@@ -116,5 +123,8 @@ def test_suite():
     suite.addTest(unittest.makeSuite(postgresqlSchemaTest))
     suite.addTest(unittest.makeSuite(postgresqlClassicInitTest))
     suite.addTest(unittest.makeSuite(postgresqlSessionTest))
+    suite.addTest(unittest.makeSuite(postgresqlConcurrencyTest))
+    suite.addTest(unittest.makeSuite(postgresqlFilterCacheTest))
     return suite
 
+# vim: set et sts=4 sw=4 :