Skip to content

Commit 7f57403

Browse files
author
Richard Jones
committed
Added some unit tests
1 parent 19a30e6 commit 7f57403

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

tests/.cvsignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
localconfig.py
3+
db

tests/README.TXT

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Structre of the tests:
2+
3+
1 Test date classes
4+
1.1 Date
5+
1.2 Interval
6+
2 Set up schema
7+
3 Open with specific backend
8+
3.1 anydbm
9+
3.2 bsddb
10+
4 Create database base set (stati, priority, etc)
11+
5 Perform some actions
12+
6 Perform mail import
13+
6.1 text/plain
14+
6.2 multipart/mixed (with one text/plain)
15+
6.3 text/html
16+
6.4 multipart/alternative (with one text/plain)
17+
6.5 multipart/alternative (with no text/plain)
18+

tests/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
3+
import test_schema, test_db
4+
5+
def go():
6+
suite = unittest.TestSuite((
7+
test_schema.suite(),
8+
test_db.suite(),
9+
))
10+
runner = unittest.TextTestRunner()
11+
runner.run(suite)

tests/test_db.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+

tests/test_schema.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
class SchemaTestCase(unittest.TestCase):
7+
def setUp(self):
8+
class Database(anydbm.Database):
9+
pass
10+
# remove previous test, ignore errors
11+
if os.path.exists('_test_dir'):
12+
shutil.rmtree('_test_dir')
13+
os.mkdir('_test_dir')
14+
self.db = Database('_test_dir', 'test')
15+
self.db.clear()
16+
17+
def tearDown(self):
18+
self.db.close()
19+
shutil.rmtree('_test_dir')
20+
21+
def testA_Status(self):
22+
status = Class(self.db, "status", name=String())
23+
self.assert_(status, 'no class object generated')
24+
status.setkey("name")
25+
val = status.create(name="unread")
26+
self.assertEqual(val, '1', 'expecting "1"')
27+
val = status.create(name="in-progress")
28+
self.assertEqual(val, '2', 'expecting "2"')
29+
val = status.create(name="testing")
30+
self.assertEqual(val, '3', 'expecting "3"')
31+
val = status.create(name="resolved")
32+
self.assertEqual(val, '4', 'expecting "4"')
33+
val = status.count()
34+
self.assertEqual(val, 4, 'expecting 4')
35+
val = status.list()
36+
self.assertEqual(val, ['1', '2', '3', '4'], 'blah')
37+
val = status.lookup("in-progress")
38+
self.assertEqual(val, '2', 'expecting "2"')
39+
status.retire('3')
40+
val = status.list()
41+
self.assertEqual(val, ['1', '2', '4'], 'blah')
42+
43+
def testB_Issue(self):
44+
issue = Class(self.db, "issue", title=String(), status=Link("status"))
45+
46+
def testC_User(self):
47+
user = Class(self.db, "user", username=String(), password=String())
48+
user.setkey("username")
49+
50+
51+
def suite():
52+
return unittest.makeSuite(SchemaTestCase, 'test')
53+

0 commit comments

Comments
 (0)