From: Torsten Werner Date: Thu, 13 Jan 2011 21:47:03 +0000 (+0100) Subject: Add tests/dbtest_debversion.py. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b66f63dac4e4293921358740695c6ec52d443ab;p=dak Add tests/dbtest_debversion.py. Signed-off-by: Torsten Werner --- diff --git a/tests/dbtest_debversion.py b/tests/dbtest_debversion.py new file mode 100755 index 00000000..3d10b92b --- /dev/null +++ b/tests/dbtest_debversion.py @@ -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 "" % 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()