Mercurial > p > roundup > code
comparison test/test_db.py @ 902:b0d3d3535998
Bugger it. Here's the current shape of the new security implementation.
Still to do:
. call the security funcs from cgi and mailgw
. change shipped templates to include correct initialisation and remove
the old config vars
... that seems like a lot. The bulk of the work has been done though. Honest :)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 25 Jul 2002 07:14:06 +0000 |
| parents | 974a4b94c5e3 |
| children | 502a5ae11cc5 |
comparison
equal
deleted
inserted
replaced
| 901:31a62bcb9c80 | 902:b0d3d3535998 |
|---|---|
| 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.36 2002-07-19 03:36:34 richard Exp $ | 18 # $Id: test_db.py,v 1.37 2002-07-25 07:14:06 richard Exp $ |
| 19 | 19 |
| 20 import unittest, os, shutil, time | 20 import unittest, os, shutil, time |
| 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 | 23 Interval, DatabaseError, Boolean, Number |
| 26 | 26 |
| 27 def setupSchema(db, create, module): | 27 def setupSchema(db, create, module): |
| 28 status = module.Class(db, "status", name=String()) | 28 status = module.Class(db, "status", name=String()) |
| 29 status.setkey("name") | 29 status.setkey("name") |
| 30 user = module.Class(db, "user", username=String(), password=Password(), | 30 user = module.Class(db, "user", username=String(), password=Password(), |
| 31 assignable=Boolean(), age=Number()) | 31 assignable=Boolean(), age=Number(), roles=Multilink('role')) |
| 32 user.setkey("username") | |
| 32 file = module.FileClass(db, "file", name=String(), type=String(), | 33 file = module.FileClass(db, "file", name=String(), type=String(), |
| 33 comment=String(indexme="yes")) | 34 comment=String(indexme="yes")) |
| 34 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), | 35 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), |
| 35 status=Link("status"), nosy=Multilink("user"), deadline=Date(), | 36 status=Link("status"), nosy=Multilink("user"), deadline=Date(), |
| 36 foo=Interval(), files=Multilink("file")) | 37 foo=Interval(), files=Multilink("file"), assignedto=Link('user')) |
| 37 session = module.Class(db, 'session', title=String()) | 38 session = module.Class(db, 'session', title=String()) |
| 38 session.disableJournalling() | 39 session.disableJournalling() |
| 39 db.post_init() | 40 db.post_init() |
| 40 if create: | 41 if create: |
| 41 status.create(name="unread") | 42 status.create(name="unread") |
| 111 a = self.db.issue.get('1', "foo") | 112 a = self.db.issue.get('1', "foo") |
| 112 self.db.issue.set('1', foo=date.Interval('-1d')) | 113 self.db.issue.set('1', foo=date.Interval('-1d')) |
| 113 self.assertNotEqual(self.db.issue.get('1', "foo"), a) | 114 self.assertNotEqual(self.db.issue.get('1', "foo"), a) |
| 114 | 115 |
| 115 def testBooleanChange(self): | 116 def testBooleanChange(self): |
| 116 self.db.user.create(username='foo', assignable=1) | 117 userid = self.db.user.create(username='foo', assignable=1) |
| 117 self.db.user.create(username='foo', assignable=0) | 118 self.db.user.create(username='foo2', assignable=0) |
| 118 a = self.db.user.get('1', 'assignable') | 119 a = self.db.user.get(userid, 'assignable') |
| 119 self.db.user.set('1', assignable=0) | 120 self.db.user.set(userid, assignable=0) |
| 120 self.assertNotEqual(self.db.user.get('1', 'assignable'), a) | 121 self.assertNotEqual(self.db.user.get(userid, 'assignable'), a) |
| 121 self.db.user.set('1', assignable=0) | 122 self.db.user.set(userid, assignable=0) |
| 122 self.db.user.set('1', assignable=1) | 123 self.db.user.set(userid, assignable=1) |
| 123 | 124 |
| 124 def testNumberChange(self): | 125 def testNumberChange(self): |
| 125 self.db.user.create(username='foo', age='1') | 126 self.db.user.create(username='foo', age='1') |
| 126 a = self.db.user.get('1', 'age') | 127 a = self.db.user.get('1', 'age') |
| 127 self.db.user.set('1', age='3') | 128 self.db.user.set('1', age='3') |
| 128 self.assertNotEqual(self.db.user.get('1', 'age'), a) | 129 self.assertNotEqual(self.db.user.get('1', 'age'), a) |
| 129 self.db.user.set('1', age='1.0') | 130 self.db.user.set('1', age='1.0') |
| 130 | 131 |
| 131 def testNewProperty(self): | 132 def testNewProperty(self): |
| 132 ' make sure a new property is added ok ' | |
| 133 self.db.issue.create(title="spam", status='1') | 133 self.db.issue.create(title="spam", status='1') |
| 134 self.db.issue.addprop(fixer=Link("user")) | 134 self.db.issue.addprop(fixer=Link("user")) |
| 135 props = self.db.issue.getprops() | 135 props = self.db.issue.getprops() |
| 136 keys = props.keys() | 136 keys = props.keys() |
| 137 keys.sort() | 137 keys.sort() |
| 138 self.assertEqual(keys, ['activity', 'creation', 'creator', 'deadline', | 138 self.assertEqual(keys, ['activity', 'assignedto', 'creation', |
| 139 'files', 'fixer', 'foo', 'id', 'messages', 'nosy', 'status', | 139 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', |
| 140 'superseder', 'title']) | 140 'nosy', 'status', 'superseder', 'title']) |
| 141 self.assertEqual(self.db.issue.get('1', "fixer"), None) | 141 self.assertEqual(self.db.issue.get('1', "fixer"), None) |
| 142 | 142 |
| 143 def testRetire(self): | 143 def testRetire(self): |
| 144 self.db.issue.create(title="spam", status='1') | 144 self.db.issue.create(title="spam", status='1') |
| 145 b = self.db.status.get('1', 'name') | 145 b = self.db.status.get('1', 'name') |
| 191 self.db.rollback() | 191 self.db.rollback() |
| 192 self.assertNotEqual(num_files, self.db.numfiles()) | 192 self.assertNotEqual(num_files, self.db.numfiles()) |
| 193 self.assertEqual(num_files2, self.db.numfiles()) | 193 self.assertEqual(num_files2, self.db.numfiles()) |
| 194 | 194 |
| 195 def testDestroyNoJournalling(self): | 195 def testDestroyNoJournalling(self): |
| 196 ' test destroy on a class with no journalling ' | |
| 197 self.innerTestDestroy(klass=self.db.session) | 196 self.innerTestDestroy(klass=self.db.session) |
| 198 | 197 |
| 199 def testDestroyJournalling(self): | 198 def testDestroyJournalling(self): |
| 200 ' test destroy on a class with journalling ' | |
| 201 self.innerTestDestroy(klass=self.db.issue) | 199 self.innerTestDestroy(klass=self.db.issue) |
| 202 | 200 |
| 203 def innerTestDestroy(self, klass): | 201 def innerTestDestroy(self, klass): |
| 204 newid = klass.create(title='Mr Friendly') | 202 newid = klass.create(title='Mr Friendly') |
| 205 n = len(klass.list()) | 203 n = len(klass.list()) |
| 330 self.assertEqual(nodeid, '1') | 328 self.assertEqual(nodeid, '1') |
| 331 self.assertEqual(journaltag, 'test') | 329 self.assertEqual(journaltag, 'test') |
| 332 self.assertEqual(action, 'create') | 330 self.assertEqual(action, 'create') |
| 333 keys = params.keys() | 331 keys = params.keys() |
| 334 keys.sort() | 332 keys.sort() |
| 335 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', | 333 self.assertEqual(keys, ['assignedto', 'deadline', 'files', 'fixer', |
| 336 'messages', 'nosy', 'status', 'superseder', 'title']) | 334 'foo', 'messages', 'nosy', 'status', 'superseder', 'title']) |
| 337 self.assertEqual(None,params['deadline']) | 335 self.assertEqual(None,params['deadline']) |
| 338 self.assertEqual(None,params['fixer']) | 336 self.assertEqual(None,params['fixer']) |
| 339 self.assertEqual(None,params['foo']) | 337 self.assertEqual(None,params['foo']) |
| 340 self.assertEqual([],params['nosy']) | 338 self.assertEqual([],params['nosy']) |
| 341 self.assertEqual('1',params['status']) | 339 self.assertEqual('1',params['status']) |
| 453 setupSchema(self.db, 0, anydbm) | 451 setupSchema(self.db, 0, anydbm) |
| 454 self.db2 = anydbm.Database(config, 'test') | 452 self.db2 = anydbm.Database(config, 'test') |
| 455 setupSchema(self.db2, 0, anydbm) | 453 setupSchema(self.db2, 0, anydbm) |
| 456 | 454 |
| 457 def testExceptions(self): | 455 def testExceptions(self): |
| 458 ' make sure exceptions are raised on writes to a read-only db ' | |
| 459 # this tests the exceptions that should be raised | 456 # this tests the exceptions that should be raised |
| 460 ar = self.assertRaises | 457 ar = self.assertRaises |
| 461 | 458 |
| 462 # this tests the exceptions that should be raised | 459 # this tests the exceptions that should be raised |
| 463 ar(DatabaseError, self.db.status.create, name="foo") | 460 ar(DatabaseError, self.db.status.create, name="foo") |
| 604 | 601 |
| 605 return unittest.TestSuite(l) | 602 return unittest.TestSuite(l) |
| 606 | 603 |
| 607 # | 604 # |
| 608 # $Log: not supported by cvs2svn $ | 605 # $Log: not supported by cvs2svn $ |
| 606 # Revision 1.36 2002/07/19 03:36:34 richard | |
| 607 # Implemented the destroy() method needed by the session database (and possibly | |
| 608 # others). At the same time, I removed the leading underscores from the hyperdb | |
| 609 # methods that Really Didn't Need Them. | |
| 610 # The journal also raises IndexError now for all situations where there is a | |
| 611 # request for the journal of a node that doesn't have one. It used to return | |
| 612 # [] in _some_ situations, but not all. This _may_ break code, but the tests | |
| 613 # pass... | |
| 614 # | |
| 609 # Revision 1.35 2002/07/18 23:07:08 richard | 615 # Revision 1.35 2002/07/18 23:07:08 richard |
| 610 # Unit tests and a few fixes. | 616 # Unit tests and a few fixes. |
| 611 # | 617 # |
| 612 # Revision 1.34 2002/07/18 11:52:00 richard | 618 # Revision 1.34 2002/07/18 11:52:00 richard |
| 613 # oops | 619 # oops |
