Mercurial > p > roundup > code
comparison tests/test_db.py @ 66:b936635f142d
Added some unit tests
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 24 Jul 2001 05:22:55 +0000 |
| parents | |
| children | 5147b4c51fd5 |
comparison
equal
deleted
inserted
replaced
| 65:7854a37a5558 | 66:b936635f142d |
|---|---|
| 1 import unittest, os, shutil | |
| 2 | |
| 3 from roundup.backends import anydbm | |
| 4 from roundup.hyperdb import String, Link, Multilink, Date, Interval, Class | |
| 5 | |
| 6 def setupSchema(db): | |
| 7 status = Class(db, "status", name=String()) | |
| 8 status.setkey("name") | |
| 9 status.create(name="unread") | |
| 10 status.create(name="in-progress") | |
| 11 status.create(name="testing") | |
| 12 status.create(name="resolved") | |
| 13 Class(db, "user", username=String(), password=String()) | |
| 14 Class(db, "issue", title=String(), status=Link("status")) | |
| 15 | |
| 16 class DBTestCase(unittest.TestCase): | |
| 17 def setUp(self): | |
| 18 class Database(anydbm.Database): | |
| 19 pass | |
| 20 # remove previous test, ignore errors | |
| 21 if os.path.exists('_test_dir'): | |
| 22 shutil.rmtree('_test_dir') | |
| 23 os.mkdir('_test_dir') | |
| 24 self.db = Database('_test_dir', 'test') | |
| 25 setupSchema(self.db) | |
| 26 | |
| 27 def tearDown(self): | |
| 28 self.db.close() | |
| 29 shutil.rmtree('_test_dir') | |
| 30 | |
| 31 def testChanges(self): | |
| 32 self.db.issue.create(title="spam", status='1') | |
| 33 self.db.issue.create(title="eggs", status='2') | |
| 34 self.db.issue.create(title="ham", status='4') | |
| 35 self.db.issue.create(title="arguments", status='2') | |
| 36 self.db.issue.create(title="abuse", status='1') | |
| 37 self.db.issue.addprop(fixer=Link("user")) | |
| 38 self.db.issue.getprops() | |
| 39 #{"title": <hyperdb.String>, "status": <hyperdb.Link to "status">, | |
| 40 #"user": <hyperdb.Link to "user">} | |
| 41 self.db.issue.set('5', status=2) | |
| 42 self.db.issue.get('5', "status") | |
| 43 self.db.status.get('2', "name") | |
| 44 self.db.issue.get('5', "title") | |
| 45 self.db.issue.find(status = self.db.status.lookup("in-progress")) | |
| 46 self.db.issue.history('5') | |
| 47 self.db.status.history('1') | |
| 48 self.db.status.history('2') | |
| 49 | |
| 50 | |
| 51 def suite(): | |
| 52 return unittest.makeSuite(DBTestCase, 'test') | |
| 53 |
