Mercurial > p > roundup > code
comparison test/test_db.py @ 676:bc46480e2a2b
Fixed serialisation problem...
...by moving the serialisation step out of the hyperdb.Class (get,
set) into the hyperdb.Database.
Also fixed htmltemplate after the showid changes I made yesterday.
Unit tests for all of the above written.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 03 Apr 2002 05:54:31 +0000 |
| parents | 07abfe8f0c01 |
| children | 509a101305da |
comparison
equal
deleted
inserted
replaced
| 675:e04d291a1194 | 676:bc46480e2a2b |
|---|---|
| 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.19 2002-02-25 14:34:31 grubert Exp $ | 18 # $Id: test_db.py,v 1.20 2002-04-03 05:54:31 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 from roundup import date, password |
| 26 | 26 |
| 27 def setupSchema(db, create): | 27 def setupSchema(db, create): |
| 28 status = Class(db, "status", name=String()) | 28 status = Class(db, "status", name=String()) |
| 29 status.setkey("name") | 29 status.setkey("name") |
| 30 if create: | 30 if create: |
| 82 self.db.issue.set('5', status='2') | 82 self.db.issue.set('5', status='2') |
| 83 self.db.issue.get('5', "status") | 83 self.db.issue.get('5', "status") |
| 84 | 84 |
| 85 a = self.db.issue.get('5', "deadline") | 85 a = self.db.issue.get('5', "deadline") |
| 86 self.db.issue.set('5', deadline=date.Date()) | 86 self.db.issue.set('5', deadline=date.Date()) |
| 87 self.assertNotEqual(a, self.db.issue.get('5', "deadline")) | 87 b = self.db.issue.get('5', "deadline") |
| 88 self.db.commit() | |
| 89 self.assertNotEqual(a, b) | |
| 90 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00')) | |
| 91 self.db.issue.set('5', deadline=date.Date()) | |
| 88 | 92 |
| 89 a = self.db.issue.get('5', "foo") | 93 a = self.db.issue.get('5', "foo") |
| 90 self.db.issue.set('5', foo=date.Interval('-1d')) | 94 self.db.issue.set('5', foo=date.Interval('-1d')) |
| 91 self.assertNotEqual(a, self.db.issue.get('5', "foo")) | 95 self.assertNotEqual(a, self.db.issue.get('5', "foo")) |
| 92 | 96 |
| 95 self.db.issue.find(status = self.db.status.lookup("in-progress")) | 99 self.db.issue.find(status = self.db.status.lookup("in-progress")) |
| 96 self.db.commit() | 100 self.db.commit() |
| 97 self.db.issue.history('5') | 101 self.db.issue.history('5') |
| 98 self.db.status.history('1') | 102 self.db.status.history('1') |
| 99 self.db.status.history('2') | 103 self.db.status.history('2') |
| 104 | |
| 105 def testSerialisation(self): | |
| 106 self.db.issue.create(title="spam", status='1', | |
| 107 deadline=date.Date(), foo=date.Interval('-1d')) | |
| 108 self.db.commit() | |
| 109 assert isinstance(self.db.issue.get('1', 'deadline'), date.Date) | |
| 110 assert isinstance(self.db.issue.get('1', 'foo'), date.Interval) | |
| 111 self.db.user.create(username="fozzy", | |
| 112 password=password.Password('t. bear')) | |
| 113 self.db.commit() | |
| 114 assert isinstance(self.db.user.get('1', 'password'), password.Password) | |
| 100 | 115 |
| 101 def testTransactions(self): | 116 def testTransactions(self): |
| 102 # remember the number of items we started | 117 # remember the number of items we started |
| 103 num_issues = len(self.db.issue.list()) | 118 num_issues = len(self.db.issue.list()) |
| 104 num_files = self.db.numfiles() | 119 num_files = self.db.numfiles() |
| 322 self.db = bsddb3.Database(config) | 337 self.db = bsddb3.Database(config) |
| 323 setupSchema(self.db, 0) | 338 setupSchema(self.db, 0) |
| 324 | 339 |
| 325 | 340 |
| 326 def suite(): | 341 def suite(): |
| 327 l = [unittest.makeSuite(anydbmDBTestCase, 'test'), | 342 l = [ |
| 343 unittest.makeSuite(anydbmDBTestCase, 'test'), | |
| 328 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') | 344 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') |
| 329 ] | 345 ] |
| 330 | 346 |
| 331 try: | 347 try: |
| 332 import bsddb | 348 import bsddb |
| 344 | 360 |
| 345 return unittest.TestSuite(l) | 361 return unittest.TestSuite(l) |
| 346 | 362 |
| 347 # | 363 # |
| 348 # $Log: not supported by cvs2svn $ | 364 # $Log: not supported by cvs2svn $ |
| 365 # Revision 1.19 2002/02/25 14:34:31 grubert | |
| 366 # . use blobfiles in back_anydbm which is used in back_bsddb. | |
| 367 # change test_db as dirlist does not work for subdirectories. | |
| 368 # ATTENTION: blobfiles now creates subdirectories for files. | |
| 369 # | |
| 349 # Revision 1.18 2002/01/22 07:21:13 richard | 370 # Revision 1.18 2002/01/22 07:21:13 richard |
| 350 # . fixed back_bsddb so it passed the journal tests | 371 # . fixed back_bsddb so it passed the journal tests |
| 351 # | 372 # |
| 352 # ... it didn't seem happy using the back_anydbm _open method, which is odd. | 373 # ... 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 | 374 # Yet another occurrance of whichdb not being able to recognise older bsddb |
