|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -# $Id: db_test_base.py,v 1.27.2.6 2004-06-23 23:21:32 richard Exp $ |
| 18 | +# $Id: db_test_base.py,v 1.27.2.7 2004-06-24 07:14:49 richard Exp $ |
19 | 19 |
|
20 | 20 | import unittest, os, shutil, errno, imp, sys, time, pprint |
21 | 21 |
|
@@ -846,6 +846,8 @@ def filteringSetup(self): |
846 | 846 | 'foo': date.Interval('0:10'), 'priority': '1', |
847 | 847 | 'nosy': ['1'], 'deadline': date.Date('2004-03-08')}): |
848 | 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 | 851 | self.db.commit() |
850 | 852 | return self.assertEqual, self.db.issue.filter |
851 | 853 |
|
@@ -981,34 +983,43 @@ def testImportExport(self): |
981 | 983 | for name in klass.getprops().keys(): |
982 | 984 | it[name] = klass.get(id, name) |
983 | 985 |
|
984 | | - # grab the export |
985 | | - export = {} |
986 | | - journals = {} |
987 | | - for cn,klass in self.db.classes.items(): |
988 | | - names = klass.getprops().keys() |
989 | | - cl = export[cn] = [names+['is retired']] |
990 | | - for id in klass.getnodeids(): |
991 | | - cl.append(klass.export_list(names, id)) |
992 | | - journals[cn] = klass.export_journals() |
993 | | - |
994 | | - # shut down this db and nuke it |
995 | | - self.db.close() |
996 | | - self.nuke_database() |
997 | | - |
998 | | - # open a new, empty database |
999 | | - os.makedirs(config.DATABASE + '/files') |
1000 | | - self.db = self.module.Database(config, 'admin') |
1001 | | - setupSchema(self.db, 0, self.module) |
1002 | | - |
1003 | | - # import |
1004 | | - for cn, items in export.items(): |
1005 | | - klass = self.db.classes[cn] |
1006 | | - names = items[0] |
1007 | | - maxid = 1 |
1008 | | - for itemprops in items[1:]: |
1009 | | - maxid = max(maxid, int(klass.import_list(names, itemprops))) |
1010 | | - self.db.setid(cn, str(maxid+1)) |
1011 | | - klass.import_journals(journals[cn]) |
| 986 | + os.mkdir('_test_export') |
| 987 | + try: |
| 988 | + # grab the export |
| 989 | + export = {} |
| 990 | + journals = {} |
| 991 | + for cn,klass in self.db.classes.items(): |
| 992 | + names = klass.export_propnames() |
| 993 | + cl = export[cn] = [names+['is retired']] |
| 994 | + for id in klass.getnodeids(): |
| 995 | + cl.append(klass.export_list(names, id)) |
| 996 | + if hasattr(klass, 'export_files'): |
| 997 | + klass.export_files('_test_export', id) |
| 998 | + journals[cn] = klass.export_journals() |
| 999 | + |
| 1000 | + # shut down this db and nuke it |
| 1001 | + self.db.close() |
| 1002 | + self.nuke_database() |
| 1003 | + |
| 1004 | + # open a new, empty database |
| 1005 | + os.makedirs(config.DATABASE + '/files') |
| 1006 | + self.db = self.module.Database(config, 'admin') |
| 1007 | + setupSchema(self.db, 0, self.module) |
| 1008 | + |
| 1009 | + # import |
| 1010 | + for cn, items in export.items(): |
| 1011 | + klass = self.db.classes[cn] |
| 1012 | + names = items[0] |
| 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 | 1024 | # compare with snapshot of the database |
1014 | 1025 | for cn, items in orig.items(): |
|
0 commit comments