Mercurial > p > roundup > code
comparison test/db_test_base.py @ 1920:f9316d2cd5ba
Fixed retirement of items in rdbms imports [SF#841355]
Fixed bug in looking up journal of newly-created items in *dbm backends
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 14 Nov 2003 00:11:19 +0000 |
| parents | 2b0ab61db194 |
| children | f5e8aeb1382d |
comparison
equal
deleted
inserted
replaced
| 1919:e90072582d41 | 1920:f9316d2cd5ba |
|---|---|
| 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.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 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 |
| 742 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '4', '3']) | 742 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '4', '3']) |
| 743 | 743 |
| 744 # XXX add sorting tests for other types | 744 # XXX add sorting tests for other types |
| 745 # XXX test auditors and reactors | 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 class ROTest(MyTestCase): | 801 class ROTest(MyTestCase): |
| 749 def setUp(self): | 802 def setUp(self): |
| 750 # remove previous test, ignore errors | 803 # remove previous test, ignore errors |
| 751 if os.path.exists(config.DATABASE): | 804 if os.path.exists(config.DATABASE): |
