Mercurial > p > roundup > code
diff test/db_test_base.py @ 4255:88af08f8666f
New config option csv_field_size:
Pythons csv module (which is used for export/import) has a new field
size limit starting with python2.5. We now issue a warning during
export if the limit is too small and use the csv_field_size
configuration during import to set the limit for the csv module.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Tue, 29 Sep 2009 07:27:17 +0000 |
| parents | dcca66d56815 |
| children | d47245c2530a |
line wrap: on
line diff
--- a/test/db_test_base.py Thu Sep 17 09:54:49 2009 +0000 +++ b/test/db_test_base.py Tue Sep 29 07:27:17 2009 +0000 @@ -1613,6 +1613,18 @@ # XXX add sorting tests for other types + # nuke and re-create db for restore + def nukeAndCreate(self): + # shut down this db and nuke it + self.db.close() + self.nuke_database() + + # open a new, empty database + os.makedirs(config.DATABASE + '/files') + self.db = self.module.Database(config, 'admin') + setupSchema(self.db, 0, self.module) + + def testImportExport(self): # use the filtering setup to create a bunch of items ae, filt = self.filteringSetup() @@ -1660,14 +1672,7 @@ klass.export_files('_test_export', id) journals[cn] = klass.export_journals() - # shut down this db and nuke it - self.db.close() - self.nuke_database() - - # open a new, empty database - os.makedirs(config.DATABASE + '/files') - self.db = self.module.Database(config, 'admin') - setupSchema(self.db, 0, self.module) + self.nukeAndCreate() # import for cn, items in export.items(): @@ -1730,6 +1735,58 @@ newid = self.db.user.create(username='testing') assert newid > maxid + # test import/export via admin interface + def testAdminImportExport(self): + import roundup.admin + import csv + # use the filtering setup to create a bunch of items + ae, filt = self.filteringSetup() + # create large field + self.db.priority.create(name = 'X' * 500) + self.db.config.CSV_FIELD_SIZE = 400 + self.db.commit() + output = [] + # ugly hack to get stderr output and disable stdout output + # during regression test. Depends on roundup.admin not using + # anything but stdout/stderr from sys (which is currently the + # case) + def stderrwrite(s): + output.append(s) + roundup.admin.sys = MockNull () + try: + roundup.admin.sys.stderr.write = stderrwrite + tool = roundup.admin.AdminTool() + home = '.' + tool.tracker_home = home + tool.db = self.db + tool.verbose = False + tool.do_export (['_test_export']) + self.assertEqual(len(output), 2) + self.assertEqual(output [1], '\n') + self.failUnless(output [0].startswith + ('Warning: config csv_field_size should be at least')) + self.failUnless(int(output[0].split()[-1]) > 500) + + if hasattr(roundup.admin.csv, 'field_size_limit'): + self.nukeAndCreate() + self.db.config.CSV_FIELD_SIZE = 400 + tool = roundup.admin.AdminTool() + tool.tracker_home = home + tool.db = self.db + tool.verbose = False + self.assertRaises(csv.Error, tool.do_import, ['_test_export']) + + self.nukeAndCreate() + self.db.config.CSV_FIELD_SIZE = 3200 + tool = roundup.admin.AdminTool() + tool.tracker_home = home + tool.db = self.db + tool.verbose = False + tool.do_import(['_test_export']) + finally: + roundup.admin.sys = sys + shutil.rmtree('_test_export') + def testAddProperty(self): self.db.issue.create(title="spam", status='1') self.db.commit()
