comparison test/db_test_base.py @ 2077:3e0961d6d44d

Added the "actor" property. Metakit backend not done (still not confident I know how it's supposed to work ;) Currently it will come up as NULL in the RDBMS backends for older items. The *dbm backends will look up the journal. I hope to remedy the former before 0.7's release. Fixed a bunch of migration issues in the rdbms backends while I was at it (index changes for key prop changes) and simplified the class table update code for RDBMSes that have "alter table" in their command set (ie. not sqlite) ... migration from "version 1" to "version 2" still hasn't actually been tested yet though.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 15 Mar 2004 05:50:20 +0000
parents b1704ba7be41
children c091cacdc505
comparison
equal deleted inserted replaced
2076:2a4309450202 2077:3e0961d6d44d
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.15 2004-03-12 04:09:00 richard Exp $ 18 # $Id: db_test_base.py,v 1.16 2004-03-15 05:50:20 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
41 session.disableJournalling() 41 session.disableJournalling()
42 db.post_init() 42 db.post_init()
43 if create: 43 if create:
44 user.create(username="admin", roles='Admin', 44 user.create(username="admin", roles='Admin',
45 password=password.Password('sekrit')) 45 password=password.Password('sekrit'))
46 user.create(username="fred", roles='User',
47 password=password.Password('sekrit'))
46 status.create(name="unread") 48 status.create(name="unread")
47 status.create(name="in-progress") 49 status.create(name="in-progress")
48 status.create(name="testing") 50 status.create(name="testing")
49 status.create(name="resolved") 51 status.create(name="resolved")
50 db.commit() 52 db.commit()
80 self.db = self.module.Database(config, 'admin') 82 self.db = self.module.Database(config, 'admin')
81 setupSchema(self.db, 1, self.module) 83 setupSchema(self.db, 1, self.module)
82 84
83 def testRefresh(self): 85 def testRefresh(self):
84 self.db.refresh_database() 86 self.db.refresh_database()
87
88 #
89 # automatic properties (well, the two easy ones anyway)
90 #
91 def testCreatorProperty(self):
92 id1 = self.db.issue.create()
93 self.db.commit()
94 self.db.close()
95 self.db = self.module.Database(config, 'fred')
96 setupSchema(self.db, 0, self.module)
97 i = self.db.issue
98 id2 = i.create()
99 self.assertNotEqual(id1, id2)
100 self.assertNotEqual(i.get(id1, 'creator'), i.get(id2, 'creator'))
101
102 def testActorProperty(self):
103 id1 = self.db.issue.create()
104 self.db.commit()
105 self.db.close()
106 self.db = self.module.Database(config, 'fred')
107 setupSchema(self.db, 0, self.module)
108 i = self.db.issue
109 i.set(id1, title='asfasd')
110 self.assertNotEqual(i.get(id1, 'creator'), i.get(id1, 'actor'))
85 111
86 # 112 #
87 # basic operations 113 # basic operations
88 # 114 #
89 def testIDGeneration(self): 115 def testIDGeneration(self):
415 # id, creation, creator and activity properties are reserved 441 # id, creation, creator and activity properties are reserved
416 ar(KeyError, self.db.status.create, id=1) 442 ar(KeyError, self.db.status.create, id=1)
417 ar(KeyError, self.db.status.create, creation=1) 443 ar(KeyError, self.db.status.create, creation=1)
418 ar(KeyError, self.db.status.create, creator=1) 444 ar(KeyError, self.db.status.create, creator=1)
419 ar(KeyError, self.db.status.create, activity=1) 445 ar(KeyError, self.db.status.create, activity=1)
446 ar(KeyError, self.db.status.create, actor=1)
420 # invalid property name 447 # invalid property name
421 ar(KeyError, self.db.status.create, foo='foo') 448 ar(KeyError, self.db.status.create, foo='foo')
422 # key name clash 449 # key name clash
423 ar(ValueError, self.db.status.create, name='unread') 450 ar(ValueError, self.db.status.create, name='unread')
424 # invalid link index 451 # invalid link index
889 # force any post-init stuff to happen 916 # force any post-init stuff to happen
890 self.db.post_init() 917 self.db.post_init()
891 props = self.db.issue.getprops() 918 props = self.db.issue.getprops()
892 keys = props.keys() 919 keys = props.keys()
893 keys.sort() 920 keys.sort()
894 self.assertEqual(keys, ['activity', 'assignedto', 'creation', 921 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
895 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', 922 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
896 'nosy', 'status', 'superseder', 'title']) 923 'nosy', 'status', 'superseder', 'title'])
897 self.assertEqual(self.db.issue.get('1', "fixer"), None) 924 self.assertEqual(self.db.issue.get('1', "fixer"), None)
898 925
899 def testRemoveProperty(self): 926 def testRemoveProperty(self):
903 del self.db.issue.properties['title'] 930 del self.db.issue.properties['title']
904 self.db.post_init() 931 self.db.post_init()
905 props = self.db.issue.getprops() 932 props = self.db.issue.getprops()
906 keys = props.keys() 933 keys = props.keys()
907 keys.sort() 934 keys.sort()
908 self.assertEqual(keys, ['activity', 'assignedto', 'creation', 935 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
909 'creator', 'deadline', 'files', 'foo', 'id', 'messages', 936 'creator', 'deadline', 'files', 'foo', 'id', 'messages',
910 'nosy', 'status', 'superseder']) 937 'nosy', 'status', 'superseder'])
911 self.assertEqual(self.db.issue.list(), ['1']) 938 self.assertEqual(self.db.issue.list(), ['1'])
912 939
913 def testAddRemoveProperty(self): 940 def testAddRemoveProperty(self):
918 del self.db.issue.properties['title'] 945 del self.db.issue.properties['title']
919 self.db.post_init() 946 self.db.post_init()
920 props = self.db.issue.getprops() 947 props = self.db.issue.getprops()
921 keys = props.keys() 948 keys = props.keys()
922 keys.sort() 949 keys.sort()
923 self.assertEqual(keys, ['activity', 'assignedto', 'creation', 950 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation',
924 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', 951 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
925 'nosy', 'status', 'superseder']) 952 'nosy', 'status', 'superseder'])
926 self.assertEqual(self.db.issue.list(), ['1']) 953 self.assertEqual(self.db.issue.list(), ['1'])
927 954
928 class ROTest(MyTestCase): 955 class ROTest(MyTestCase):
961 creation=String()) 988 creation=String())
962 self.assertRaises(ValueError, self.module.Class, self.db, "a", 989 self.assertRaises(ValueError, self.module.Class, self.db, "a",
963 activity=String()) 990 activity=String())
964 self.assertRaises(ValueError, self.module.Class, self.db, "a", 991 self.assertRaises(ValueError, self.module.Class, self.db, "a",
965 creator=String()) 992 creator=String())
993 self.assertRaises(ValueError, self.module.Class, self.db, "a",
994 actor=String())
966 995
967 def init_a(self): 996 def init_a(self):
968 self.db = self.module.Database(config, 'admin') 997 self.db = self.module.Database(config, 'admin')
969 a = self.module.Class(self.db, "a", name=String()) 998 a = self.module.Class(self.db, "a", name=String())
970 a.setkey("name") 999 a.setkey("name")

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