]> git.decadent.org.uk Git - dak.git/commitdiff
Add tests/dbtest_debversion.py.
authorTorsten Werner <twerner@debian.org>
Thu, 13 Jan 2011 21:47:03 +0000 (22:47 +0100)
committerTorsten Werner <twerner@debian.org>
Thu, 13 Jan 2011 21:47:03 +0000 (22:47 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
tests/dbtest_debversion.py [new file with mode: 0755]

diff --git a/tests/dbtest_debversion.py b/tests/dbtest_debversion.py
new file mode 100755 (executable)
index 0000000..3d10b92
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+from db_test import DBDakTestCase
+
+from daklib.dbconn import DBConn, DebVersion
+
+from sqlalchemy import Table, Column, Integer, func
+from sqlalchemy.orm import mapper
+import unittest
+
+class Version(object):
+    def __init__(self, version):
+        self.version = version
+
+    def __repr__(self):
+        return "<Version('%s')>" % self.version
+
+class DebVersionTestCase(DBDakTestCase):
+    def setUp(self):
+        super(DebVersionTestCase, self).setUp()
+        self.version_table = Table('version', self.metadata, \
+            Column('id', Integer, primary_key = True), \
+            Column('version', DebVersion), \
+            )
+        self.version_table.create(checkfirst = True)
+        mapper(Version, self.version_table)
+
+    def test_debversion(self):
+        v1 = Version('0.5')
+        self.session.add(v1)
+        v2 = Version('1.0')
+        self.session.add(v2)
+        #self.session.commit()
+        q = self.session.query(Version)
+        self.assertEqual(2, q.count())
+        self.assertEqual(2, q.filter(Version.version > '0.5~').count())
+        self.assertEqual(1, q.filter(Version.version > '0.5').count())
+        self.assertEqual(0, q.filter(Version.version > '1.0').count())
+        for v in self.session.query(Version.version):
+            print v
+
+    def tearDown(self):
+        self.session.close()
+        self.version_table.drop()
+        super(DebVersionTestCase, self).tearDown()
+
+if __name__ == '__main__':
+    unittest.main()