3 from db_test import DBDakTestCase
5 from daklib.dbconn import DBConn, DebVersion
7 from sqlalchemy import Table, Column, Integer, func
8 from sqlalchemy.orm import mapper
11 class Version(object):
12 def __init__(self, version):
13 self.version = version
16 return "<Version('%s')>" % self.version
18 class DebVersionTestCase(DBDakTestCase):
20 The DebVersionTestCase tests both comparison (<=, ==, >, !=), the in_()
21 method and aggregate functions (min, max) for the DebVersion type. To
22 simplify the test it creates a separate table 'version' which is not used
27 super(DebVersionTestCase, self).setUp()
28 self.version_table = Table('version', self.metadata, \
29 Column('id', Integer, primary_key = True), \
30 Column('version', DebVersion), \
32 self.version_table.create(checkfirst = True)
33 mapper(Version, self.version_table)
35 def test_debversion(self):
42 q = self.session.query(Version)
43 self.assertEqual(3, q.count())
44 self.assertEqual(2, q.filter(Version.version <= '0.5').count())
45 self.assertEqual(1, q.filter(Version.version == '0.5').count())
46 self.assertEqual(2, q.filter(Version.version > '0.5~').count())
47 self.assertEqual(1, q.filter(Version.version > '0.5').count())
48 self.assertEqual(0, q.filter(Version.version > '1.0').count())
49 self.assertEqual(2, q.filter(Version.version != '1.0').count())
50 self.assertEqual(2, q.filter(Version.version.in_(['0.5~', '1.0'])).count())
51 q = self.session.query(func.min(Version.version))
52 self.assertEqual('0.5~', q.scalar())
53 q = self.session.query(func.max(Version.version))
54 self.assertEqual('1.0', q.scalar())
57 self.session.rollback()
58 self.version_table.drop()
59 super(DebVersionTestCase, self).tearDown()
61 if __name__ == '__main__':