Mercurial > p > roundup > code
comparison test/test_mysql.py @ 1873:f63aa57386b0
Backend improvements.
- using Zope3's test runner now, allowing GC checks, nicer controls and
coverage analysis
- all RDMBS backends now have indexes on several columns
- added testing of schema mutation, fixed rdbms backends handling of a
couple of cases
- !BETA! added postgresql backend, needs work !BETA!
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 25 Oct 2003 22:53:26 +0000 |
| parents | |
| children | be9b87ad711b |
comparison
equal
deleted
inserted
replaced
| 1872:c085b4f4f0c0 | 1873:f63aa57386b0 |
|---|---|
| 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.1 2003-10-25 22:53:26 richard Exp $ | |
| 19 | |
| 20 import unittest, os, shutil, time, imp | |
| 21 | |
| 22 from roundup.hyperdb import DatabaseError | |
| 23 from roundup import init | |
| 24 | |
| 25 from db_test_base import DBTest, ROTest, config, SchemaTest, nodbconfig, \ | |
| 26 ClassicInitTest | |
| 27 | |
| 28 class mysqlOpener: | |
| 29 from roundup.backends import mysql as module | |
| 30 | |
| 31 def tearDown(self): | |
| 32 self.db.close() | |
| 33 self.module.db_nuke(config) | |
| 34 | |
| 35 class mysqlDBTest(mysqlOpener, DBTest): | |
| 36 pass | |
| 37 | |
| 38 class mysqlROTest(mysqlOpener, ROTest): | |
| 39 pass | |
| 40 | |
| 41 class mysqlSchemaTest(mysqlOpener, SchemaTest): | |
| 42 pass | |
| 43 | |
| 44 class mysqlClassicInitTest(ClassicInitTest): | |
| 45 backend = 'mysql' | |
| 46 | |
| 47 def testCreation(self): | |
| 48 ae = self.assertEqual | |
| 49 | |
| 50 # create the instance | |
| 51 init.install(self.dirname, 'templates/classic') | |
| 52 init.write_select_db(self.dirname, self.backend) | |
| 53 f = open(os.path.join(self.dirname, 'config.py'), 'a') | |
| 54 try: | |
| 55 f.write(''' | |
| 56 MYSQL_DBHOST = 'localhost' | |
| 57 MYSQL_DBUSER = 'rounduptest' | |
| 58 MYSQL_DBPASSWORD = 'rounduptest' | |
| 59 MYSQL_DBNAME = 'rounduptest' | |
| 60 MYSQL_DATABASE = (MYSQL_DBHOST, MYSQL_DBUSER, MYSQL_DBPASSWORD, MYSQL_DBNAME) | |
| 61 ''') | |
| 62 finally: | |
| 63 f.close() | |
| 64 init.initialise(self.dirname, 'sekrit') | |
| 65 | |
| 66 # check we can load the package | |
| 67 instance = imp.load_package(self.dirname, self.dirname) | |
| 68 | |
| 69 # and open the database | |
| 70 db = instance.open() | |
| 71 | |
| 72 # check the basics of the schema and initial data set | |
| 73 l = db.priority.list() | |
| 74 ae(l, ['1', '2', '3', '4', '5']) | |
| 75 l = db.status.list() | |
| 76 ae(l, ['1', '2', '3', '4', '5', '6', '7', '8']) | |
| 77 l = db.keyword.list() | |
| 78 ae(l, []) | |
| 79 l = db.user.list() | |
| 80 ae(l, ['1', '2']) | |
| 81 l = db.msg.list() | |
| 82 ae(l, []) | |
| 83 l = db.file.list() | |
| 84 ae(l, []) | |
| 85 l = db.issue.list() | |
| 86 ae(l, []) | |
| 87 | |
| 88 from roundup.backends import mysql as module | |
| 89 def tearDown(self): | |
| 90 ClassicInitTest.tearDown(self) | |
| 91 self.module.db_nuke(config) | |
| 92 | |
| 93 def test_suite(): | |
| 94 suite = unittest.TestSuite() | |
| 95 | |
| 96 from roundup import backends | |
| 97 if not hasattr(backends, 'mysql'): | |
| 98 return suite | |
| 99 | |
| 100 from roundup.backends import mysql | |
| 101 try: | |
| 102 # Check if we can run mysql tests | |
| 103 import MySQLdb | |
| 104 db = mysql.Database(nodbconfig, 'admin') | |
| 105 db.conn.select_db(config.MYSQL_DBNAME) | |
| 106 db.sql("SHOW TABLES"); | |
| 107 tables = db.sql_fetchall() | |
| 108 if 0: #tables: | |
| 109 # Database should be empty. We don't dare to delete any data | |
| 110 raise DatabaseError, "Database %s contains tables"%\ | |
| 111 config.MYSQL_DBNAME | |
| 112 db.sql("DROP DATABASE %s" % config.MYSQL_DBNAME) | |
| 113 db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME) | |
| 114 db.close() | |
| 115 except (MySQLdb.ProgrammingError, DatabaseError), msg: | |
| 116 print "Skipping mysql tests (%s)"%msg | |
| 117 else: | |
| 118 print 'Including mysql tests' | |
| 119 suite.addTest(unittest.makeSuite(mysqlDBTest)) | |
| 120 suite.addTest(unittest.makeSuite(mysqlROTest)) | |
| 121 suite.addTest(unittest.makeSuite(mysqlSchemaTest)) | |
| 122 suite.addTest(unittest.makeSuite(mysqlClassicInitTest)) | |
| 123 return suite | |
| 124 | |
| 125 if __name__ == '__main__': | |
| 126 runner = unittest.TextTestRunner() | |
| 127 unittest.main(testRunner=runner) | |
| 128 |
