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, FilterCacheTest
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 ConcurrentDBTest.setUp(self)
72 def tearDown(self):
73 ConcurrentDBTest.tearDown(self)
74 self.nuke_database()
76 class mysqlFilterCacheTest(mysqlOpener, FilterCacheTest):
77 backend = 'mysql'
78 def setUp(self):
79 mysqlOpener.setUp(self)
80 FilterCacheTest.setUp(self)
81 def tearDown(self):
82 FilterCacheTest.tearDown(self)
83 self.nuke_database()
85 from session_common import RDBMSTest
86 class mysqlSessionTest(mysqlOpener, RDBMSTest):
87 def setUp(self):
88 mysqlOpener.setUp(self)
89 RDBMSTest.setUp(self)
90 def tearDown(self):
91 RDBMSTest.tearDown(self)
92 mysqlOpener.tearDown(self)
94 def test_suite():
95 suite = unittest.TestSuite()
96 if not have_backend('mysql'):
97 print "Skipping mysql tests"
98 return suite
100 import MySQLdb
101 try:
102 # Check if we can connect to the server.
103 # use db_exists() to make a connection, ignore it's return value
104 mysqlOpener.module.db_exists(config)
105 except (MySQLdb.MySQLError, DatabaseError), msg:
106 print "Skipping mysql tests (%s)"%msg
107 else:
108 print 'Including mysql tests'
109 suite.addTest(unittest.makeSuite(mysqlDBTest))
110 suite.addTest(unittest.makeSuite(mysqlROTest))
111 suite.addTest(unittest.makeSuite(mysqlSchemaTest))
112 suite.addTest(unittest.makeSuite(mysqlClassicInitTest))
113 suite.addTest(unittest.makeSuite(mysqlSessionTest))
114 suite.addTest(unittest.makeSuite(mysqlConcurrencyTest))
115 suite.addTest(unittest.makeSuite(mysqlFilterCacheTest))
116 return suite
118 if __name__ == '__main__':
119 runner = unittest.TextTestRunner()
120 unittest.main(testRunner=runner)
122 # vim: set et sts=4 sw=4 :