Code

make mysql / postgresql work again. beginnings of otk/session store in rdbmses
[roundup.git] / test / test_postgresql.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 # $Id: test_postgresql.py,v 1.5 2004-03-12 04:09:00 richard Exp $ 
20 import unittest
22 from roundup.hyperdb import DatabaseError
24 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
26 # Postgresql connection data
27 # NOTE: THIS MUST BE A LOCAL DATABASE
28 config.POSTGRESQL_DATABASE = {'database': 'rounduptest'}
30 from roundup import backends
31 from roundup.backends.back_postgresql import db_nuke, db_create, db_exists
33 class postgresqlOpener:
34     if hasattr(backends, 'postgresql'):
35         from roundup.backends import postgresql as module
37     def setUp(self):
38         #db_nuke(config, 1)
39         pass
41     def tearDown(self):
42         self.nuke_database()
44     def nuke_database(self):
45         # clear out the database - easiest way is to nuke and re-create it
46         db_nuke(config)
48 class postgresqlDBTest(postgresqlOpener, DBTest):
49     def setUp(self):
50         postgresqlOpener.setUp(self)
51         DBTest.setUp(self)
53     def tearDown(self):
54         DBTest.tearDown(self)
55         postgresqlOpener.tearDown(self)
57     def testFilteringIntervalSort(self):
58         # PostgreSQL sorts NULLs differently to other databases (others
59         # treat it as lower than real values, PG treats it as higher)
60         ae, filt = self.filteringSetup()
61         # ascending should sort None, 1:10, 1d
62         ae(filt(None, {}, ('+','foo'), (None,None)), ['4', '1', '2', '3'])
63         # descending should sort 1d, 1:10, None
64         ae(filt(None, {}, ('-','foo'), (None,None)), ['3', '2', '1', '4'])
66 class postgresqlROTest(postgresqlOpener, ROTest):
67     def setUp(self):
68         postgresqlOpener.setUp(self)
69         ROTest.setUp(self)
71     def tearDown(self):
72         ROTest.tearDown(self)
73         postgresqlOpener.tearDown(self)
75 class postgresqlSchemaTest(postgresqlOpener, SchemaTest):
76     def setUp(self):
77         postgresqlOpener.setUp(self)
78         SchemaTest.setUp(self)
80     def tearDown(self):
81         SchemaTest.tearDown(self)
82         postgresqlOpener.tearDown(self)
84 class postgresqlClassicInitTest(postgresqlOpener, ClassicInitTest):
85     backend = 'postgresql'
86     extra_config = "POSTGRESQL_DATABASE = {'database': 'rounduptest'}"
87     def setUp(self):
88         postgresqlOpener.setUp(self)
89         ClassicInitTest.setUp(self)
91     def tearDown(self):
92         ClassicInitTest.tearDown(self)
93         postgresqlOpener.tearDown(self)
95 def test_suite():
96     suite = unittest.TestSuite()
97     if not hasattr(backends, 'postgresql'):
98         return suite
100     # make sure we start with a clean slate
101     db_nuke(config, 1)
103     # TODO: Check if we can run postgresql tests
104     print 'Including postgresql tests'
105     suite.addTest(unittest.makeSuite(postgresqlDBTest))
106     suite.addTest(unittest.makeSuite(postgresqlROTest))
107     suite.addTest(unittest.makeSuite(postgresqlSchemaTest))
108     suite.addTest(unittest.makeSuite(postgresqlClassicInitTest))
109     return suite