|
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.7 2003-11-12 03:42:13 richard Exp $ |
| 18 | +# $Id: db_test_base.py,v 1.8 2003-11-14 00:11:19 richard Exp $ |
19 | 19 |
|
20 | 20 | import unittest, os, shutil, errno, imp, sys, time, pprint |
21 | 21 |
|
@@ -744,6 +744,59 @@ def testFilteringIntervalSort(self): |
744 | 744 | # XXX add sorting tests for other types |
745 | 745 | # XXX test auditors and reactors |
746 | 746 |
|
| 747 | + def testImportExport(self): |
| 748 | + # use the filtering setup to create a bunch of items |
| 749 | + ae, filt = self.filteringSetup() |
| 750 | + self.db.user.retire('3') |
| 751 | + self.db.issue.retire('2') |
| 752 | + |
| 753 | + # grab snapshot of the current database |
| 754 | + orig = {} |
| 755 | + for cn,klass in self.db.classes.items(): |
| 756 | + cl = orig[cn] = {} |
| 757 | + for id in klass.list(): |
| 758 | + it = cl[id] = {} |
| 759 | + for name in klass.getprops().keys(): |
| 760 | + it[name] = klass.get(id, name) |
| 761 | + |
| 762 | + # grab the export |
| 763 | + export = {} |
| 764 | + for cn,klass in self.db.classes.items(): |
| 765 | + names = klass.getprops().keys() |
| 766 | + cl = export[cn] = [names+['is retired']] |
| 767 | + for id in klass.getnodeids(): |
| 768 | + cl.append(klass.export_list(names, id)) |
| 769 | + |
| 770 | + # shut down this db and nuke it |
| 771 | + self.db.close() |
| 772 | + self.nuke_database() |
| 773 | + |
| 774 | + # open a new, empty database |
| 775 | + os.makedirs(config.DATABASE + '/files') |
| 776 | + self.db = self.module.Database(config, 'admin') |
| 777 | + setupSchema(self.db, 0, self.module) |
| 778 | + |
| 779 | + # import |
| 780 | + for cn, items in export.items(): |
| 781 | + klass = self.db.classes[cn] |
| 782 | + names = items[0] |
| 783 | + for itemprops in items[1:]: |
| 784 | + klass.import_list(names, itemprops) |
| 785 | + |
| 786 | + # grab snapshot of the current database |
| 787 | + for cn, items in orig.items(): |
| 788 | + klass = self.db.classes[cn] |
| 789 | + # ensure retired items are retired :) |
| 790 | + l = items.keys(); l.sort() |
| 791 | + m = klass.list(); m.sort() |
| 792 | + ae(l, m) |
| 793 | + for id, props in items.items(): |
| 794 | + for name, value in props.items(): |
| 795 | + ae(klass.get(id, name), value) |
| 796 | + |
| 797 | + # make sure the retired items are actually imported |
| 798 | + ae(self.db.user.get('3', 'username'), 'blop') |
| 799 | + ae(self.db.issue.get('2', 'title'), 'issue two') |
747 | 800 |
|
748 | 801 | class ROTest(MyTestCase): |
749 | 802 | def setUp(self): |
|
0 commit comments