Mercurial > p > roundup > code
comparison test/db_test_base.py @ 2680:c26a9a5a25d2
rdbms backends require new config object. make one.
add rdbms settings (now common for all backends).
trim trailing spaces; add vim modeline.
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Sat, 25 Sep 2004 15:47:02 +0000 |
| parents | 6e9bd67fefa9 |
| children | 99bd8a4b8abf |
comparison
equal
deleted
inserted
replaced
| 2679:b3f0b7b9d20d | 2680:c26a9a5a25d2 |
|---|---|
| 12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 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.43 2004-07-21 00:50:50 richard Exp $ | 18 # $Id: db_test_base.py,v 1.44 2004-09-25 15:47:02 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 |
| 24 from roundup import date, password, init, instance | 24 from roundup import date, password, init, instance, configuration |
| 25 | 25 |
| 26 from mocknull import MockNull | 26 from mocknull import MockNull |
| 27 | |
| 28 config = configuration.CoreConfig() | |
| 29 config.DATABASE = "_test_dir" | |
| 30 config.RDBMS_NAME = "rounduptest" | |
| 31 config.RDBMS_HOST = "localhost" | |
| 32 config.RDBMS_USER = "rounduptest" | |
| 33 config.RDBMS_PASSWORD = "rounduptest" | |
| 34 config.logging = MockNull() | |
| 27 | 35 |
| 28 def setupSchema(db, create, module): | 36 def setupSchema(db, create, module): |
| 29 status = module.Class(db, "status", name=String()) | 37 status = module.Class(db, "status", name=String()) |
| 30 status.setkey("name") | 38 status.setkey("name") |
| 31 priority = module.Class(db, "priority", name=String(), order=String()) | 39 priority = module.Class(db, "priority", name=String(), order=String()) |
| 62 if hasattr(self, 'db'): | 70 if hasattr(self, 'db'): |
| 63 self.db.close() | 71 self.db.close() |
| 64 if os.path.exists(config.DATABASE): | 72 if os.path.exists(config.DATABASE): |
| 65 shutil.rmtree(config.DATABASE) | 73 shutil.rmtree(config.DATABASE) |
| 66 | 74 |
| 67 class config: | |
| 68 DATABASE='_test_dir' | |
| 69 MAILHOST = 'localhost' | |
| 70 MAIL_DOMAIN = 'fill.me.in.' | |
| 71 TRACKER_NAME = 'Roundup issue tracker' | |
| 72 TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN | |
| 73 TRACKER_WEB = 'http://some.useful.url/' | |
| 74 ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN | |
| 75 FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom' | |
| 76 ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow' | |
| 77 ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow' | |
| 78 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' | |
| 79 EMAIL_SIGNATURE_POSITION = 'bottom' | |
| 80 | |
| 81 logging = MockNull() | |
| 82 | |
| 83 if os.environ.has_key('LOGGING_LEVEL'): | 75 if os.environ.has_key('LOGGING_LEVEL'): |
| 84 from roundup import rlog | 76 from roundup import rlog |
| 85 config.logging = rlog.BasicLogging() | 77 config.logging = rlog.BasicLogging() |
| 86 config.logging.setLevel(os.environ['LOGGING_LEVEL']) | 78 config.logging.setLevel(os.environ['LOGGING_LEVEL']) |
| 87 config.logging.getLogger('hyperdb').setFormat('%(message)s') | 79 config.logging.getLogger('hyperdb').setFormat('%(message)s') |
| 215 m = self.db.issue.get(nid, "nosy"); m.sort() | 207 m = self.db.issue.get(nid, "nosy"); m.sort() |
| 216 self.assertEqual(l, m) | 208 self.assertEqual(l, m) |
| 217 | 209 |
| 218 # Date | 210 # Date |
| 219 def testDateChange(self): | 211 def testDateChange(self): |
| 220 self.assertRaises(TypeError, self.db.issue.create, | 212 self.assertRaises(TypeError, self.db.issue.create, |
| 221 title='spam', deadline=1) | 213 title='spam', deadline=1) |
| 222 for commit in (0,1): | 214 for commit in (0,1): |
| 223 nid = self.db.issue.create(title="spam", status='1') | 215 nid = self.db.issue.create(title="spam", status='1') |
| 224 self.assertRaises(TypeError, self.db.issue.set, nid, deadline=1) | 216 self.assertRaises(TypeError, self.db.issue.set, nid, deadline=1) |
| 225 a = self.db.issue.get(nid, "deadline") | 217 a = self.db.issue.get(nid, "deadline") |
| 240 if commit: self.db.commit() | 232 if commit: self.db.commit() |
| 241 self.assertEqual(self.db.issue.get(nid, "deadline"), None) | 233 self.assertEqual(self.db.issue.get(nid, "deadline"), None) |
| 242 | 234 |
| 243 # Interval | 235 # Interval |
| 244 def testIntervalChange(self): | 236 def testIntervalChange(self): |
| 245 self.assertRaises(TypeError, self.db.issue.create, | 237 self.assertRaises(TypeError, self.db.issue.create, |
| 246 title='spam', foo=1) | 238 title='spam', foo=1) |
| 247 for commit in (0,1): | 239 for commit in (0,1): |
| 248 nid = self.db.issue.create(title="spam", status='1') | 240 nid = self.db.issue.create(title="spam", status='1') |
| 249 self.assertRaises(TypeError, self.db.issue.set, nid, foo=1) | 241 self.assertRaises(TypeError, self.db.issue.set, nid, foo=1) |
| 250 if commit: self.db.commit() | 242 if commit: self.db.commit() |
| 363 def testRetire(self): | 355 def testRetire(self): |
| 364 self.db.issue.create(title="spam", status='1') | 356 self.db.issue.create(title="spam", status='1') |
| 365 b = self.db.status.get('1', 'name') | 357 b = self.db.status.get('1', 'name') |
| 366 a = self.db.status.list() | 358 a = self.db.status.list() |
| 367 self.db.status.retire('1') | 359 self.db.status.retire('1') |
| 368 # make sure the list is different | 360 # make sure the list is different |
| 369 self.assertNotEqual(a, self.db.status.list()) | 361 self.assertNotEqual(a, self.db.status.list()) |
| 370 # can still access the node if necessary | 362 # can still access the node if necessary |
| 371 self.assertEqual(self.db.status.get('1', 'name'), b) | 363 self.assertEqual(self.db.status.get('1', 'name'), b) |
| 372 self.assertRaises(IndexError, self.db.status.set, '1', name='hello') | 364 self.assertRaises(IndexError, self.db.status.set, '1', name='hello') |
| 373 self.db.commit() | 365 self.db.commit() |
| 374 self.assertEqual(self.db.status.get('1', 'name'), b) | 366 self.assertEqual(self.db.status.get('1', 'name'), b) |
| 375 self.assertNotEqual(a, self.db.status.list()) | 367 self.assertNotEqual(a, self.db.status.list()) |
| 376 # try to restore retired node | 368 # try to restore retired node |
| 377 self.db.status.restore('1') | 369 self.db.status.restore('1') |
| 378 | 370 |
| 379 def testCacheCreateSet(self): | 371 def testCacheCreateSet(self): |
| 380 self.db.issue.create(title="spam", status='1') | 372 self.db.issue.create(title="spam", status='1') |
| 381 a = self.db.issue.get('1', 'title') | 373 a = self.db.issue.get('1', 'title') |
| 382 self.assertEqual(a, 'spam') | 374 self.assertEqual(a, 'spam') |
| 383 self.db.issue.set('1', title='ham') | 375 self.db.issue.set('1', title='ham') |
| 411 self.assertNotEqual(num_issues, len(self.db.issue.list())) | 403 self.assertNotEqual(num_issues, len(self.db.issue.list())) |
| 412 self.db.file.create(name="test", type="text/plain", content="hi") | 404 self.db.file.create(name="test", type="text/plain", content="hi") |
| 413 self.db.rollback() | 405 self.db.rollback() |
| 414 self.assertEqual(num_files, self.db.numfiles()) | 406 self.assertEqual(num_files, self.db.numfiles()) |
| 415 for i in range(10): | 407 for i in range(10): |
| 416 self.db.file.create(name="test", type="text/plain", | 408 self.db.file.create(name="test", type="text/plain", |
| 417 content="hi %d"%(i)) | 409 content="hi %d"%(i)) |
| 418 self.db.commit() | 410 self.db.commit() |
| 419 num_files2 = self.db.numfiles() | 411 num_files2 = self.db.numfiles() |
| 420 self.assertNotEqual(num_files, num_files2) | 412 self.assertNotEqual(num_files, num_files2) |
| 421 self.db.file.create(name="test", type="text/plain", content="hi") | 413 self.db.file.create(name="test", type="text/plain", content="hi") |
| 516 ar(IndexError, self.db.issue.create, title='foo', status='1', | 508 ar(IndexError, self.db.issue.create, title='foo', status='1', |
| 517 nosy=['10']) | 509 nosy=['10']) |
| 518 | 510 |
| 519 # | 511 # |
| 520 # key property | 512 # key property |
| 521 # | 513 # |
| 522 # key must be a String | 514 # key must be a String |
| 523 ar(TypeError, self.db.file.setkey, 'fooz') | 515 ar(TypeError, self.db.file.setkey, 'fooz') |
| 524 # key must exist | 516 # key must exist |
| 525 ar(KeyError, self.db.file.setkey, 'fubar') | 517 ar(KeyError, self.db.file.setkey, 'fubar') |
| 526 | 518 |
| 1370 f = open(os.path.join(self.dirname, 'config.py'), 'a') | 1362 f = open(os.path.join(self.dirname, 'config.py'), 'a') |
| 1371 try: | 1363 try: |
| 1372 f.write(self.extra_config) | 1364 f.write(self.extra_config) |
| 1373 finally: | 1365 finally: |
| 1374 f.close() | 1366 f.close() |
| 1375 | 1367 |
| 1376 init.initialise(self.dirname, 'sekrit') | 1368 init.initialise(self.dirname, 'sekrit') |
| 1377 | 1369 |
| 1378 # check we can load the package | 1370 # check we can load the package |
| 1379 tracker = instance.open(self.dirname) | 1371 tracker = instance.open(self.dirname) |
| 1380 | 1372 |
| 1403 try: | 1395 try: |
| 1404 shutil.rmtree(self.dirname) | 1396 shutil.rmtree(self.dirname) |
| 1405 except OSError, error: | 1397 except OSError, error: |
| 1406 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | 1398 if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 1407 | 1399 |
| 1400 # vim: set et sts=4 sw=4 : |
