comparison test/test_db.py @ 461:b579418f7ed1

Implemented file store rollback. As a bonus, the hyperdb is now capable of storing more than one file per node - if a property name is supplied, the file is called designator.property. I decided not to migrate the existing files stored over to the new naming scheme - the FileClass just doesn't specify the property name.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 17 Dec 2001 03:52:48 +0000
parents 698534628072
children dce4c75bef5a c242455d9b46
comparison
equal deleted inserted replaced
460:9c895b44240a 461:b579418f7ed1
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.11 2001-12-10 23:17:20 richard Exp $ 18 # $Id: test_db.py,v 1.12 2001-12-17 03:52:48 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 25
25 def setupSchema(db, create): 26 def setupSchema(db, create):
26 status = Class(db, "status", name=String()) 27 status = Class(db, "status", name=String())
27 status.setkey("name") 28 status.setkey("name")
28 if create: 29 if create:
31 status.create(name="testing") 32 status.create(name="testing")
32 status.create(name="resolved") 33 status.create(name="resolved")
33 Class(db, "user", username=String(), password=Password()) 34 Class(db, "user", username=String(), password=Password())
34 Class(db, "issue", title=String(), status=Link("status"), 35 Class(db, "issue", title=String(), status=Link("status"),
35 nosy=Multilink("user")) 36 nosy=Multilink("user"))
37 FileClass(db, "file", name=String(), type=String())
36 db.commit() 38 db.commit()
37 39
38 class MyTestCase(unittest.TestCase): 40 class MyTestCase(unittest.TestCase):
39 def tearDown(self): 41 def tearDown(self):
40 if os.path.exists('_test_dir'): 42 if os.path.exists('_test_dir'):
44 def setUp(self): 46 def setUp(self):
45 from roundup.backends import anydbm 47 from roundup.backends import anydbm
46 # remove previous test, ignore errors 48 # remove previous test, ignore errors
47 if os.path.exists('_test_dir'): 49 if os.path.exists('_test_dir'):
48 shutil.rmtree('_test_dir') 50 shutil.rmtree('_test_dir')
49 os.mkdir('_test_dir') 51 os.makedirs('_test_dir/files')
50 self.db = anydbm.Database('_test_dir', 'test') 52 self.db = anydbm.Database('_test_dir', 'test')
51 setupSchema(self.db, 1) 53 setupSchema(self.db, 1)
52 54
53 def testChanges(self): 55 def testChanges(self):
54 self.db.issue.create(title="spam", status='1') 56 self.db.issue.create(title="spam", status='1')
71 self.db.status.history('1') 73 self.db.status.history('1')
72 self.db.status.history('2') 74 self.db.status.history('2')
73 75
74 def testTransactions(self): 76 def testTransactions(self):
75 num_issues = len(self.db.issue.list()) 77 num_issues = len(self.db.issue.list())
78 files_dir = os.path.join('_test_dir', 'files')
79 if os.path.exists(files_dir):
80 num_files = len(os.listdir(files_dir))
81 else:
82 num_files = 0
76 self.db.issue.create(title="don't commit me!", status='1') 83 self.db.issue.create(title="don't commit me!", status='1')
77 self.assertNotEqual(num_issues, len(self.db.issue.list())) 84 self.assertNotEqual(num_issues, len(self.db.issue.list()))
78 self.db.rollback() 85 self.db.rollback()
79 self.assertEqual(num_issues, len(self.db.issue.list())) 86 self.assertEqual(num_issues, len(self.db.issue.list()))
80 self.db.issue.create(title="please commit me!", status='1') 87 self.db.issue.create(title="please commit me!", status='1')
81 self.assertNotEqual(num_issues, len(self.db.issue.list())) 88 self.assertNotEqual(num_issues, len(self.db.issue.list()))
82 self.db.commit() 89 self.db.commit()
83 self.assertNotEqual(num_issues, len(self.db.issue.list())) 90 self.assertNotEqual(num_issues, len(self.db.issue.list()))
84 self.db.rollback() 91 self.db.rollback()
85 self.assertNotEqual(num_issues, len(self.db.issue.list())) 92 self.assertNotEqual(num_issues, len(self.db.issue.list()))
93 self.db.file.create(name="test", type="text/plain", content="hi")
94 self.db.rollback()
95 self.assertEqual(num_files, len(os.listdir(files_dir)))
96 self.db.file.create(name="test", type="text/plain", content="hi")
97 self.db.commit()
98 self.assertNotEqual(num_files, len(os.listdir(files_dir)))
99 num_files2 = len(os.listdir(files_dir))
100 self.db.file.create(name="test", type="text/plain", content="hi")
101 self.db.rollback()
102 self.assertNotEqual(num_files, len(os.listdir(files_dir)))
103 self.assertEqual(num_files2, len(os.listdir(files_dir)))
104
86 105
87 def testExceptions(self): 106 def testExceptions(self):
88 # this tests the exceptions that should be raised 107 # this tests the exceptions that should be raised
89 ar = self.assertRaises 108 ar = self.assertRaises
90 109
154 def setUp(self): 173 def setUp(self):
155 from roundup.backends import anydbm 174 from roundup.backends import anydbm
156 # remove previous test, ignore errors 175 # remove previous test, ignore errors
157 if os.path.exists('_test_dir'): 176 if os.path.exists('_test_dir'):
158 shutil.rmtree('_test_dir') 177 shutil.rmtree('_test_dir')
159 os.mkdir('_test_dir') 178 os.makedirs('_test_dir/files')
160 db = anydbm.Database('_test_dir', 'test') 179 db = anydbm.Database('_test_dir', 'test')
161 setupSchema(db, 1) 180 setupSchema(db, 1)
162 self.db = anydbm.Database('_test_dir') 181 self.db = anydbm.Database('_test_dir')
163 setupSchema(self.db, 0) 182 setupSchema(self.db, 0)
164 183
176 def setUp(self): 195 def setUp(self):
177 from roundup.backends import bsddb 196 from roundup.backends import bsddb
178 # remove previous test, ignore errors 197 # remove previous test, ignore errors
179 if os.path.exists('_test_dir'): 198 if os.path.exists('_test_dir'):
180 shutil.rmtree('_test_dir') 199 shutil.rmtree('_test_dir')
181 os.mkdir('_test_dir') 200 os.makedirs('_test_dir/files')
182 self.db = bsddb.Database('_test_dir', 'test') 201 self.db = bsddb.Database('_test_dir', 'test')
183 setupSchema(self.db, 1) 202 setupSchema(self.db, 1)
184 203
185 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 204 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
186 def setUp(self): 205 def setUp(self):
187 from roundup.backends import bsddb 206 from roundup.backends import bsddb
188 # remove previous test, ignore errors 207 # remove previous test, ignore errors
189 if os.path.exists('_test_dir'): 208 if os.path.exists('_test_dir'):
190 shutil.rmtree('_test_dir') 209 shutil.rmtree('_test_dir')
191 os.mkdir('_test_dir') 210 os.makedirs('_test_dir/files')
192 db = bsddb.Database('_test_dir', 'test') 211 db = bsddb.Database('_test_dir', 'test')
193 setupSchema(db, 1) 212 setupSchema(db, 1)
194 self.db = bsddb.Database('_test_dir') 213 self.db = bsddb.Database('_test_dir')
195 setupSchema(self.db, 0) 214 setupSchema(self.db, 0)
196 215
199 def setUp(self): 218 def setUp(self):
200 from roundup.backends import bsddb3 219 from roundup.backends import bsddb3
201 # remove previous test, ignore errors 220 # remove previous test, ignore errors
202 if os.path.exists('_test_dir'): 221 if os.path.exists('_test_dir'):
203 shutil.rmtree('_test_dir') 222 shutil.rmtree('_test_dir')
204 os.mkdir('_test_dir') 223 os.makedirs('_test_dir/files')
205 self.db = bsddb3.Database('_test_dir', 'test') 224 self.db = bsddb3.Database('_test_dir', 'test')
206 setupSchema(self.db, 1) 225 setupSchema(self.db, 1)
207 226
208 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 227 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
209 def setUp(self): 228 def setUp(self):
210 from roundup.backends import bsddb3 229 from roundup.backends import bsddb3
211 # remove previous test, ignore errors 230 # remove previous test, ignore errors
212 if os.path.exists('_test_dir'): 231 if os.path.exists('_test_dir'):
213 shutil.rmtree('_test_dir') 232 shutil.rmtree('_test_dir')
214 os.mkdir('_test_dir') 233 os.makedirs('_test_dir/files')
215 db = bsddb3.Database('_test_dir', 'test') 234 db = bsddb3.Database('_test_dir', 'test')
216 setupSchema(db, 1) 235 setupSchema(db, 1)
217 self.db = bsddb3.Database('_test_dir') 236 self.db = bsddb3.Database('_test_dir')
218 setupSchema(self.db, 0) 237 setupSchema(self.db, 0)
219 238
239 258
240 return unittest.TestSuite(l) 259 return unittest.TestSuite(l)
241 260
242 # 261 #
243 # $Log: not supported by cvs2svn $ 262 # $Log: not supported by cvs2svn $
263 # Revision 1.11 2001/12/10 23:17:20 richard
264 # Added transaction tests to test_db
265 #
244 # Revision 1.10 2001/12/03 21:33:39 richard 266 # Revision 1.10 2001/12/03 21:33:39 richard
245 # Fixes so the tests use commit and not close 267 # Fixes so the tests use commit and not close
246 # 268 #
247 # Revision 1.9 2001/12/02 05:06:16 richard 269 # Revision 1.9 2001/12/02 05:06:16 richard
248 # . We now use weakrefs in the Classes to keep the database reference, so 270 # . We now use weakrefs in the Classes to keep the database reference, so

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