Code

Added some unit tests
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 24 Jul 2001 05:22:55 +0000 (05:22 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 24 Jul 2001 05:22:55 +0000 (05:22 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@70 57a73879-2fb5-44c3-a270-3262357dd7e2

tests/.cvsignore [new file with mode: 0644]
tests/README.TXT [new file with mode: 0644]
tests/__init__.py [new file with mode: 0644]
tests/test_db.py [new file with mode: 0644]
tests/test_schema.py [new file with mode: 0644]

diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644 (file)
index 0000000..b0d7302
--- /dev/null
@@ -0,0 +1,3 @@
+*.pyc
+localconfig.py
+db
diff --git a/tests/README.TXT b/tests/README.TXT
new file mode 100644 (file)
index 0000000..c7d0f10
--- /dev/null
@@ -0,0 +1,18 @@
+Structre of the tests:
+
+   1   Test date classes
+   1.1 Date
+   1.2 Interval
+   2   Set up schema
+   3   Open with specific backend
+   3.1 anydbm
+   3.2 bsddb
+   4   Create database base set (stati, priority, etc)
+   5   Perform some actions
+   6   Perform mail import
+   6.1 text/plain
+   6.2 multipart/mixed (with one text/plain)
+   6.3 text/html
+   6.4 multipart/alternative (with one text/plain)
+   6.5 multipart/alternative (with no text/plain)
+
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644 (file)
index 0000000..9a158bf
--- /dev/null
@@ -0,0 +1,11 @@
+import unittest
+
+import test_schema, test_db
+
+def go():
+    suite = unittest.TestSuite((
+        test_schema.suite(),
+        test_db.suite(),
+    ))
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
diff --git a/tests/test_db.py b/tests/test_db.py
new file mode 100644 (file)
index 0000000..67b17c4
--- /dev/null
@@ -0,0 +1,53 @@
+import unittest, os, shutil
+
+from roundup.backends import anydbm
+from roundup.hyperdb import String, Link, Multilink, Date, Interval, Class
+
+def setupSchema(db):
+    status = Class(db, "status", name=String())
+    status.setkey("name")
+    status.create(name="unread")
+    status.create(name="in-progress")
+    status.create(name="testing")
+    status.create(name="resolved")
+    Class(db, "user", username=String(), password=String())
+    Class(db, "issue", title=String(), status=Link("status"))
+
+class DBTestCase(unittest.TestCase):
+    def setUp(self):
+        class Database(anydbm.Database):
+            pass
+        # remove previous test, ignore errors
+        if os.path.exists('_test_dir'):
+            shutil.rmtree('_test_dir')
+        os.mkdir('_test_dir')
+        self.db = Database('_test_dir', 'test')
+        setupSchema(self.db)
+
+    def tearDown(self):
+        self.db.close()
+        shutil.rmtree('_test_dir')
+
+    def testChanges(self):
+        self.db.issue.create(title="spam", status='1')
+        self.db.issue.create(title="eggs", status='2')
+        self.db.issue.create(title="ham", status='4')
+        self.db.issue.create(title="arguments", status='2')
+        self.db.issue.create(title="abuse", status='1')
+        self.db.issue.addprop(fixer=Link("user"))
+        self.db.issue.getprops()
+#{"title": <hyperdb.String>, "status": <hyperdb.Link to "status">,
+#"user": <hyperdb.Link to "user">}
+        self.db.issue.set('5', status=2)
+        self.db.issue.get('5', "status")
+        self.db.status.get('2', "name")
+        self.db.issue.get('5', "title")
+        self.db.issue.find(status = self.db.status.lookup("in-progress"))
+        self.db.issue.history('5')
+        self.db.status.history('1')
+        self.db.status.history('2')
+
+
+def suite():
+   return unittest.makeSuite(DBTestCase, 'test')
+
diff --git a/tests/test_schema.py b/tests/test_schema.py
new file mode 100644 (file)
index 0000000..3620840
--- /dev/null
@@ -0,0 +1,53 @@
+import unittest, os, shutil
+
+from roundup.backends import anydbm
+from roundup.hyperdb import String, Link, Multilink, Date, Interval, Class
+
+class SchemaTestCase(unittest.TestCase):
+    def setUp(self):
+        class Database(anydbm.Database):
+            pass
+        # remove previous test, ignore errors
+        if os.path.exists('_test_dir'):
+            shutil.rmtree('_test_dir')
+        os.mkdir('_test_dir')
+        self.db = Database('_test_dir', 'test')
+        self.db.clear()
+
+    def tearDown(self):
+        self.db.close()
+        shutil.rmtree('_test_dir')
+
+    def testA_Status(self):
+        status = Class(self.db, "status", name=String())
+        self.assert_(status, 'no class object generated')
+        status.setkey("name")
+        val = status.create(name="unread")
+        self.assertEqual(val, '1', 'expecting "1"')
+        val = status.create(name="in-progress")
+        self.assertEqual(val, '2', 'expecting "2"')
+        val = status.create(name="testing")
+        self.assertEqual(val, '3', 'expecting "3"')
+        val = status.create(name="resolved")
+        self.assertEqual(val, '4', 'expecting "4"')
+        val = status.count()
+        self.assertEqual(val, 4, 'expecting 4')
+        val = status.list()
+        self.assertEqual(val, ['1', '2', '3', '4'], 'blah')
+        val = status.lookup("in-progress")
+        self.assertEqual(val, '2', 'expecting "2"')
+        status.retire('3')
+        val = status.list()
+        self.assertEqual(val, ['1', '2', '4'], 'blah')
+
+    def testB_Issue(self):
+        issue = Class(self.db, "issue", title=String(), status=Link("status"))
+
+    def testC_User(self):
+        user = Class(self.db, "user", username=String(), password=String())
+        user.setkey("username")
+
+
+def suite():
+   return unittest.makeSuite(SchemaTestCase, 'test')
+