Mercurial > p > roundup > code
comparison test/test_db.py @ 602:c242455d9b46 config-0-4-0-branch
Brought the config branch up to date with HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 06 Feb 2002 04:05:55 +0000 |
| parents | b579418f7ed1 |
| children |
comparison
equal
deleted
inserted
replaced
| 601:912029653c1c | 602:c242455d9b46 |
|---|---|
| 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.12 2001-12-17 03:52:48 richard Exp $ | 18 # $Id: test_db.py,v 1.12.2.1 2002-02-06 04:05:55 richard Exp $ |
| 19 | 19 |
| 20 import unittest, os, shutil | 20 import unittest, os, shutil |
| 21 | 21 |
| 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 23 Interval, Class, DatabaseError | 23 Interval, Class, DatabaseError |
| 24 from roundup.roundupdb import FileClass | 24 from roundup.roundupdb import FileClass |
| 25 from roundup import date | |
| 25 | 26 |
| 26 def setupSchema(db, create): | 27 def setupSchema(db, create): |
| 27 status = Class(db, "status", name=String()) | 28 status = Class(db, "status", name=String()) |
| 28 status.setkey("name") | 29 status.setkey("name") |
| 29 if create: | 30 if create: |
| 31 status.create(name="in-progress") | 32 status.create(name="in-progress") |
| 32 status.create(name="testing") | 33 status.create(name="testing") |
| 33 status.create(name="resolved") | 34 status.create(name="resolved") |
| 34 Class(db, "user", username=String(), password=Password()) | 35 Class(db, "user", username=String(), password=Password()) |
| 35 Class(db, "issue", title=String(), status=Link("status"), | 36 Class(db, "issue", title=String(), status=Link("status"), |
| 36 nosy=Multilink("user")) | 37 nosy=Multilink("user"), deadline=Date(), foo=Interval()) |
| 37 FileClass(db, "file", name=String(), type=String()) | 38 FileClass(db, "file", name=String(), type=String()) |
| 38 db.commit() | 39 db.commit() |
| 39 | 40 |
| 40 class MyTestCase(unittest.TestCase): | 41 class MyTestCase(unittest.TestCase): |
| 41 def tearDown(self): | 42 def tearDown(self): |
| 42 if os.path.exists('_test_dir'): | 43 if os.path.exists('_test_dir'): |
| 43 shutil.rmtree('_test_dir') | 44 shutil.rmtree('_test_dir') |
| 44 | 45 |
| 46 class config: | |
| 47 DATABASE='_test_dir' | |
| 48 MAILHOST = 'localhost' | |
| 49 MAIL_DOMAIN = 'fill.me.in.' | |
| 50 INSTANCE_NAME = 'Roundup issue tracker' | |
| 51 ISSUE_TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN | |
| 52 ISSUE_TRACKER_WEB = 'http://some.useful.url/' | |
| 53 ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN | |
| 54 FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom' | |
| 55 ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow' | |
| 56 ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow' | |
| 57 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no' | |
| 58 EMAIL_SIGNATURE_POSITION = 'bottom' | |
| 59 | |
| 45 class anydbmDBTestCase(MyTestCase): | 60 class anydbmDBTestCase(MyTestCase): |
| 46 def setUp(self): | 61 def setUp(self): |
| 47 from roundup.backends import anydbm | 62 from roundup.backends import anydbm |
| 48 # remove previous test, ignore errors | 63 # remove previous test, ignore errors |
| 49 if os.path.exists('_test_dir'): | 64 if os.path.exists(config.DATABASE): |
| 50 shutil.rmtree('_test_dir') | 65 shutil.rmtree(config.DATABASE) |
| 51 os.makedirs('_test_dir/files') | 66 os.makedirs(config.DATABASE + '/files') |
| 52 self.db = anydbm.Database('_test_dir', 'test') | 67 self.db = anydbm.Database(config, 'test') |
| 53 setupSchema(self.db, 1) | 68 setupSchema(self.db, 1) |
| 54 | 69 |
| 55 def testChanges(self): | 70 def testChanges(self): |
| 56 self.db.issue.create(title="spam", status='1') | 71 self.db.issue.create(title="spam", status='1') |
| 57 self.db.issue.create(title="eggs", status='2') | 72 self.db.issue.create(title="eggs", status='2') |
| 60 self.db.issue.create(title="abuse", status='1') | 75 self.db.issue.create(title="abuse", status='1') |
| 61 self.db.issue.addprop(fixer=Link("user")) | 76 self.db.issue.addprop(fixer=Link("user")) |
| 62 props = self.db.issue.getprops() | 77 props = self.db.issue.getprops() |
| 63 keys = props.keys() | 78 keys = props.keys() |
| 64 keys.sort() | 79 keys.sort() |
| 65 self.assertEqual(keys, ['fixer', 'id', 'nosy', 'status', 'title']) | 80 self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'id', 'nosy', |
| 81 'status', 'title']) | |
| 66 self.db.issue.set('5', status='2') | 82 self.db.issue.set('5', status='2') |
| 67 self.db.issue.get('5', "status") | 83 self.db.issue.get('5', "status") |
| 84 | |
| 85 a = self.db.issue.get('5', "deadline") | |
| 86 self.db.issue.set('5', deadline=date.Date()) | |
| 87 self.assertNotEqual(a, self.db.issue.get('5', "deadline")) | |
| 88 | |
| 89 a = self.db.issue.get('5', "foo") | |
| 90 self.db.issue.set('5', foo=date.Interval('-1d')) | |
| 91 self.assertNotEqual(a, self.db.issue.get('5', "foo")) | |
| 92 | |
| 68 self.db.status.get('2', "name") | 93 self.db.status.get('2', "name") |
| 69 self.db.issue.get('5', "title") | 94 self.db.issue.get('5', "title") |
| 70 self.db.issue.find(status = self.db.status.lookup("in-progress")) | 95 self.db.issue.find(status = self.db.status.lookup("in-progress")) |
| 71 self.db.commit() | 96 self.db.commit() |
| 72 self.db.issue.history('5') | 97 self.db.issue.history('5') |
| 163 nosy=[1]) | 188 nosy=[1]) |
| 164 # invalid multilink index | 189 # invalid multilink index |
| 165 ar(IndexError, self.db.issue.set, '1', title='foo', status='1', | 190 ar(IndexError, self.db.issue.set, '1', title='foo', status='1', |
| 166 nosy=['10']) | 191 nosy=['10']) |
| 167 | 192 |
| 193 def testJournals(self): | |
| 194 self.db.issue.addprop(fixer=Link("user", do_journal='yes')) | |
| 195 self.db.user.create(username="mary") | |
| 196 self.db.user.create(username="pete") | |
| 197 self.db.issue.create(title="spam", status='1') | |
| 198 self.db.commit() | |
| 199 | |
| 200 # journal entry for issue create | |
| 201 journal = self.db.getjournal('issue', '1') | |
| 202 self.assertEqual(1, len(journal)) | |
| 203 (nodeid, date_stamp, journaltag, action, params) = journal[0] | |
| 204 self.assertEqual(nodeid, '1') | |
| 205 self.assertEqual(journaltag, 'test') | |
| 206 self.assertEqual(action, 'create') | |
| 207 keys = params.keys() | |
| 208 keys.sort() | |
| 209 self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'nosy', | |
| 210 'status', 'title']) | |
| 211 self.assertEqual(None,params['deadline']) | |
| 212 self.assertEqual(None,params['fixer']) | |
| 213 self.assertEqual(None,params['foo']) | |
| 214 self.assertEqual([],params['nosy']) | |
| 215 self.assertEqual('1',params['status']) | |
| 216 self.assertEqual('spam',params['title']) | |
| 217 | |
| 218 # journal entry for link | |
| 219 journal = self.db.getjournal('user', '1') | |
| 220 self.assertEqual(1, len(journal)) | |
| 221 self.db.issue.set('1', fixer='1') | |
| 222 self.db.commit() | |
| 223 journal = self.db.getjournal('user', '1') | |
| 224 self.assertEqual(2, len(journal)) | |
| 225 (nodeid, date_stamp, journaltag, action, params) = journal[1] | |
| 226 self.assertEqual('1', nodeid) | |
| 227 self.assertEqual('test', journaltag) | |
| 228 self.assertEqual('link', action) | |
| 229 self.assertEqual(('issue', '1', 'fixer'), params) | |
| 230 | |
| 231 # journal entry for unlink | |
| 232 self.db.issue.set('1', fixer='2') | |
| 233 self.db.commit() | |
| 234 journal = self.db.getjournal('user', '1') | |
| 235 self.assertEqual(3, len(journal)) | |
| 236 (nodeid, date_stamp, journaltag, action, params) = journal[2] | |
| 237 self.assertEqual('1', nodeid) | |
| 238 self.assertEqual('test', journaltag) | |
| 239 self.assertEqual('unlink', action) | |
| 240 self.assertEqual(('issue', '1', 'fixer'), params) | |
| 241 | |
| 242 def testPack(self): | |
| 243 self.db.issue.create(title="spam", status='1') | |
| 244 self.db.commit() | |
| 245 self.db.issue.set('1', status='2') | |
| 246 self.db.commit() | |
| 247 self.db.issue.set('1', status='3') | |
| 248 self.db.commit() | |
| 249 pack_before = date.Date(". + 1d") | |
| 250 self.db.pack(pack_before) | |
| 251 journal = self.db.getjournal('issue', '1') | |
| 252 self.assertEqual(2, len(journal)) | |
| 253 | |
| 168 def testRetire(self): | 254 def testRetire(self): |
| 169 pass | 255 pass |
| 170 | 256 |
| 171 | 257 |
| 172 class anydbmReadOnlyDBTestCase(MyTestCase): | 258 class anydbmReadOnlyDBTestCase(MyTestCase): |
| 173 def setUp(self): | 259 def setUp(self): |
| 174 from roundup.backends import anydbm | 260 from roundup.backends import anydbm |
| 175 # remove previous test, ignore errors | 261 # remove previous test, ignore errors |
| 176 if os.path.exists('_test_dir'): | 262 if os.path.exists(config.DATABASE): |
| 177 shutil.rmtree('_test_dir') | 263 shutil.rmtree(config.DATABASE) |
| 178 os.makedirs('_test_dir/files') | 264 os.makedirs(config.DATABASE + '/files') |
| 179 db = anydbm.Database('_test_dir', 'test') | 265 db = anydbm.Database(config, 'test') |
| 180 setupSchema(db, 1) | 266 setupSchema(db, 1) |
| 181 self.db = anydbm.Database('_test_dir') | 267 self.db = anydbm.Database(config) |
| 182 setupSchema(self.db, 0) | 268 setupSchema(self.db, 0) |
| 183 | 269 |
| 184 def testExceptions(self): | 270 def testExceptions(self): |
| 185 # this tests the exceptions that should be raised | 271 # this tests the exceptions that should be raised |
| 186 ar = self.assertRaises | 272 ar = self.assertRaises |
| 193 | 279 |
| 194 class bsddbDBTestCase(anydbmDBTestCase): | 280 class bsddbDBTestCase(anydbmDBTestCase): |
| 195 def setUp(self): | 281 def setUp(self): |
| 196 from roundup.backends import bsddb | 282 from roundup.backends import bsddb |
| 197 # remove previous test, ignore errors | 283 # remove previous test, ignore errors |
| 198 if os.path.exists('_test_dir'): | 284 if os.path.exists(config.DATABASE): |
| 199 shutil.rmtree('_test_dir') | 285 shutil.rmtree(config.DATABASE) |
| 200 os.makedirs('_test_dir/files') | 286 os.makedirs(config.DATABASE + '/files') |
| 201 self.db = bsddb.Database('_test_dir', 'test') | 287 self.db = bsddb.Database(config, 'test') |
| 202 setupSchema(self.db, 1) | 288 setupSchema(self.db, 1) |
| 203 | 289 |
| 204 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): | 290 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 205 def setUp(self): | 291 def setUp(self): |
| 206 from roundup.backends import bsddb | 292 from roundup.backends import bsddb |
| 207 # remove previous test, ignore errors | 293 # remove previous test, ignore errors |
| 208 if os.path.exists('_test_dir'): | 294 if os.path.exists(config.DATABASE): |
| 209 shutil.rmtree('_test_dir') | 295 shutil.rmtree(config.DATABASE) |
| 210 os.makedirs('_test_dir/files') | 296 os.makedirs(config.DATABASE + '/files') |
| 211 db = bsddb.Database('_test_dir', 'test') | 297 db = bsddb.Database(config, 'test') |
| 212 setupSchema(db, 1) | 298 setupSchema(db, 1) |
| 213 self.db = bsddb.Database('_test_dir') | 299 self.db = bsddb.Database(config) |
| 214 setupSchema(self.db, 0) | 300 setupSchema(self.db, 0) |
| 215 | 301 |
| 216 | 302 |
| 217 class bsddb3DBTestCase(anydbmDBTestCase): | 303 class bsddb3DBTestCase(anydbmDBTestCase): |
| 218 def setUp(self): | 304 def setUp(self): |
| 219 from roundup.backends import bsddb3 | 305 from roundup.backends import bsddb3 |
| 220 # remove previous test, ignore errors | 306 # remove previous test, ignore errors |
| 221 if os.path.exists('_test_dir'): | 307 if os.path.exists(config.DATABASE): |
| 222 shutil.rmtree('_test_dir') | 308 shutil.rmtree(config.DATABASE) |
| 223 os.makedirs('_test_dir/files') | 309 os.makedirs(config.DATABASE + '/files') |
| 224 self.db = bsddb3.Database('_test_dir', 'test') | 310 self.db = bsddb3.Database(config, 'test') |
| 225 setupSchema(self.db, 1) | 311 setupSchema(self.db, 1) |
| 226 | 312 |
| 227 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): | 313 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 228 def setUp(self): | 314 def setUp(self): |
| 229 from roundup.backends import bsddb3 | 315 from roundup.backends import bsddb3 |
| 230 # remove previous test, ignore errors | 316 # remove previous test, ignore errors |
| 231 if os.path.exists('_test_dir'): | 317 if os.path.exists(config.DATABASE): |
| 232 shutil.rmtree('_test_dir') | 318 shutil.rmtree(config.DATABASE) |
| 233 os.makedirs('_test_dir/files') | 319 os.makedirs(config.DATABASE + '/files') |
| 234 db = bsddb3.Database('_test_dir', 'test') | 320 db = bsddb3.Database(config, 'test') |
| 235 setupSchema(db, 1) | 321 setupSchema(db, 1) |
| 236 self.db = bsddb3.Database('_test_dir') | 322 self.db = bsddb3.Database(config) |
| 237 setupSchema(self.db, 0) | 323 setupSchema(self.db, 0) |
| 238 | 324 |
| 239 | 325 |
| 240 def suite(): | 326 def suite(): |
| 241 l = [unittest.makeSuite(anydbmDBTestCase, 'test'), | 327 l = [unittest.makeSuite(anydbmDBTestCase, 'test'), |
| 258 | 344 |
| 259 return unittest.TestSuite(l) | 345 return unittest.TestSuite(l) |
| 260 | 346 |
| 261 # | 347 # |
| 262 # $Log: not supported by cvs2svn $ | 348 # $Log: not supported by cvs2svn $ |
| 349 # Revision 1.18 2002/01/22 07:21:13 richard | |
| 350 # . fixed back_bsddb so it passed the journal tests | |
| 351 # | |
| 352 # ... it didn't seem happy using the back_anydbm _open method, which is odd. | |
| 353 # Yet another occurrance of whichdb not being able to recognise older bsddb | |
| 354 # databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the | |
| 355 # process. | |
| 356 # | |
| 357 # Revision 1.17 2002/01/22 05:06:09 rochecompaan | |
| 358 # We need to keep the last 'set' entry in the journal to preserve | |
| 359 # information on 'activity' for nodes. | |
| 360 # | |
| 361 # Revision 1.16 2002/01/21 16:33:20 rochecompaan | |
| 362 # You can now use the roundup-admin tool to pack the database | |
| 363 # | |
| 364 # Revision 1.15 2002/01/19 13:16:04 rochecompaan | |
| 365 # Journal entries for link and multilink properties can now be switched on | |
| 366 # or off. | |
| 367 # | |
| 368 # Revision 1.14 2002/01/16 07:02:57 richard | |
| 369 # . lots of date/interval related changes: | |
| 370 # - more relaxed date format for input | |
| 371 # | |
| 372 # Revision 1.13 2002/01/14 02:20:15 richard | |
| 373 # . changed all config accesses so they access either the instance or the | |
| 374 # config attriubute on the db. This means that all config is obtained from | |
| 375 # instance_config instead of the mish-mash of classes. This will make | |
| 376 # switching to a ConfigParser setup easier too, I hope. | |
| 377 # | |
| 378 # At a minimum, this makes migration a _little_ easier (a lot easier in the | |
| 379 # 0.5.0 switch, I hope!) | |
| 380 # | |
| 381 # Revision 1.12 2001/12/17 03:52:48 richard | |
| 382 # Implemented file store rollback. As a bonus, the hyperdb is now capable of | |
| 383 # storing more than one file per node - if a property name is supplied, | |
| 384 # the file is called designator.property. | |
| 385 # I decided not to migrate the existing files stored over to the new naming | |
| 386 # scheme - the FileClass just doesn't specify the property name. | |
| 387 # | |
| 263 # Revision 1.11 2001/12/10 23:17:20 richard | 388 # Revision 1.11 2001/12/10 23:17:20 richard |
| 264 # Added transaction tests to test_db | 389 # Added transaction tests to test_db |
| 265 # | 390 # |
| 266 # Revision 1.10 2001/12/03 21:33:39 richard | 391 # Revision 1.10 2001/12/03 21:33:39 richard |
| 267 # Fixes so the tests use commit and not close | 392 # Fixes so the tests use commit and not close |
