]> err.no Git - dak/commitdiff
Really fix the DebVersion type in dbconn.py.
authorTorsten Werner <twerner@debian.org>
Fri, 14 Jan 2011 22:35:33 +0000 (23:35 +0100)
committerTorsten Werner <twerner@debian.org>
Fri, 14 Jan 2011 22:35:33 +0000 (23:35 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_debversion.py [new file with mode: 0755]
tests/dbtest_fingerprint.py

index bae2bb355c3cc24869d0c166f027adba4955de43..d72f002c522baf0a9869b5ca6724d25dceef746e 100755 (executable)
@@ -78,7 +78,8 @@ class DebVersion(UserDefinedType):
     def bind_processor(self, dialect):
         return None
 
-    def result_processor(self, dialect):
+    # ' = None' is needed for sqlalchemy 0.5:
+    def result_processor(self, dialect, coltype = None):
         return None
 
 sa_major_version = sqlalchemy.__version__[0:3]
diff --git a/tests/dbtest_debversion.py b/tests/dbtest_debversion.py
new file mode 100755 (executable)
index 0000000..86dd3d2
--- /dev/null
@@ -0,0 +1,62 @@
+#!/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):
+    """
+    The DebVersionTestCase tests both comparison (<=, ==, >, !=), the in_()
+    method and aggregate functions (min, max) for the DebVersion type. To
+    simplify the test it creates a separate table 'version' which is not used
+    by dak itself.
+    """
+
+    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):
+        v = Version('0.5~')
+        self.session.add(v)
+        v = Version('0.5')
+        self.session.add(v)
+        v = Version('1.0')
+        self.session.add(v)
+        q = self.session.query(Version)
+        self.assertEqual(3, q.count())
+        self.assertEqual(2, q.filter(Version.version <= '0.5').count())
+        self.assertEqual(1, q.filter(Version.version == '0.5').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())
+        self.assertEqual(2, q.filter(Version.version != '1.0').count())
+        self.assertEqual(2, q.filter(Version.version.in_(['0.5~', '1.0'])).count())
+        q = self.session.query(func.min(Version.version))
+        self.assertEqual('0.5~', q.one()[0])
+        q = self.session.query(func.max(Version.version))
+        self.assertEqual('1.0', q.one()[0])
+
+    def tearDown(self):
+        self.session.close()
+        self.version_table.drop()
+        super(DebVersionTestCase, self).tearDown()
+
+if __name__ == '__main__':
+    unittest.main()
index c0d23525479cf698968174a56b69c7f142767871..efd994d3267dec5f1b8f9b9ad9290ccc016d8742 100755 (executable)
@@ -16,5 +16,9 @@ class FingerprintTestCase(DBDakTestCase):
         self.assertEqual(1, query.count())
         self.assertEqual('deadbeefdeadbeef', query.one().fingerprint)
 
+    def tearDown(self):
+        self.session.query(Fingerprint).delete()
+        super(FingerprintTestCase, self).tearDown()
+
 if __name__ == '__main__':
     unittest.main()