comparison test/db_test_base.py @ 3826:bf2e9535da00

Journal and database testing. - Add to Import/Export test to also test that journals are correctly retrieved - Fix a bug in anydbm backend that didn't export journal 'set' actions where the previous value was None -- all other backends export them correctly so I consider this a bug of anydbm - Fix journal import/export of Date and Interval for metakit - Fix journal import of Password for metakit - Fix setting of Password oldvalue for metakit -- this would be written as the string "None" instead of the value None. Note that existing databases *will* have wrong log-entries. Since this is only for passwords -- and old passwords aren't of much importance -- I consider this fix to be enough... This fix makes the Journal import/export test run for metakit.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Wed, 14 Mar 2007 15:23:11 +0000
parents 2a60b68985db
children cf8b716d9ac2
comparison
equal deleted inserted replaced
3825:f5bb1ad47268 3826:bf2e9535da00
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.83 2007-03-09 10:25:10 schlatterbeck Exp $ 18 # $Id: db_test_base.py,v 1.84 2007-03-14 15:23:11 schlatterbeck Exp $
19 19
20 import unittest, os, shutil, errno, imp, sys, time, pprint, sets 20 import unittest, os, shutil, errno, imp, sys, time, pprint, sets
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
1482 # XXX add sorting tests for other types 1482 # XXX add sorting tests for other types
1483 1483
1484 def testImportExport(self): 1484 def testImportExport(self):
1485 # use the filtering setup to create a bunch of items 1485 # use the filtering setup to create a bunch of items
1486 ae, filt = self.filteringSetup() 1486 ae, filt = self.filteringSetup()
1487 # Get some stuff into the journal for testing import/export of
1488 # journal data:
1489 self.db.user.set('4', password = password.Password('xyzzy'))
1490 self.db.user.set('4', age = 3)
1491 self.db.user.set('4', assignable = True)
1492 self.db.issue.set('1', title = 'i1', status = '3')
1493 self.db.issue.set('1', deadline = date.Date('2007'))
1494 self.db.issue.set('1', foo = date.Interval('1:20'))
1495 p = self.db.priority.create(name = 'some_prio_without_order')
1496 self.db.commit()
1497 self.db.user.set('4', password = password.Password('123xyzzy'))
1498 self.db.user.set('4', assignable = False)
1499 self.db.priority.set(p, order = '4711')
1500 self.db.commit()
1501
1487 self.db.user.retire('3') 1502 self.db.user.retire('3')
1488 self.db.issue.retire('2') 1503 self.db.issue.retire('2')
1489 1504
1490 # grab snapshot of the current database 1505 # grab snapshot of the current database
1491 orig = {} 1506 orig = {}
1507 origj = {}
1492 for cn,klass in self.db.classes.items(): 1508 for cn,klass in self.db.classes.items():
1493 cl = orig[cn] = {} 1509 cl = orig[cn] = {}
1510 jn = origj[cn] = {}
1494 for id in klass.list(): 1511 for id in klass.list():
1495 it = cl[id] = {} 1512 it = cl[id] = {}
1513 jn[id] = self.db.getjournal(cn, id)
1496 for name in klass.getprops().keys(): 1514 for name in klass.getprops().keys():
1497 it[name] = klass.get(id, name) 1515 it[name] = klass.get(id, name)
1498 1516
1499 os.mkdir('_test_export') 1517 os.mkdir('_test_export')
1500 try: 1518 try:
1529 if hasattr(klass, 'import_files'): 1547 if hasattr(klass, 'import_files'):
1530 klass.import_files('_test_export', str(id)) 1548 klass.import_files('_test_export', str(id))
1531 maxid = max(maxid, id) 1549 maxid = max(maxid, id)
1532 self.db.setid(cn, str(maxid+1)) 1550 self.db.setid(cn, str(maxid+1))
1533 klass.import_journals(journals[cn]) 1551 klass.import_journals(journals[cn])
1552 # This is needed, otherwise journals won't be there for anydbm
1553 self.db.commit()
1534 finally: 1554 finally:
1535 shutil.rmtree('_test_export') 1555 shutil.rmtree('_test_export')
1536 1556
1537 # compare with snapshot of the database 1557 # compare with snapshot of the database
1538 for cn, items in orig.items(): 1558 for cn, items in orig.iteritems():
1539 klass = self.db.classes[cn] 1559 klass = self.db.classes[cn]
1540 propdefs = klass.getprops(1) 1560 propdefs = klass.getprops(1)
1541 # ensure retired items are retired :) 1561 # ensure retired items are retired :)
1542 l = items.keys(); l.sort() 1562 l = items.keys(); l.sort()
1543 m = klass.list(); m.sort() 1563 m = klass.list(); m.sort()
1553 except AssertionError: 1573 except AssertionError:
1554 if not isinstance(propdefs[name], Date): 1574 if not isinstance(propdefs[name], Date):
1555 raise 1575 raise
1556 # don't get hung up on rounding errors 1576 # don't get hung up on rounding errors
1557 assert not l.__cmp__(value, int_seconds=1) 1577 assert not l.__cmp__(value, int_seconds=1)
1578 for jc, items in origj.iteritems():
1579 for id, oj in items.iteritems():
1580 rj = self.db.getjournal(jc, id)
1581 # Both mysql and postgresql have some minor issues with
1582 # rounded seconds on export/import, so we compare only
1583 # the integer part.
1584 for j in oj:
1585 j[1].second = float(int(j[1].second))
1586 for j in rj:
1587 j[1].second = float(int(j[1].second))
1588 oj.sort()
1589 rj.sort()
1590 ae(oj, rj)
1558 1591
1559 # make sure the retired items are actually imported 1592 # make sure the retired items are actually imported
1560 ae(self.db.user.get('4', 'username'), 'blop') 1593 ae(self.db.user.get('4', 'username'), 'blop')
1561 ae(self.db.issue.get('2', 'title'), 'issue two') 1594 ae(self.db.issue.get('2', 'title'), 'issue two')
1562 1595

Roundup Issue Tracker: http://roundup-tracker.org/