comparison test/db_test_base.py @ 1951:767ff2a03eee

more unit tests to improve coverage (up from 85% to 88% for anydbm! :)
author Richard Jones <richard@users.sourceforge.net>
date Fri, 05 Dec 2003 09:47:46 +0000
parents b7912efc7f57
children b00ad075bb2f
comparison
equal deleted inserted replaced
1950:1eba6b6ca159 1951:767ff2a03eee
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: db_test_base.py,v 1.10 2003-11-16 22:56:46 jlgijsbers Exp $ 18 # $Id: db_test_base.py,v 1.11 2003-12-05 09:47:46 richard Exp $
19 19
20 import unittest, os, shutil, errno, imp, sys, time, pprint 20 import unittest, os, shutil, errno, imp, sys, time, pprint
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, Node 23 Interval, DatabaseError, Boolean, Number, Node
34 file = module.FileClass(db, "file", name=String(), type=String(), 34 file = module.FileClass(db, "file", name=String(), type=String(),
35 comment=String(indexme="yes"), fooz=Password()) 35 comment=String(indexme="yes"), fooz=Password())
36 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), 36 issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
37 status=Link("status"), nosy=Multilink("user"), deadline=Date(), 37 status=Link("status"), nosy=Multilink("user"), deadline=Date(),
38 foo=Interval(), files=Multilink("file"), assignedto=Link('user')) 38 foo=Interval(), files=Multilink("file"), assignedto=Link('user'))
39 stuff = module.Class(db, "stuff", stuff=String())
39 session = module.Class(db, 'session', title=String()) 40 session = module.Class(db, 'session', title=String())
40 session.disableJournalling() 41 session.disableJournalling()
41 db.post_init() 42 db.post_init()
42 if create: 43 if create:
43 user.create(username="admin", roles='Admin') 44 user.create(username="admin", roles='Admin',
45 password=password.Password('sekrit'))
44 status.create(name="unread") 46 status.create(name="unread")
45 status.create(name="in-progress") 47 status.create(name="in-progress")
46 status.create(name="testing") 48 status.create(name="testing")
47 status.create(name="resolved") 49 status.create(name="resolved")
48 db.commit() 50 db.commit()
76 shutil.rmtree(config.DATABASE) 78 shutil.rmtree(config.DATABASE)
77 os.makedirs(config.DATABASE + '/files') 79 os.makedirs(config.DATABASE + '/files')
78 self.db = self.module.Database(config, 'admin') 80 self.db = self.module.Database(config, 'admin')
79 setupSchema(self.db, 1, self.module) 81 setupSchema(self.db, 1, self.module)
80 82
81 # 83 def testRefresh(self):
82 # schema mutation 84 self.db.refresh_database()
83 #
84 def testAddProperty(self):
85 self.db.issue.create(title="spam", status='1')
86 self.db.commit()
87
88 self.db.issue.addprop(fixer=Link("user"))
89 # force any post-init stuff to happen
90 self.db.post_init()
91 props = self.db.issue.getprops()
92 keys = props.keys()
93 keys.sort()
94 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
95 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
96 'nosy', 'status', 'superseder', 'title'])
97 self.assertEqual(self.db.issue.get('1', "fixer"), None)
98
99 def testRemoveProperty(self):
100 self.db.issue.create(title="spam", status='1')
101 self.db.commit()
102
103 del self.db.issue.properties['title']
104 self.db.post_init()
105 props = self.db.issue.getprops()
106 keys = props.keys()
107 keys.sort()
108 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
109 'creator', 'deadline', 'files', 'foo', 'id', 'messages',
110 'nosy', 'status', 'superseder'])
111 self.assertEqual(self.db.issue.list(), ['1'])
112
113 def testAddRemoveProperty(self):
114 self.db.issue.create(title="spam", status='1')
115 self.db.commit()
116
117 self.db.issue.addprop(fixer=Link("user"))
118 del self.db.issue.properties['title']
119 self.db.post_init()
120 props = self.db.issue.getprops()
121 keys = props.keys()
122 keys.sort()
123 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
124 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
125 'nosy', 'status', 'superseder'])
126 self.assertEqual(self.db.issue.list(), ['1'])
127 85
128 # 86 #
129 # basic operations 87 # basic operations
130 # 88 #
131 def testIDGeneration(self): 89 def testIDGeneration(self):
132 id1 = self.db.issue.create(title="spam", status='1') 90 id1 = self.db.issue.create(title="spam", status='1')
133 id2 = self.db.issue.create(title="eggs", status='2') 91 id2 = self.db.issue.create(title="eggs", status='2')
134 self.assertNotEqual(id1, id2) 92 self.assertNotEqual(id1, id2)
135 93
94 def testEmptySet(self):
95 id1 = self.db.issue.create(title="spam", status='1')
96 self.db.issue.set(id1)
97
136 def testStringChange(self): 98 def testStringChange(self):
137 for commit in (0,1): 99 for commit in (0,1):
138 # test set & retrieve 100 # test set & retrieve
139 nid = self.db.issue.create(title="spam", status='1') 101 nid = self.db.issue.create(title="spam", status='1')
140 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam') 102 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam')
153 self.db.issue.set(nid, title=None) 115 self.db.issue.set(nid, title=None)
154 if commit: self.db.commit() 116 if commit: self.db.commit()
155 self.assertEqual(self.db.issue.get(nid, "title"), None) 117 self.assertEqual(self.db.issue.get(nid, "title"), None)
156 118
157 def testLinkChange(self): 119 def testLinkChange(self):
120 self.assertRaises(IndexError, self.db.issue.create, title="spam",
121 status='100')
158 for commit in (0,1): 122 for commit in (0,1):
159 nid = self.db.issue.create(title="spam", status='1') 123 nid = self.db.issue.create(title="spam", status='1')
160 if commit: self.db.commit() 124 if commit: self.db.commit()
161 self.assertEqual(self.db.issue.get(nid, "status"), '1') 125 self.assertEqual(self.db.issue.get(nid, "status"), '1')
162 self.db.issue.set(nid, status='2') 126 self.db.issue.set(nid, status='2')
171 if commit: self.db.commit() 135 if commit: self.db.commit()
172 self.assertEqual(self.db.issue.get(nid, "status"), None) 136 self.assertEqual(self.db.issue.get(nid, "status"), None)
173 137
174 def testMultilinkChange(self): 138 def testMultilinkChange(self):
175 for commit in (0,1): 139 for commit in (0,1):
140 self.assertRaises(IndexError, self.db.issue.create, title="spam",
141 nosy=['foo%s'%commit])
176 u1 = self.db.user.create(username='foo%s'%commit) 142 u1 = self.db.user.create(username='foo%s'%commit)
177 u2 = self.db.user.create(username='bar%s'%commit) 143 u2 = self.db.user.create(username='bar%s'%commit)
178 nid = self.db.issue.create(title="spam", nosy=[u1]) 144 nid = self.db.issue.create(title="spam", nosy=[u1])
179 if commit: self.db.commit() 145 if commit: self.db.commit()
180 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1]) 146 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1])
184 self.db.issue.set(nid, nosy=[u1,u2]) 150 self.db.issue.set(nid, nosy=[u1,u2])
185 if commit: self.db.commit() 151 if commit: self.db.commit()
186 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1,u2]) 152 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1,u2])
187 153
188 def testDateChange(self): 154 def testDateChange(self):
155 self.assertRaises(TypeError, self.db.issue.create,
156 title='spam', deadline=1)
189 for commit in (0,1): 157 for commit in (0,1):
190 nid = self.db.issue.create(title="spam", status='1') 158 nid = self.db.issue.create(title="spam", status='1')
159 self.assertRaises(TypeError, self.db.issue.set, nid, deadline=1)
191 a = self.db.issue.get(nid, "deadline") 160 a = self.db.issue.get(nid, "deadline")
192 if commit: self.db.commit() 161 if commit: self.db.commit()
193 self.db.issue.set(nid, deadline=date.Date()) 162 self.db.issue.set(nid, deadline=date.Date())
194 b = self.db.issue.get(nid, "deadline") 163 b = self.db.issue.get(nid, "deadline")
195 if commit: self.db.commit() 164 if commit: self.db.commit()
205 self.db.issue.set(nid, deadline=None) 174 self.db.issue.set(nid, deadline=None)
206 if commit: self.db.commit() 175 if commit: self.db.commit()
207 self.assertEqual(self.db.issue.get(nid, "deadline"), None) 176 self.assertEqual(self.db.issue.get(nid, "deadline"), None)
208 177
209 def testIntervalChange(self): 178 def testIntervalChange(self):
179 self.assertRaises(TypeError, self.db.issue.create,
180 title='spam', foo=1)
210 for commit in (0,1): 181 for commit in (0,1):
211 nid = self.db.issue.create(title="spam", status='1') 182 nid = self.db.issue.create(title="spam", status='1')
183 self.assertRaises(TypeError, self.db.issue.set, nid, foo=1)
212 if commit: self.db.commit() 184 if commit: self.db.commit()
213 a = self.db.issue.get(nid, "foo") 185 a = self.db.issue.get(nid, "foo")
214 i = date.Interval('-1d') 186 i = date.Interval('-1d')
215 self.db.issue.set(nid, foo=i) 187 self.db.issue.set(nid, foo=i)
216 if commit: self.db.commit() 188 if commit: self.db.commit()
259 def testNumberUnset(self): 231 def testNumberUnset(self):
260 nid = self.db.user.create(username='foo', age=1) 232 nid = self.db.user.create(username='foo', age=1)
261 self.db.user.set(nid, age=None) 233 self.db.user.set(nid, age=None)
262 self.assertEqual(self.db.user.get(nid, "age"), None) 234 self.assertEqual(self.db.user.get(nid, "age"), None)
263 235
236 def testPasswordChange(self):
237 x = password.Password('x')
238 userid = self.db.user.create(username='foo', password=x)
239 self.assertEqual(x, self.db.user.get(userid, 'password'))
240 self.assertEqual(self.db.user.get(userid, 'password'), 'x')
241 y = password.Password('y')
242 self.db.user.set(userid, password=y)
243 self.assertEqual(self.db.user.get(userid, 'password'), 'y')
244 self.assertRaises(TypeError, self.db.user.create, userid,
245 username='bar', password='x')
246 self.assertRaises(TypeError, self.db.user.set, userid, password='x')
247
248 def testPasswordUnset(self):
249 x = password.Password('x')
250 nid = self.db.user.create(username='foo', password=x)
251 self.db.user.set(nid, assignable=None)
252 self.assertEqual(self.db.user.get(nid, "assignable"), None)
253
264 def testKeyValue(self): 254 def testKeyValue(self):
255 self.assertRaises(ValueError, self.db.user.create)
256
265 newid = self.db.user.create(username="spam") 257 newid = self.db.user.create(username="spam")
266 self.assertEqual(self.db.user.lookup('spam'), newid) 258 self.assertEqual(self.db.user.lookup('spam'), newid)
267 self.db.commit() 259 self.db.commit()
268 self.assertEqual(self.db.user.lookup('spam'), newid) 260 self.assertEqual(self.db.user.lookup('spam'), newid)
269 self.db.user.retire(newid) 261 self.db.user.retire(newid)
272 # use the key again now that the old is retired 264 # use the key again now that the old is retired
273 newid2 = self.db.user.create(username="spam") 265 newid2 = self.db.user.create(username="spam")
274 self.assertNotEqual(newid, newid2) 266 self.assertNotEqual(newid, newid2)
275 # try to restore old node. this shouldn't succeed! 267 # try to restore old node. this shouldn't succeed!
276 self.assertRaises(KeyError, self.db.user.restore, newid) 268 self.assertRaises(KeyError, self.db.user.restore, newid)
269
270 self.assertRaises(TypeError, self.db.issue.lookup, 'fubar')
271
272 def testLabelProp(self):
273 # key prop
274 self.assertEqual(self.db.status.labelprop(), 'name')
275 self.assertEqual(self.db.user.labelprop(), 'username')
276 # title
277 self.assertEqual(self.db.issue.labelprop(), 'title')
278 # name
279 self.assertEqual(self.db.file.labelprop(), 'name')
280 # id
281 self.assertEqual(self.db.stuff.labelprop(default_to_id=1), 'id')
277 282
278 def testRetire(self): 283 def testRetire(self):
279 self.db.issue.create(title="spam", status='1') 284 self.db.issue.create(title="spam", status='1')
280 b = self.db.status.get('1', 'name') 285 b = self.db.status.get('1', 'name')
281 a = self.db.status.list() 286 a = self.db.status.list()
282 self.db.status.retire('1') 287 self.db.status.retire('1')
283 # make sure the list is different 288 # make sure the list is different
284 self.assertNotEqual(a, self.db.status.list()) 289 self.assertNotEqual(a, self.db.status.list())
285 # can still access the node if necessary 290 # can still access the node if necessary
286 self.assertEqual(self.db.status.get('1', 'name'), b) 291 self.assertEqual(self.db.status.get('1', 'name'), b)
292 self.assertRaises(IndexError, self.db.status.set, '1', name='hello')
287 self.db.commit() 293 self.db.commit()
288 self.assertEqual(self.db.status.get('1', 'name'), b) 294 self.assertEqual(self.db.status.get('1', 'name'), b)
289 self.assertNotEqual(a, self.db.status.list()) 295 self.assertNotEqual(a, self.db.status.list())
290 # try to restore retired node 296 # try to restore retired node
291 self.db.status.restore('1') 297 self.db.status.restore('1')
354 360
355 def innerTestDestroy(self, klass): 361 def innerTestDestroy(self, klass):
356 newid = klass.create(title='Mr Friendly') 362 newid = klass.create(title='Mr Friendly')
357 n = len(klass.list()) 363 n = len(klass.list())
358 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly') 364 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
365 count = klass.count()
359 klass.destroy(newid) 366 klass.destroy(newid)
367 self.assertNotEqual(count, klass.count())
360 self.assertRaises(IndexError, klass.get, newid, 'title') 368 self.assertRaises(IndexError, klass.get, newid, 'title')
361 self.assertNotEqual(len(klass.list()), n) 369 self.assertNotEqual(len(klass.list()), n)
362 if klass.do_journal: 370 if klass.do_journal:
363 self.assertRaises(IndexError, klass.history, newid) 371 self.assertRaises(IndexError, klass.history, newid)
364 372
365 # now with a commit 373 # now with a commit
366 newid = klass.create(title='Mr Friendly') 374 newid = klass.create(title='Mr Friendly')
367 n = len(klass.list()) 375 n = len(klass.list())
368 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly') 376 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
369 self.db.commit() 377 self.db.commit()
378 count = klass.count()
370 klass.destroy(newid) 379 klass.destroy(newid)
380 self.assertNotEqual(count, klass.count())
371 self.assertRaises(IndexError, klass.get, newid, 'title') 381 self.assertRaises(IndexError, klass.get, newid, 'title')
372 self.db.commit() 382 self.db.commit()
373 self.assertRaises(IndexError, klass.get, newid, 'title') 383 self.assertRaises(IndexError, klass.get, newid, 'title')
374 self.assertNotEqual(len(klass.list()), n) 384 self.assertNotEqual(len(klass.list()), n)
375 if klass.do_journal: 385 if klass.do_journal:
378 # now with a rollback 388 # now with a rollback
379 newid = klass.create(title='Mr Friendly') 389 newid = klass.create(title='Mr Friendly')
380 n = len(klass.list()) 390 n = len(klass.list())
381 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly') 391 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
382 self.db.commit() 392 self.db.commit()
393 count = klass.count()
383 klass.destroy(newid) 394 klass.destroy(newid)
384 self.assertNotEqual(len(klass.list()), n) 395 self.assertNotEqual(len(klass.list()), n)
385 self.assertRaises(IndexError, klass.get, newid, 'title') 396 self.assertRaises(IndexError, klass.get, newid, 'title')
386 self.db.rollback() 397 self.db.rollback()
398 self.assertEqual(count, klass.count())
387 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly') 399 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
388 self.assertEqual(len(klass.list()), n) 400 self.assertEqual(len(klass.list()), n)
389 if klass.do_journal: 401 if klass.do_journal:
390 self.assertNotEqual(klass.history(newid), []) 402 self.assertNotEqual(klass.history(newid), [])
391 403
392 def testExceptions(self): 404 def testExceptions(self):
393 # this tests the exceptions that should be raised 405 # this tests the exceptions that should be raised
394 ar = self.assertRaises 406 ar = self.assertRaises
407
408 ar(KeyError, self.db.getclass, 'fubar')
395 409
396 # 410 #
397 # class create 411 # class create
398 # 412 #
399 # string property 413 # string property
400 ar(TypeError, self.db.status.create, name=1) 414 ar(TypeError, self.db.status.create, name=1)
415 # id, creation, creator and activity properties are reserved
416 ar(KeyError, self.db.status.create, id=1)
417 ar(KeyError, self.db.status.create, creation=1)
418 ar(KeyError, self.db.status.create, creator=1)
419 ar(KeyError, self.db.status.create, activity=1)
401 # invalid property name 420 # invalid property name
402 ar(KeyError, self.db.status.create, foo='foo') 421 ar(KeyError, self.db.status.create, foo='foo')
403 # key name clash 422 # key name clash
404 ar(ValueError, self.db.status.create, name='unread') 423 ar(ValueError, self.db.status.create, name='unread')
405 # invalid link index 424 # invalid link index
601 620
602 # 621 #
603 # searching tests follow 622 # searching tests follow
604 # 623 #
605 def testFind(self): 624 def testFind(self):
625 self.assertRaises(TypeError, self.db.issue.find, title='fubar')
626
606 self.db.user.create(username='test') 627 self.db.user.create(username='test')
607 ids = [] 628 ids = []
608 ids.append(self.db.issue.create(status="1", nosy=['1'])) 629 ids.append(self.db.issue.create(status="1", nosy=['1']))
609 oddid = self.db.issue.create(status="2", nosy=['2'], assignedto='2') 630 oddid = self.db.issue.create(status="2", nosy=['2'], assignedto='2')
610 ids.append(self.db.issue.create(status="1", nosy=['1','2'])) 631 ids.append(self.db.issue.create(status="1", nosy=['1','2']))
643 664
644 # none 665 # none
645 self.assertEqual(self.db.issue.find(status='4', nosy='3'), []) 666 self.assertEqual(self.db.issue.find(status='4', nosy='3'), [])
646 self.assertEqual(self.db.issue.find(status={'4':1}, nosy={'3':1}), []) 667 self.assertEqual(self.db.issue.find(status={'4':1}, nosy={'3':1}), [])
647 668
669 # test retiring a node
670 self.db.issue.retire(ids[0])
671 self.assertEqual(len(self.db.issue.find(status='1', nosy='2')), 2)
672
648 def testStringFind(self): 673 def testStringFind(self):
674 self.assertRaises(TypeError, self.db.issue.stringFind, status='1')
675
649 ids = [] 676 ids = []
650 ids.append(self.db.issue.create(title="spam")) 677 ids.append(self.db.issue.create(title="spam"))
651 self.db.issue.create(title="not spam") 678 self.db.issue.create(title="not spam")
652 ids.append(self.db.issue.create(title="spam")) 679 ids.append(self.db.issue.create(title="spam"))
653 ids.sort() 680 ids.sort()
654 got = self.db.issue.stringFind(title='spam') 681 got = self.db.issue.stringFind(title='spam')
655 got.sort() 682 got.sort()
656 self.assertEqual(got, ids) 683 self.assertEqual(got, ids)
657 self.assertEqual(self.db.issue.stringFind(title='fubar'), []) 684 self.assertEqual(self.db.issue.stringFind(title='fubar'), [])
685
686 # test retiring a node
687 self.db.issue.retire(ids[0])
688 self.assertEqual(len(self.db.issue.stringFind(title='spam')), 1)
658 689
659 def filteringSetup(self): 690 def filteringSetup(self):
660 for user in ( 691 for user in (
661 {'username': 'bleep'}, 692 {'username': 'bleep'},
662 {'username': 'blop'}, 693 {'username': 'blop'},
778 809
779 # import 810 # import
780 for cn, items in export.items(): 811 for cn, items in export.items():
781 klass = self.db.classes[cn] 812 klass = self.db.classes[cn]
782 names = items[0] 813 names = items[0]
814 maxid = 1
783 for itemprops in items[1:]: 815 for itemprops in items[1:]:
784 klass.import_list(names, itemprops) 816 maxid = max(maxid, int(klass.import_list(names, itemprops)))
785 817 self.db.setid(cn, str(maxid+1))
786 # grab snapshot of the current database 818
819 # compare with snapshot of the database
787 for cn, items in orig.items(): 820 for cn, items in orig.items():
788 klass = self.db.classes[cn] 821 klass = self.db.classes[cn]
789 # ensure retired items are retired :) 822 # ensure retired items are retired :)
790 l = items.keys(); l.sort() 823 l = items.keys(); l.sort()
791 m = klass.list(); m.sort() 824 m = klass.list(); m.sort()
796 829
797 # make sure the retired items are actually imported 830 # make sure the retired items are actually imported
798 ae(self.db.user.get('3', 'username'), 'blop') 831 ae(self.db.user.get('3', 'username'), 'blop')
799 ae(self.db.issue.get('2', 'title'), 'issue two') 832 ae(self.db.issue.get('2', 'title'), 'issue two')
800 833
834 # make sure id counters are set correctly
835 maxid = max([int(id) for id in self.db.user.list()])
836 newid = self.db.user.create(username='testing')
837 assert newid > maxid
838
801 def testSafeGet(self): 839 def testSafeGet(self):
802 # existent nodeid, existent property 840 # existent nodeid, existent property
803 self.assertEqual(self.db.user.safeget('1', 'username'), 'admin') 841 self.assertEqual(self.db.user.safeget('1', 'username'), 'admin')
804 # nonexistent nodeid, existent property 842 # nonexistent nodeid, existent property
805 self.assertEqual(self.db.user.safeget('999', 'username'), None) 843 self.assertEqual(self.db.user.safeget('999', 'username'), None)
806 # different default 844 # different default
807 self.assertEqual(self.db.issue.safeget('999', 'nosy', []), []) 845 self.assertEqual(self.db.issue.safeget('999', 'nosy', []), [])
846
847 def testAddProperty(self):
848 self.db.issue.create(title="spam", status='1')
849 self.db.commit()
850
851 self.db.issue.addprop(fixer=Link("user"))
852 # force any post-init stuff to happen
853 self.db.post_init()
854 props = self.db.issue.getprops()
855 keys = props.keys()
856 keys.sort()
857 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
858 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
859 'nosy', 'status', 'superseder', 'title'])
860 self.assertEqual(self.db.issue.get('1', "fixer"), None)
861
862 def testRemoveProperty(self):
863 self.db.issue.create(title="spam", status='1')
864 self.db.commit()
865
866 del self.db.issue.properties['title']
867 self.db.post_init()
868 props = self.db.issue.getprops()
869 keys = props.keys()
870 keys.sort()
871 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
872 'creator', 'deadline', 'files', 'foo', 'id', 'messages',
873 'nosy', 'status', 'superseder'])
874 self.assertEqual(self.db.issue.list(), ['1'])
875
876 def testAddRemoveProperty(self):
877 self.db.issue.create(title="spam", status='1')
878 self.db.commit()
879
880 self.db.issue.addprop(fixer=Link("user"))
881 del self.db.issue.properties['title']
882 self.db.post_init()
883 props = self.db.issue.getprops()
884 keys = props.keys()
885 keys.sort()
886 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
887 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
888 'nosy', 'status', 'superseder'])
889 self.assertEqual(self.db.issue.list(), ['1'])
808 890
809 class ROTest(MyTestCase): 891 class ROTest(MyTestCase):
810 def setUp(self): 892 def setUp(self):
811 # remove previous test, ignore errors 893 # remove previous test, ignore errors
812 if os.path.exists(config.DATABASE): 894 if os.path.exists(config.DATABASE):
834 # remove previous test, ignore errors 916 # remove previous test, ignore errors
835 if os.path.exists(config.DATABASE): 917 if os.path.exists(config.DATABASE):
836 shutil.rmtree(config.DATABASE) 918 shutil.rmtree(config.DATABASE)
837 os.makedirs(config.DATABASE + '/files') 919 os.makedirs(config.DATABASE + '/files')
838 920
921 def test_reservedProperties(self):
922 self.db = self.module.Database(config, 'admin')
923 self.assertRaises(ValueError, self.module.Class, self.db, "a",
924 creation=String())
925 self.assertRaises(ValueError, self.module.Class, self.db, "a",
926 activity=String())
927 self.assertRaises(ValueError, self.module.Class, self.db, "a",
928 creator=String())
929
839 def init_a(self): 930 def init_a(self):
840 self.db = self.module.Database(config, 'admin') 931 self.db = self.module.Database(config, 'admin')
841 a = self.module.Class(self.db, "a", name=String()) 932 a = self.module.Class(self.db, "a", name=String())
842 a.setkey("name") 933 a.setkey("name")
843 self.db.post_init() 934 self.db.post_init()
850 b.setkey("name") 941 b.setkey("name")
851 self.db.post_init() 942 self.db.post_init()
852 943
853 def test_addNewClass(self): 944 def test_addNewClass(self):
854 self.init_a() 945 self.init_a()
946
947 self.assertRaises(ValueError, self.module.Class, self.db, "a",
948 name=String())
949
855 aid = self.db.a.create(name='apple') 950 aid = self.db.a.create(name='apple')
856 self.db.commit(); self.db.close() 951 self.db.commit(); self.db.close()
857 952
858 # add a new class to the schema and check creation of new items 953 # add a new class to the schema and check creation of new items
859 # (and existence of old ones) 954 # (and existence of old ones)
1007 self.assertEqual(self.db.a.get(aid, 'name'), 'apple') 1102 self.assertEqual(self.db.a.get(aid, 'name'), 'apple')
1008 self.assertEqual(self.db.a.lookup('apple'), aid) 1103 self.assertEqual(self.db.a.lookup('apple'), aid)
1009 1104
1010 # confirm journal's ok 1105 # confirm journal's ok
1011 self.db.getjournal('a', aid) 1106 self.db.getjournal('a', aid)
1107
1108 class RDBMSTest:
1109 ''' tests specific to RDBMS backends '''
1110 def test_indexTest(self):
1111 self.assertEqual(self.db.sql_index_exists('_issue', '_issue_id_idx'), 1)
1112 self.assertEqual(self.db.sql_index_exists('_issue', '_issue_x_idx'), 0)
1012 1113
1013 1114
1014 class ClassicInitTest(unittest.TestCase): 1115 class ClassicInitTest(unittest.TestCase):
1015 count = 0 1116 count = 0
1016 db = None 1117 db = None

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