Mercurial > p > roundup > code
comparison test/db_test_base.py @ 2496:682eefe8ef23
WIP
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 24 Jun 2004 06:39:07 +0000 |
| parents | ea7fb2f416db |
| children | bdd112cf61ba |
comparison
equal
deleted
inserted
replaced
| 2494:ea7fb2f416db | 2496:682eefe8ef23 |
|---|---|
| 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.33 2004-06-23 23:19:07 richard Exp $ | 18 # $Id: db_test_base.py,v 1.34 2004-06-24 06:39:07 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 |
| 844 'nosy': ['1','2'], 'deadline': date.Date('2003-02-18')}, | 844 'nosy': ['1','2'], 'deadline': date.Date('2003-02-18')}, |
| 845 {'title': 'non four', 'status': '3', | 845 {'title': 'non four', 'status': '3', |
| 846 'foo': date.Interval('0:10'), 'priority': '1', | 846 'foo': date.Interval('0:10'), 'priority': '1', |
| 847 'nosy': ['1'], 'deadline': date.Date('2004-03-08')}): | 847 'nosy': ['1'], 'deadline': date.Date('2004-03-08')}): |
| 848 self.db.issue.create(**issue) | 848 self.db.issue.create(**issue) |
| 849 file_content = ''.join([chr(i) for i in range(255)]) | |
| 850 self.db.file.create(content=file_content) | |
| 849 self.db.commit() | 851 self.db.commit() |
| 850 return self.assertEqual, self.db.issue.filter | 852 return self.assertEqual, self.db.issue.filter |
| 851 | 853 |
| 852 def testFilteringID(self): | 854 def testFilteringID(self): |
| 853 ae, filt = self.filteringSetup() | 855 ae, filt = self.filteringSetup() |
| 979 for id in klass.list(): | 981 for id in klass.list(): |
| 980 it = cl[id] = {} | 982 it = cl[id] = {} |
| 981 for name in klass.getprops().keys(): | 983 for name in klass.getprops().keys(): |
| 982 it[name] = klass.get(id, name) | 984 it[name] = klass.get(id, name) |
| 983 | 985 |
| 984 # grab the export | 986 os.mkdir('_test_export') |
| 985 export = {} | 987 try: |
| 986 journals = {} | 988 # grab the export |
| 987 for cn,klass in self.db.classes.items(): | 989 export = {} |
| 988 names = klass.getprops().keys() | 990 journals = {} |
| 989 cl = export[cn] = [names+['is retired']] | 991 for cn,klass in self.db.classes.items(): |
| 990 for id in klass.getnodeids(): | 992 names = klass.export_propnames() |
| 991 cl.append(klass.export_list(names, id)) | 993 cl = export[cn] = [names+['is retired']] |
| 992 journals[cn] = klass.export_journals() | 994 for id in klass.getnodeids(): |
| 993 | 995 cl.append(klass.export_list(names, id)) |
| 994 # shut down this db and nuke it | 996 if hasattr(klass, 'export_files'): |
| 995 self.db.close() | 997 klass.export_files('_test_export', id) |
| 996 self.nuke_database() | 998 journals[cn] = klass.export_journals() |
| 997 | 999 |
| 998 # open a new, empty database | 1000 # shut down this db and nuke it |
| 999 os.makedirs(config.DATABASE + '/files') | 1001 self.db.close() |
| 1000 self.db = self.module.Database(config, 'admin') | 1002 self.nuke_database() |
| 1001 setupSchema(self.db, 0, self.module) | 1003 |
| 1002 | 1004 # open a new, empty database |
| 1003 # import | 1005 os.makedirs(config.DATABASE + '/files') |
| 1004 for cn, items in export.items(): | 1006 self.db = self.module.Database(config, 'admin') |
| 1005 klass = self.db.classes[cn] | 1007 setupSchema(self.db, 0, self.module) |
| 1006 names = items[0] | 1008 |
| 1007 maxid = 1 | 1009 # import |
| 1008 for itemprops in items[1:]: | 1010 for cn, items in export.items(): |
| 1009 maxid = max(maxid, int(klass.import_list(names, itemprops))) | 1011 klass = self.db.classes[cn] |
| 1010 self.db.setid(cn, str(maxid+1)) | 1012 names = items[0] |
| 1011 klass.import_journals(journals[cn]) | 1013 maxid = 1 |
| 1014 for itemprops in items[1:]: | |
| 1015 id = int(klass.import_list(names, itemprops)) | |
| 1016 if hasattr(klass, 'import_files'): | |
| 1017 klass.import_files('_test_export', id) | |
| 1018 maxid = max(maxid, id) | |
| 1019 self.db.setid(cn, str(maxid+1)) | |
| 1020 klass.import_journals(journals[cn]) | |
| 1021 finally: | |
| 1022 shutil.rmtree('_test_export') | |
| 1012 | 1023 |
| 1013 # compare with snapshot of the database | 1024 # compare with snapshot of the database |
| 1014 for cn, items in orig.items(): | 1025 for cn, items in orig.items(): |
| 1015 klass = self.db.classes[cn] | 1026 klass = self.db.classes[cn] |
| 1016 propdefs = klass.getprops(1) | 1027 propdefs = klass.getprops(1) |
