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