Code

bec33c4758a57e7cbcd5f76e3fb2fea212d41c70
[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.8 2004-03-25 02:16:08 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
32 class postgresqlOpener:
33     if hasattr(backends, 'postgresql'):
34         from roundup.backends import postgresql as module
36     def setUp(self):
37         #from roundup.backends.back_postgresql import db_nuke
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         from roundup.backends.back_postgresql import db_nuke
47         db_nuke(config)
49 class postgresqlDBTest(postgresqlOpener, DBTest):
50     def setUp(self):
51         postgresqlOpener.setUp(self)
52         DBTest.setUp(self)
54     def tearDown(self):
55         DBTest.tearDown(self)
56         postgresqlOpener.tearDown(self)
58     def testFilteringIntervalSort(self):
59         # PostgreSQL sorts NULLs differently to other databases (others
60         # treat it as lower than real values, PG treats it as higher)
61         ae, filt = self.filteringSetup()
62         # ascending should sort None, 1:10, 1d
63         ae(filt(None, {}, ('+','foo'), (None,None)), ['4', '1', '2', '3'])
64         # descending should sort 1d, 1:10, None
65         ae(filt(None, {}, ('-','foo'), (None,None)), ['3', '2', '1', '4'])
67 class postgresqlROTest(postgresqlOpener, ROTest):
68     def setUp(self):
69         postgresqlOpener.setUp(self)
70         ROTest.setUp(self)
72     def tearDown(self):
73         ROTest.tearDown(self)
74         postgresqlOpener.tearDown(self)
76 class postgresqlSchemaTest(postgresqlOpener, SchemaTest):
77     def setUp(self):
78         postgresqlOpener.setUp(self)
79         SchemaTest.setUp(self)
81     def tearDown(self):
82         SchemaTest.tearDown(self)
83         postgresqlOpener.tearDown(self)
85 class postgresqlClassicInitTest(postgresqlOpener, ClassicInitTest):
86     backend = 'postgresql'
87     extra_config = "POSTGRESQL_DATABASE = {'database': 'rounduptest'}"
88     def setUp(self):
89         postgresqlOpener.setUp(self)
90         ClassicInitTest.setUp(self)
92     def tearDown(self):
93         ClassicInitTest.tearDown(self)
94         postgresqlOpener.tearDown(self)
96 from session_common import RDBMSTest
97 class postgresqlSessionTest(postgresqlOpener, RDBMSTest):
98     def setUp(self):
99         postgresqlOpener.setUp(self)
100         RDBMSTest.setUp(self)
101     def tearDown(self):
102         RDBMSTest.tearDown(self)
103         postgresqlOpener.tearDown(self)
105 def test_suite():
106     suite = unittest.TestSuite()
107     if not hasattr(backends, 'postgresql'):
108         print "Skipping postgresql tests"
109         return suite
111     # make sure we start with a clean slate
112     from roundup.backends.back_postgresql import db_nuke
113     db_nuke(config, 1)
115     # TODO: Check if we can run postgresql tests
116     print 'Including postgresql tests'
117     suite.addTest(unittest.makeSuite(postgresqlDBTest))
118     suite.addTest(unittest.makeSuite(postgresqlROTest))
119     suite.addTest(unittest.makeSuite(postgresqlSchemaTest))
120     suite.addTest(unittest.makeSuite(postgresqlClassicInitTest))
121     suite.addTest(unittest.makeSuite(postgresqlSessionTest))
122     return suite