Code

Forward-porting of fixes from the maintenance branch.
[roundup.git] / test / test_mysql.py
index 5825ff3050078e8d926362a89e46d10d926d8cf1..1388d47e8df0401009eaa265dc871169da67c5f0 100644 (file)
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: test_mysql.py,v 1.3 2003-11-02 08:44:17 richard Exp $ 
+# $Id: test_mysql.py,v 1.6 2003-11-14 00:11:19 richard Exp $ 
 
 import unittest, os, shutil, time, imp
 
 from roundup.hyperdb import DatabaseError
 from roundup import init, backends
 
-from db_test_base import DBTest, ROTest, config, SchemaTest, nodbconfig, \
-    ClassicInitTest
+from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
+
+
+# Mysql connection data
+config.MYSQL_DBHOST = 'localhost'
+config.MYSQL_DBUSER = 'rounduptest'
+config.MYSQL_DBPASSWORD = 'rounduptest'
+config.MYSQL_DBNAME = 'rounduptest'
+config.MYSQL_DATABASE = (config.MYSQL_DBHOST, config.MYSQL_DBUSER,
+    config.MYSQL_DBPASSWORD, config.MYSQL_DBNAME)
+
+class nodbconfig(config):
+    MYSQL_DATABASE = (config.MYSQL_DBHOST, config.MYSQL_DBUSER, config.MYSQL_DBPASSWORD)
 
 class mysqlOpener:
     if hasattr(backends, 'mysql'):
@@ -31,6 +42,9 @@ class mysqlOpener:
 
     def tearDown(self):
         self.db.close()
+        self.nuke_database()
+
+    def nuke_database(self):
         self.module.db_nuke(config)
 
 class mysqlDBTest(mysqlOpener, DBTest):
@@ -42,55 +56,20 @@ class mysqlROTest(mysqlOpener, ROTest):
 class mysqlSchemaTest(mysqlOpener, SchemaTest):
     pass
 
-class mysqlClassicInitTest(ClassicInitTest):
+class mysqlClassicInitTest(mysqlOpener, ClassicInitTest):
     backend = 'mysql'
-
-    def testCreation(self):
-        ae = self.assertEqual
-
-        # create the instance
-        init.install(self.dirname, 'templates/classic')
-        init.write_select_db(self.dirname, self.backend)
-        f = open(os.path.join(self.dirname, 'config.py'), 'a')
-        try:
-            f.write('''
+    extra_config = '''
 MYSQL_DBHOST = 'localhost'
 MYSQL_DBUSER = 'rounduptest'
 MYSQL_DBPASSWORD = 'rounduptest'
 MYSQL_DBNAME = 'rounduptest'
 MYSQL_DATABASE = (MYSQL_DBHOST, MYSQL_DBUSER, MYSQL_DBPASSWORD, MYSQL_DBNAME)
-            ''')
-        finally:
-            f.close()
-        init.initialise(self.dirname, 'sekrit')
-
-        # check we can load the package
-        instance = imp.load_package(self.dirname, self.dirname)
-
-        # and open the database
-        db = instance.open()
-
-        # check the basics of the schema and initial data set
-        l = db.priority.list()
-        ae(l, ['1', '2', '3', '4', '5'])
-        l = db.status.list()
-        ae(l, ['1', '2', '3', '4', '5', '6', '7', '8'])
-        l = db.keyword.list()
-        ae(l, [])
-        l = db.user.list()
-        ae(l, ['1', '2'])
-        l = db.msg.list()
-        ae(l, [])
-        l = db.file.list()
-        ae(l, [])
-        l = db.issue.list()
-        ae(l, [])
-
+'''
     if hasattr(backends, 'mysql'):
         from roundup.backends import mysql as module
     def tearDown(self):
         ClassicInitTest.tearDown(self)
-        self.module.db_nuke(config)
+        self.nuke_database()
 
 def test_suite():
     suite = unittest.TestSuite()
@@ -101,10 +80,11 @@ def test_suite():
     try:
         # Check if we can run mysql tests
         import MySQLdb
-        db = mysql.Database(nodbconfig, 'admin')
+        db = mysql.Database(config, 'admin')
         db.conn.select_db(config.MYSQL_DBNAME)
         db.sql("SHOW TABLES");
         tables = db.sql_fetchall()
+        # TODO: reinstate the check here
         if 0: #tables:
             # Database should be empty. We don't dare to delete any data
             raise DatabaseError, "Database %s contains tables"%\