comparison test/test_db.py @ 891:974a4b94c5e3

Implemented the destroy() method needed by the session database... (and possibly others). At the same time, I removed the leading underscores from the hyperdb methods that Really Didn't Need Them. The journal also raises IndexError now for all situations where there is a request for the journal of a node that doesn't have one. It used to return [] in _some_ situations, but not all. This _may_ break code, but the tests pass...
author Richard Jones <richard@users.sourceforge.net>
date Fri, 19 Jul 2002 03:36:34 +0000
parents a568596dbea7
children b0d3d3535998
comparison
equal deleted inserted replaced
890:a568596dbea7 891:974a4b94c5e3
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.35 2002-07-18 23:07:08 richard Exp $ 18 # $Id: test_db.py,v 1.36 2002-07-19 03:36:34 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
32 file = module.FileClass(db, "file", name=String(), type=String(), 32 file = module.FileClass(db, "file", name=String(), type=String(),
33 comment=String(indexme="yes")) 33 comment=String(indexme="yes"))
34 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), 34 issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
35 status=Link("status"), nosy=Multilink("user"), deadline=Date(), 35 status=Link("status"), nosy=Multilink("user"), deadline=Date(),
36 foo=Interval(), files=Multilink("file")) 36 foo=Interval(), files=Multilink("file"))
37 session = module.Class(db, 'session', title=String())
38 session.disableJournalling()
37 db.post_init() 39 db.post_init()
38 if create: 40 if create:
39 status.create(name="unread") 41 status.create(name="unread")
40 status.create(name="in-progress") 42 status.create(name="in-progress")
41 status.create(name="testing") 43 status.create(name="testing")
187 self.assertNotEqual(num_files, num_files2) 189 self.assertNotEqual(num_files, num_files2)
188 self.db.file.create(name="test", type="text/plain", content="hi") 190 self.db.file.create(name="test", type="text/plain", content="hi")
189 self.db.rollback() 191 self.db.rollback()
190 self.assertNotEqual(num_files, self.db.numfiles()) 192 self.assertNotEqual(num_files, self.db.numfiles())
191 self.assertEqual(num_files2, self.db.numfiles()) 193 self.assertEqual(num_files2, self.db.numfiles())
194
195 def testDestroyNoJournalling(self):
196 ' test destroy on a class with no journalling '
197 self.innerTestDestroy(klass=self.db.session)
198
199 def testDestroyJournalling(self):
200 ' test destroy on a class with journalling '
201 self.innerTestDestroy(klass=self.db.issue)
202
203 def innerTestDestroy(self, klass):
204 newid = klass.create(title='Mr Friendly')
205 n = len(klass.list())
206 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
207 klass.destroy(newid)
208 self.assertRaises(IndexError, klass.get, newid, 'title')
209 self.assertNotEqual(len(klass.list()), n)
210 if klass.do_journal:
211 self.assertRaises(IndexError, klass.history, newid)
212
213 # now with a commit
214 newid = klass.create(title='Mr Friendly')
215 n = len(klass.list())
216 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
217 self.db.commit()
218 klass.destroy(newid)
219 self.assertRaises(IndexError, klass.get, newid, 'title')
220 self.db.commit()
221 self.assertRaises(IndexError, klass.get, newid, 'title')
222 self.assertNotEqual(len(klass.list()), n)
223 if klass.do_journal:
224 self.assertRaises(IndexError, klass.history, newid)
225
226 # now with a rollback
227 newid = klass.create(title='Mr Friendly')
228 n = len(klass.list())
229 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
230 self.db.commit()
231 klass.destroy(newid)
232 self.assertNotEqual(len(klass.list()), n)
233 self.assertRaises(IndexError, klass.get, newid, 'title')
234 self.db.rollback()
235 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
236 self.assertEqual(len(klass.list()), n)
237 if klass.do_journal:
238 self.assertNotEqual(klass.history(newid), [])
192 239
193 def testExceptions(self): 240 def testExceptions(self):
194 # this tests the exceptions that should be raised 241 # this tests the exceptions that should be raised
195 ar = self.assertRaises 242 ar = self.assertRaises
196 243
557 604
558 return unittest.TestSuite(l) 605 return unittest.TestSuite(l)
559 606
560 # 607 #
561 # $Log: not supported by cvs2svn $ 608 # $Log: not supported by cvs2svn $
609 # Revision 1.35 2002/07/18 23:07:08 richard
610 # Unit tests and a few fixes.
611 #
562 # Revision 1.34 2002/07/18 11:52:00 richard 612 # Revision 1.34 2002/07/18 11:52:00 richard
563 # oops 613 # oops
564 # 614 #
565 # Revision 1.33 2002/07/18 11:50:58 richard 615 # Revision 1.33 2002/07/18 11:50:58 richard
566 # added tests for number type too 616 # added tests for number type too

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