From: Torsten Werner Date: Fri, 14 Jan 2011 22:35:33 +0000 (+0100) Subject: Really fix the DebVersion type in dbconn.py. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=113c16c9829699e41dd020920254e87ce499b56a;p=dak.git Really fix the DebVersion type in dbconn.py. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index bae2bb35..d72f002c 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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 index 00000000..86dd3d28 --- /dev/null +++ b/tests/dbtest_debversion.py @@ -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 "" % 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() diff --git a/tests/dbtest_fingerprint.py b/tests/dbtest_fingerprint.py index c0d23525..efd994d3 100755 --- a/tests/dbtest_fingerprint.py +++ b/tests/dbtest_fingerprint.py @@ -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()