Mercurial > p > roundup > code
comparison test/db_test_base.py @ 2318:fa2f7ba34399
merge from maint-0-7
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 16 May 2004 09:35:50 +0000 |
| parents | 4990fd3d57a7 |
| children | 5fd066bcf9cf |
comparison
equal
deleted
inserted
replaced
| 2316:f8a4c51e5847 | 2318:fa2f7ba34399 |
|---|---|
| 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.27 2004-05-06 01:03:01 richard Exp $ | 18 # $Id: db_test_base.py,v 1.28 2004-05-16 09:35:50 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 |
| 25 from roundup import init | 25 from roundup import init |
| 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 priority = module.Class(db, "priority", name=String(), order=String()) | |
| 31 priority.setkey("name") | |
| 30 user = module.Class(db, "user", username=String(), password=Password(), | 32 user = module.Class(db, "user", username=String(), password=Password(), |
| 31 assignable=Boolean(), age=Number(), roles=String()) | 33 assignable=Boolean(), age=Number(), roles=String()) |
| 32 user.setkey("username") | 34 user.setkey("username") |
| 33 file = module.FileClass(db, "file", name=String(), type=String(), | 35 file = module.FileClass(db, "file", name=String(), type=String(), |
| 34 comment=String(indexme="yes"), fooz=Password()) | 36 comment=String(indexme="yes"), fooz=Password()) |
| 35 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), | 37 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), |
| 36 status=Link("status"), nosy=Multilink("user"), deadline=Date(), | 38 status=Link("status"), nosy=Multilink("user"), deadline=Date(), |
| 37 foo=Interval(), files=Multilink("file"), assignedto=Link('user')) | 39 foo=Interval(), files=Multilink("file"), assignedto=Link('user'), |
| 40 priority=Link('priority')) | |
| 38 stuff = module.Class(db, "stuff", stuff=String()) | 41 stuff = module.Class(db, "stuff", stuff=String()) |
| 39 session = module.Class(db, 'session', title=String()) | 42 session = module.Class(db, 'session', title=String()) |
| 40 session.disableJournalling() | 43 session.disableJournalling() |
| 41 db.post_init() | 44 db.post_init() |
| 42 if create: | 45 if create: |
| 46 password=password.Password('sekrit')) | 49 password=password.Password('sekrit')) |
| 47 status.create(name="unread") | 50 status.create(name="unread") |
| 48 status.create(name="in-progress") | 51 status.create(name="in-progress") |
| 49 status.create(name="testing") | 52 status.create(name="testing") |
| 50 status.create(name="resolved") | 53 status.create(name="resolved") |
| 54 priority.create(name="feature", order="2") | |
| 55 priority.create(name="wish", order="3") | |
| 56 priority.create(name="bug", order="1") | |
| 51 db.commit() | 57 db.commit() |
| 52 | 58 |
| 53 class MyTestCase(unittest.TestCase): | 59 class MyTestCase(unittest.TestCase): |
| 54 def tearDown(self): | 60 def tearDown(self): |
| 55 if hasattr(self, 'db'): | 61 if hasattr(self, 'db'): |
| 812 {'username': 'blorp'}): | 818 {'username': 'blorp'}): |
| 813 self.db.user.create(**user) | 819 self.db.user.create(**user) |
| 814 iss = self.db.issue | 820 iss = self.db.issue |
| 815 for issue in ( | 821 for issue in ( |
| 816 {'title': 'issue one', 'status': '2', 'assignedto': '1', | 822 {'title': 'issue one', 'status': '2', 'assignedto': '1', |
| 817 'foo': date.Interval('1:10'), | 823 'foo': date.Interval('1:10'), 'priority': '1', |
| 818 'deadline': date.Date('2003-01-01.00:00')}, | 824 'deadline': date.Date('2003-01-01.00:00')}, |
| 819 {'title': 'issue two', 'status': '1', 'assignedto': '2', | 825 {'title': 'issue two', 'status': '1', 'assignedto': '2', |
| 820 'foo': date.Interval('1d'), | 826 'foo': date.Interval('1d'), 'priority': '3', |
| 821 'deadline': date.Date('2003-02-16.22:50')}, | 827 'deadline': date.Date('2003-02-16.22:50')}, |
| 822 {'title': 'issue three', 'status': '1', | 828 {'title': 'issue three', 'status': '1', 'priority': '2', |
| 823 'nosy': ['1','2'], 'deadline': date.Date('2003-02-18')}, | 829 'nosy': ['1','2'], 'deadline': date.Date('2003-02-18')}, |
| 824 {'title': 'non four', 'status': '3', | 830 {'title': 'non four', 'status': '3', |
| 825 'foo': date.Interval('0:10'), | 831 'foo': date.Interval('0:10'), 'priority': '1', |
| 826 'nosy': ['1'], 'deadline': date.Date('2004-03-08')}): | 832 'nosy': ['1'], 'deadline': date.Date('2004-03-08')}): |
| 827 self.db.issue.create(**issue) | 833 self.db.issue.create(**issue) |
| 828 self.db.commit() | 834 self.db.commit() |
| 829 return self.assertEqual, self.db.issue.filter | 835 return self.assertEqual, self.db.issue.filter |
| 830 | 836 |
| 885 ae(filt(None, {'foo': 'from 0:50 to 1d 2:00'}), ['1', '2']) | 891 ae(filt(None, {'foo': 'from 0:50 to 1d 2:00'}), ['1', '2']) |
| 886 ae(filt(None, {'foo': 'from 5:50'}), ['2']) | 892 ae(filt(None, {'foo': 'from 5:50'}), ['2']) |
| 887 ae(filt(None, {'foo': 'to 0:05'}), []) | 893 ae(filt(None, {'foo': 'to 0:05'}), []) |
| 888 | 894 |
| 889 def testFilteringIntervalSort(self): | 895 def testFilteringIntervalSort(self): |
| 896 # 1: '1:10' | |
| 897 # 2: '1d' | |
| 898 # 3: None | |
| 899 # 4: '0:10' | |
| 890 ae, filt = self.filteringSetup() | 900 ae, filt = self.filteringSetup() |
| 891 # ascending should sort None, 1:10, 1d | 901 # ascending should sort None, 1:10, 1d |
| 892 ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '4', '1', '2']) | 902 ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '4', '1', '2']) |
| 893 # descending should sort 1d, 1:10, None | 903 # descending should sort 1d, 1:10, None |
| 894 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '4', '3']) | 904 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '4', '3']) |
| 895 | 905 |
| 896 def testFilteringMultilinkSort(self): | 906 def testFilteringMultilinkSort(self): |
| 907 # 1: [] | |
| 908 # 2: [] | |
| 909 # 3: ['1','2'] | |
| 910 # 4: ['1'] | |
| 897 ae, filt = self.filteringSetup() | 911 ae, filt = self.filteringSetup() |
| 898 ae(filt(None, {}, ('+','nosy'), (None,None)), ['1', '2', '4', '3']) | 912 ae(filt(None, {}, ('+','nosy'), (None,None)), ['1', '2', '4', '3']) |
| 899 ae(filt(None, {}, ('-','nosy'), (None,None)), ['3', '4', '1', '2']) | 913 ae(filt(None, {}, ('-','nosy'), (None,None)), ['3', '4', '1', '2']) |
| 914 | |
| 915 def testFilteringDateSort(self): | |
| 916 # '1': '2003-01-01.00:00' | |
| 917 # '2': '2003-02-16.22:50' | |
| 918 # '3': '2003-02-18' | |
| 919 # '4': '2004-03-08' | |
| 920 ae, filt = self.filteringSetup() | |
| 921 # ascending | |
| 922 ae(filt(None, {}, ('+','deadline'), (None,None)), ['1', '2', '3', '4']) | |
| 923 # descending | |
| 924 ae(filt(None, {}, ('-','deadline'), (None,None)), ['4', '3', '2', '1']) | |
| 925 | |
| 926 def testFilteringDateSortPriorityGroup(self): | |
| 927 # '1': '2003-01-01.00:00' 1 => 2 | |
| 928 # '2': '2003-02-16.22:50' 3 => 1 | |
| 929 # '3': '2003-02-18' 2 => 3 | |
| 930 # '4': '2004-03-08' 1 => 2 | |
| 931 ae, filt = self.filteringSetup() | |
| 932 # ascending | |
| 933 ae(filt(None, {}, ('+','deadline'), ('+','priority')), | |
| 934 ['2', '1', '4', '3']) | |
| 935 ae(filt(None, {}, ('-','deadline'), ('+','priority')), | |
| 936 ['2', '4', '1', '3']) | |
| 937 # descending | |
| 938 ae(filt(None, {}, ('+','deadline'), ('-','priority')), | |
| 939 ['3', '1', '4', '2']) | |
| 940 ae(filt(None, {}, ('-','deadline'), ('-','priority')), | |
| 941 ['3', '4', '1', '2']) | |
| 900 | 942 |
| 901 # XXX add sorting tests for other types | 943 # XXX add sorting tests for other types |
| 902 # XXX test auditors and reactors | 944 # XXX test auditors and reactors |
| 903 | 945 |
| 904 def testImportExport(self): | 946 def testImportExport(self): |
| 991 props = self.db.issue.getprops() | 1033 props = self.db.issue.getprops() |
| 992 keys = props.keys() | 1034 keys = props.keys() |
| 993 keys.sort() | 1035 keys.sort() |
| 994 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', | 1036 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', |
| 995 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', | 1037 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', |
| 996 'nosy', 'status', 'superseder', 'title']) | 1038 'nosy', 'priority', 'status', 'superseder', 'title']) |
| 997 self.assertEqual(self.db.issue.get('1', "fixer"), None) | 1039 self.assertEqual(self.db.issue.get('1', "fixer"), None) |
| 998 | 1040 |
| 999 def testRemoveProperty(self): | 1041 def testRemoveProperty(self): |
| 1000 self.db.issue.create(title="spam", status='1') | 1042 self.db.issue.create(title="spam", status='1') |
| 1001 self.db.commit() | 1043 self.db.commit() |
| 1005 props = self.db.issue.getprops() | 1047 props = self.db.issue.getprops() |
| 1006 keys = props.keys() | 1048 keys = props.keys() |
| 1007 keys.sort() | 1049 keys.sort() |
| 1008 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', | 1050 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', |
| 1009 'creator', 'deadline', 'files', 'foo', 'id', 'messages', | 1051 'creator', 'deadline', 'files', 'foo', 'id', 'messages', |
| 1010 'nosy', 'status', 'superseder']) | 1052 'nosy', 'priority', 'status', 'superseder']) |
| 1011 self.assertEqual(self.db.issue.list(), ['1']) | 1053 self.assertEqual(self.db.issue.list(), ['1']) |
| 1012 | 1054 |
| 1013 def testAddRemoveProperty(self): | 1055 def testAddRemoveProperty(self): |
| 1014 self.db.issue.create(title="spam", status='1') | 1056 self.db.issue.create(title="spam", status='1') |
| 1015 self.db.commit() | 1057 self.db.commit() |
| 1020 props = self.db.issue.getprops() | 1062 props = self.db.issue.getprops() |
| 1021 keys = props.keys() | 1063 keys = props.keys() |
| 1022 keys.sort() | 1064 keys.sort() |
| 1023 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', | 1065 self.assertEqual(keys, ['activity', 'actor', 'assignedto', 'creation', |
| 1024 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', | 1066 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', |
| 1025 'nosy', 'status', 'superseder']) | 1067 'nosy', 'priority', 'status', 'superseder']) |
| 1026 self.assertEqual(self.db.issue.list(), ['1']) | 1068 self.assertEqual(self.db.issue.list(), ['1']) |
| 1027 | 1069 |
| 1028 class ROTest(MyTestCase): | 1070 class ROTest(MyTestCase): |
| 1029 def setUp(self): | 1071 def setUp(self): |
| 1030 # remove previous test, ignore errors | 1072 # remove previous test, ignore errors |
