From: Torsten Werner Date: Fri, 14 Jan 2011 23:04:51 +0000 (+0100) Subject: Improve database tests. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=83d12a41d882629937ed7fa6d65735d8f1e3e0a5;p=dak.git Improve database tests. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index d72f002c..0db4caf1 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1226,8 +1226,8 @@ __all__.append('add_poolfile') ################################################################################ class Fingerprint(object): - def __init__(self, *args, **kwargs): - pass + def __init__(self, fingerprint = None): + self.fingerprint = fingerprint def __repr__(self): return '' % self.fingerprint @@ -2676,8 +2676,9 @@ __all__.append('get_suite_src_formats') ################################################################################ class Uid(object): - def __init__(self, *args, **kwargs): - pass + def __init__(self, uid = None, name = None): + self.uid = uid + self.name = name def __eq__(self, val): if isinstance(val, str): diff --git a/tests/dbtest_debversion.py b/tests/dbtest_debversion.py index 86dd3d28..ae4baf1b 100755 --- a/tests/dbtest_debversion.py +++ b/tests/dbtest_debversion.py @@ -48,10 +48,10 @@ class DebVersionTestCase(DBDakTestCase): 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]) + q = self.session.query(func.min(Version.version).label('min')) + self.assertEqual('0.5~', q.one().min) + q = self.session.query(func.max(Version.version).label('max')) + self.assertEqual('1.0', q.one().max) def tearDown(self): self.session.close() diff --git a/tests/dbtest_fingerprint.py b/tests/dbtest_fingerprint.py index efd994d3..581795a5 100755 --- a/tests/dbtest_fingerprint.py +++ b/tests/dbtest_fingerprint.py @@ -2,23 +2,23 @@ from db_test import DBDakTestCase -from daklib.dbconn import Fingerprint +from daklib.dbconn import Fingerprint, Uid import unittest class FingerprintTestCase(DBDakTestCase): def test_mini(self): - fingerprint = Fingerprint() - fingerprint.fingerprint = 'deadbeefdeadbeef' + fingerprint = Fingerprint(fingerprint = 'deadbeefdeadbeef') self.session.add(fingerprint) - self.session.commit query = self.session.query(Fingerprint) self.assertEqual(1, query.count()) self.assertEqual('deadbeefdeadbeef', query.one().fingerprint) - - def tearDown(self): - self.session.query(Fingerprint).delete() - super(FingerprintTestCase, self).tearDown() + fingerprint.uid = Uid(uid = 'ftp-master@debian.org', name = 'ftpteam') + uid = self.session.query(Uid).one() + self.assertEqual('ftp-master@debian.org', uid.uid) + self.assertEqual('ftpteam', uid.name) + self.assertEqual(1, len(uid.fingerprint)) + self.assertEqual('deadbeefdeadbeef', uid.fingerprint[0].fingerprint) if __name__ == '__main__': unittest.main()