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_mysql.py,v 1.15 2004-11-10 22:22:59 richard Exp $
20 import unittest, os, shutil, time, imp
22 from roundup.hyperdb import DatabaseError
23 from roundup.backends import get_backend, have_backend
25 from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
26 from db_test_base import ConcurrentDBTest
29 class mysqlOpener:
30 if have_backend('mysql'):
31 module = get_backend('mysql')
33 def setUp(self):
34 self.module.db_nuke(config)
36 def tearDown(self):
37 self.db.close()
38 self.nuke_database()
40 def nuke_database(self):
41 self.module.db_nuke(config)
43 class mysqlDBTest(mysqlOpener, DBTest):
44 def setUp(self):
45 mysqlOpener.setUp(self)
46 DBTest.setUp(self)
48 class mysqlROTest(mysqlOpener, ROTest):
49 def setUp(self):
50 mysqlOpener.setUp(self)
51 ROTest.setUp(self)
53 class mysqlSchemaTest(mysqlOpener, SchemaTest):
54 def setUp(self):
55 mysqlOpener.setUp(self)
56 SchemaTest.setUp(self)
58 class mysqlClassicInitTest(mysqlOpener, ClassicInitTest):
59 backend = 'mysql'
60 def setUp(self):
61 mysqlOpener.setUp(self)
62 ClassicInitTest.setUp(self)
63 def tearDown(self):
64 ClassicInitTest.tearDown(self)
65 self.nuke_database()
67 class mysqlConcurrencyTest(mysqlOpener, ConcurrentDBTest):
68 backend = 'mysql'
69 def setUp(self):
70 mysqlOpener.setUp(self)
71 ClassicInitTest.setUp(self)
72 def tearDown(self):
73 ClassicInitTest.tearDown(self)
74 self.nuke_database()
76 from session_common import RDBMSTest
77 class mysqlSessionTest(mysqlOpener, RDBMSTest):
78 def setUp(self):
79 mysqlOpener.setUp(self)
80 RDBMSTest.setUp(self)
81 def tearDown(self):
82 RDBMSTest.tearDown(self)
83 mysqlOpener.tearDown(self)
85 def test_suite():
86 suite = unittest.TestSuite()
87 if not have_backend('mysql'):
88 print "Skipping mysql tests"
89 return suite
91 import MySQLdb
92 try:
93 # Check if we can connect to the server.
94 # use db_exists() to make a connection, ignore it's return value
95 mysqlOpener.module.db_exists(config)
96 except (MySQLdb.MySQLError, DatabaseError), msg:
97 print "Skipping mysql tests (%s)"%msg
98 else:
99 print 'Including mysql tests'
100 suite.addTest(unittest.makeSuite(mysqlDBTest))
101 suite.addTest(unittest.makeSuite(mysqlROTest))
102 suite.addTest(unittest.makeSuite(mysqlSchemaTest))
103 suite.addTest(unittest.makeSuite(mysqlClassicInitTest))
104 suite.addTest(unittest.makeSuite(mysqlSessionTest))
105 suite.addTest(unittest.makeSuite(mysqlConcurrencyTest))
106 return suite
108 if __name__ == '__main__':
109 runner = unittest.TextTestRunner()
110 unittest.main(testRunner=runner)
112 # vim: set et sts=4 sw=4 :