Mercurial > p > roundup > code
comparison test/test_db.py @ 1433:8429095241d7
mysql tests will not be run if there is no chance of passing.
Notes about mysql backend added
| author | Andrey Lebedev <kedder@users.sourceforge.net> |
|---|---|
| date | Sat, 15 Feb 2003 14:26:38 +0000 |
| parents | 6883852e9b15 |
| children | b953750bdc04 |
comparison
equal
deleted
inserted
replaced
| 1432:f7b41db155d2 | 1433:8429095241d7 |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 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" | 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, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: test_db.py,v 1.69 2003-02-08 15:31:28 kedder Exp $ | 18 # $Id: test_db.py,v 1.70 2003-02-15 14:26:38 kedder Exp $ |
| 19 | 19 |
| 20 import unittest, os, shutil, time | 20 import unittest, os, shutil, time |
| 21 | 21 |
| 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 23 Interval, DatabaseError, Boolean, Number | 23 Interval, DatabaseError, Boolean, Number |
| 63 FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom' | 63 FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom' |
| 64 ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow' | 64 ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow' |
| 65 ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow' | 65 ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow' |
| 66 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' | 66 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' |
| 67 EMAIL_SIGNATURE_POSITION = 'bottom' | 67 EMAIL_SIGNATURE_POSITION = 'bottom' |
| 68 # Mysql connection data | |
| 69 MYSQL_DBHOST = 'localhost' | |
| 70 MYSQL_DBUSER = 'rounduptest' | |
| 71 MYSQL_DBPASSWORD = 'rounduptest' | |
| 72 MYSQL_DBNAME = 'rounduptest' | |
| 73 MYSQL_DATABASE = (MYSQL_DBHOST, MYSQL_DBUSER, MYSQL_DBPASSWORD, MYSQL_DBNAME) | |
| 74 | |
| 75 class nodbconfig(config): | |
| 76 MYSQL_DATABASE = (config.MYSQL_DBHOST, config.MYSQL_DBUSER, config.MYSQL_DBPASSWORD) | |
| 68 | 77 |
| 69 class anydbmDBTestCase(MyTestCase): | 78 class anydbmDBTestCase(MyTestCase): |
| 70 def setUp(self): | 79 def setUp(self): |
| 71 from roundup.backends import anydbm | 80 from roundup.backends import anydbm |
| 72 # remove previous test, ignore errors | 81 # remove previous test, ignore errors |
| 713 setupSchema(db, 1, gadfly) | 722 setupSchema(db, 1, gadfly) |
| 714 db.close() | 723 db.close() |
| 715 self.db = gadfly.Database(config) | 724 self.db = gadfly.Database(config) |
| 716 setupSchema(self.db, 0, gadfly) | 725 setupSchema(self.db, 0, gadfly) |
| 717 | 726 |
| 718 | |
| 719 # XXX to fix the mysql tests... | |
| 720 # From: Andrey Lebedev <andrey@micro.lt> | |
| 721 # I believe we can DROP DATABASE <dbname> and then CREATE DATABASE | |
| 722 # <dbname>.. it's an easiest way. This will work if db user has all | |
| 723 # privileges on database. | |
| 724 # Another way - to perform "SHOW TABLES" SQL and then perform DROP TABLE | |
| 725 # <tblname> on each table... | |
| 726 class mysqlDBTestCase(anydbmDBTestCase): | 727 class mysqlDBTestCase(anydbmDBTestCase): |
| 727 def setUp(self): | 728 def setUp(self): |
| 728 from roundup.backends import mysql | 729 from roundup.backends import mysql |
| 729 # remove previous test, ignore errors | 730 # remove previous test, ignore errors |
| 730 if os.path.exists(config.DATABASE): | 731 if os.path.exists(config.DATABASE): |
| 731 shutil.rmtree(config.DATABASE) | 732 shutil.rmtree(config.DATABASE) |
| 732 config.MYSQL_DATABASE = ('localhost', 'rounduptest', 'rounduptest', | 733 os.makedirs(config.DATABASE + '/files') |
| 733 'rounduptest') | 734 # open database for testing |
| 734 os.makedirs(config.DATABASE + '/files') | 735 self.db = mysql.Database(config, 'admin') |
| 735 # open database for cleaning | 736 setupSchema(self.db, 1, mysql) |
| 736 self.db = mysql.Database(config, 'admin') | 737 |
| 737 self.db.sql("DROP DATABASE %s" % config.MYSQL_DATABASE[1]) | 738 def tearDown(self): |
| 738 self.db.sql("CREATE DATABASE %s" % config.MYSQL_DATABASE[1]) | 739 from roundup.backends import mysql |
| 739 self.db.close() | 740 self.db.close() |
| 740 # open database for testing | 741 mysql.nuke(config) |
| 741 self.db = mysql.Database(config, 'admin') | 742 anydbmDBTestCase.tearDown(self) |
| 742 | |
| 743 setupSchema(self.db, 1, mysql) | |
| 744 | 743 |
| 745 class mysqlReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): | 744 class mysqlReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 746 def setUp(self): | 745 def setUp(self): |
| 747 from roundup.backends import mysql | 746 from roundup.backends import mysql |
| 748 # remove previous test, ignore errors | 747 # remove previous test, ignore errors |
| 749 if os.path.exists(config.DATABASE): | 748 if os.path.exists(config.DATABASE): |
| 750 shutil.rmtree(config.DATABASE) | 749 shutil.rmtree(config.DATABASE) |
| 751 config.MYSQL_DATABASE = ('localhost', 'rounduptest', 'rounduptest', | 750 os.makedirs(config.DATABASE + '/files') |
| 752 'rounduptest') | |
| 753 os.makedirs(config.DATABASE + '/files') | |
| 754 # open database for cleaning | |
| 755 self.db = mysql.Database(config, 'admin') | |
| 756 self.db.sql("DROP DATABASE %s" % config.MYSQL_DATABASE[1]) | |
| 757 self.db.sql("CREATE DATABASE %s" % config.MYSQL_DATABASE[1]) | |
| 758 self.db.close() | |
| 759 # open database for testing | |
| 760 self.db = mysql.Database(config) | 751 self.db = mysql.Database(config) |
| 761 setupSchema(self.db, 0, mysql) | 752 setupSchema(self.db, 0, mysql) |
| 753 | |
| 754 def tearDown(self): | |
| 755 from roundup.backends import mysql | |
| 756 self.db.close() | |
| 757 mysql.nuke(config) | |
| 758 anydbmReadOnlyDBTestCase.tearDown(self) | |
| 762 | 759 |
| 763 class sqliteDBTestCase(anydbmDBTestCase): | 760 class sqliteDBTestCase(anydbmDBTestCase): |
| 764 def setUp(self): | 761 def setUp(self): |
| 765 from roundup.backends import sqlite | 762 from roundup.backends import sqlite |
| 766 # remove previous test, ignore errors | 763 # remove previous test, ignore errors |
| 863 # return unittest.TestSuite(l) | 860 # return unittest.TestSuite(l) |
| 864 | 861 |
| 865 from roundup import backends | 862 from roundup import backends |
| 866 p = [] | 863 p = [] |
| 867 if hasattr(backends, 'mysql'): | 864 if hasattr(backends, 'mysql'): |
| 868 p.append('mysql') | 865 from roundup.backends import mysql |
| 869 l.append(unittest.makeSuite(mysqlDBTestCase, 'test')) | 866 try: |
| 870 l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test')) | 867 # Check if we can run mysql tests |
| 868 import MySQLdb | |
| 869 db = mysql.Database(nodbconfig, 'admin') | |
| 870 db.conn.select_db(config.MYSQL_DBNAME) | |
| 871 db.sql("SHOW TABLES"); | |
| 872 tables = db.sql_fetchall() | |
| 873 if tables: | |
| 874 # Database should be empty. We don't dare to delete any data | |
| 875 raise DatabaseError, "(Database %s contains tables)" % config.MYSQL_DBNAME | |
| 876 db.sql("DROP DATABASE IF EXISTS %s" % config.MYSQL_DBNAME) | |
| 877 db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME) | |
| 878 db.close() | |
| 879 except (MySQLdb.ProgrammingError, DatabaseError), msg: | |
| 880 print "Warning! Mysql tests will not be performed", msg | |
| 881 print "See doc/mysql.txt for more details." | |
| 882 else: | |
| 883 p.append('mysql') | |
| 884 l.append(unittest.makeSuite(mysqlDBTestCase, 'test')) | |
| 885 l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test')) | |
| 871 #return unittest.TestSuite(l) | 886 #return unittest.TestSuite(l) |
| 872 | 887 |
| 873 if hasattr(backends, 'gadfly'): | 888 if hasattr(backends, 'gadfly'): |
| 874 p.append('gadfly') | 889 p.append('gadfly') |
| 875 l.append(unittest.makeSuite(gadflyDBTestCase, 'test')) | 890 l.append(unittest.makeSuite(gadflyDBTestCase, 'test')) |
