comparison test/db_test_base.py @ 2820:da2a9175eb83

tracker setup put in separate function for use in other test suites
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Sun, 24 Oct 2004 09:57:32 +0000
parents 1f89984c0ea5
children d530b68e4b42
comparison
equal deleted inserted replaced
2819:24a5447725a2 2820:da2a9175eb83
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: db_test_base.py,v 1.50 2004-10-14 10:47:07 a1s Exp $ 18 # $Id: db_test_base.py,v 1.51 2004-10-24 09:57:32 a1s Exp $
19 19
20 import unittest, os, shutil, errno, imp, sys, time, pprint 20 import unittest, os, shutil, errno, imp, sys, time, pprint
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, Node 23 Interval, DatabaseError, Boolean, Number, Node
30 config.RDBMS_NAME = "rounduptest" 30 config.RDBMS_NAME = "rounduptest"
31 config.RDBMS_HOST = "localhost" 31 config.RDBMS_HOST = "localhost"
32 config.RDBMS_USER = "rounduptest" 32 config.RDBMS_USER = "rounduptest"
33 config.RDBMS_PASSWORD = "rounduptest" 33 config.RDBMS_PASSWORD = "rounduptest"
34 config.logging = MockNull() 34 config.logging = MockNull()
35 # MAIL_DOMAIN is required for config.save() 35 # these TRACKER_WEB and MAIL_DOMAIN values are used in mailgw tests
36 config.MAIL_DOMAIN = "localhost" 36 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
37 config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/"
38 # uncomment the following to have excessive debug output from test cases
39 # FIXME: tracker logging level should be increased by -v arguments
40 # to 'run_tests.py' script
41 #config.LOGGING_LEVEL = "DEBUG"
42
43 def setupTracker(dirname, backend="anydbm"):
44 """Install and initialize new tracker in dirname; return tracker instance.
45
46 If the directory exists, it is wiped out before the operation.
47
48 """
49 global config
50 try:
51 shutil.rmtree(dirname)
52 except OSError, error:
53 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
54 # create the instance
55 init.install(dirname, 'templates/classic')
56 init.write_select_db(dirname, backend)
57 config.save(os.path.join(dirname, 'config.ini'))
58 tracker = instance.open(dirname)
59 if tracker.exists():
60 tracker.nuke()
61 tracker.init(password.Password('sekrit'))
62 return tracker
37 63
38 def setupSchema(db, create, module): 64 def setupSchema(db, create, module):
39 status = module.Class(db, "status", name=String()) 65 status = module.Class(db, "status", name=String())
40 status.setkey("name") 66 status.setkey("name")
41 priority = module.Class(db, "priority", name=String(), order=String()) 67 priority = module.Class(db, "priority", name=String(), order=String())
1353 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 1379 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
1354 1380
1355 def testCreation(self): 1381 def testCreation(self):
1356 ae = self.assertEqual 1382 ae = self.assertEqual
1357 1383
1358 # create the instance 1384 # set up and open a tracker
1359 init.install(self.dirname, 'templates/classic') 1385 tracker = setupTracker(self.dirname, self.backend)
1360 init.write_select_db(self.dirname, self.backend) 1386 # open the database
1361 config.save(os.path.join(self.dirname, 'config.ini'))
1362
1363 # check we can load the package
1364 tracker = instance.open(self.dirname)
1365
1366 # if there is a database left behind
1367 # from previous test runs, nuke it
1368 if tracker.exists():
1369 tracker.nuke()
1370
1371 # initialize the tracker database
1372 tracker.init(password.Password('sekrit'))
1373
1374 # and open the database
1375 db = self.db = tracker.open('test') 1387 db = self.db = tracker.open('test')
1376 1388
1377 # check the basics of the schema and initial data set 1389 # check the basics of the schema and initial data set
1378 l = db.priority.list() 1390 l = db.priority.list()
1379 ae(l, ['1', '2', '3', '4', '5']) 1391 ae(l, ['1', '2', '3', '4', '5'])

Roundup Issue Tracker: http://roundup-tracker.org/