From 2f142b2bf324aba8fcc74cd1aef5de6fa5b9e49c Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Thu, 20 Jan 2011 20:48:38 +0100 Subject: [PATCH] Improve test_maintainers(). Signed-off-by: Torsten Werner --- daklib/dbconn.py | 7 ++++++- tests/db_test.py | 11 ++++++++++- tests/dbtest_packages.py | 23 +++++++++++++---------- tests/dbtest_timestamps.py | 10 ---------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index e685d919..a1c28210 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2074,9 +2074,14 @@ __all__.append('get_sections') ################################################################################ class DBSource(object): - def __init__(self, maintainer = None, changedby = None): + def __init__(self, source = None, version = None, maintainer = None, \ + changedby = None, poolfile = None, install_date = None): + self.source = source + self.version = version self.maintainer = maintainer self.changedby = changedby + self.poolfile = poolfile + self.install_date = install_date def __repr__(self): return '' % (self.source, self.version) diff --git a/tests/db_test.py b/tests/db_test.py index 4f01f6d5..fc9ce893 100644 --- a/tests/db_test.py +++ b/tests/db_test.py @@ -3,7 +3,7 @@ from base_test import DakTestCase, fixture from daklib.config import Config from daklib.dbconn import DBConn -from sqlalchemy import create_engine, __version__ +from sqlalchemy import create_engine, func, __version__ from sqlalchemy.exc import SADeprecationWarning from sqlalchemy.schema import DDL @@ -72,6 +72,15 @@ class DBDakTestCase(DakTestCase): self.initialize() self.session = DBConn().session() + def now(self): + "returns the current time at the db server" + + # we fetch a fresh session each time to avoid caching + local_session = DBConn().session() + current_time = local_session.query(func.now()).scalar() + local_session.close() + return current_time + def classes_to_clean(self): """ The function classes_to_clean() returns a list of classes. All objects diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index c35123ce..249ad81e 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -102,6 +102,7 @@ class PackageTestCase(DBDakTestCase): def setup_poolfiles(self): 'create some PoolFile objects' + self.setup_locations() self.file = {} self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \ location = self.loc['main'], filesize = 0, md5sum = '') @@ -121,7 +122,7 @@ class PackageTestCase(DBDakTestCase): somelocation.files.append(somefile) ''' - self.setup_locations() + self.setup_poolfiles() location = self.session.query(Location)[0] self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', location.path) @@ -179,8 +180,11 @@ class PackageTestCase(DBDakTestCase): def setup_sources(self): 'create a DBSource object; but it cannot be stored in the DB yet' - self.source = DBSource(maintainer = self.maintainer['maintainer'], - changedby = self.maintainer['uploader']) + self.setup_poolfiles() + self.source = DBSource(source = 'hello', version = '2.2-2', \ + maintainer = self.maintainer['maintainer'], \ + changedby = self.maintainer['uploader'], \ + poolfile = self.file['hello'], install_date = self.now()) def test_maintainers(self): ''' @@ -200,13 +204,12 @@ class PackageTestCase(DBDakTestCase): self.assertEqual(lazyguy, self.session.query(Maintainer).get(lazyguy.maintainer_id)) self.setup_sources() - #TODO: needs File and Location - #self.assertEqual(maintainer.maintains_sources, [self.source]) - #self.assertEqual(maintainer.changed_sources, []) - #self.assertEqual(uploader.maintains_sources, []) - #self.assertEqual(uploader.changed_sources, [self.source]) - #self.assertEqual(lazyguy.maintains_sources, []) - #self.assertEqual(lazyguy.changed_sources, []) + self.assertEqual(maintainer.maintains_sources, [self.source]) + self.assertEqual(maintainer.changed_sources, []) + self.assertEqual(uploader.maintains_sources, []) + self.assertEqual(uploader.changed_sources, [self.source]) + self.assertEqual(lazyguy.maintains_sources, []) + self.assertEqual(lazyguy.changed_sources, []) if __name__ == '__main__': diff --git a/tests/dbtest_timestamps.py b/tests/dbtest_timestamps.py index 1a53ae86..8b35c63f 100755 --- a/tests/dbtest_timestamps.py +++ b/tests/dbtest_timestamps.py @@ -4,7 +4,6 @@ from db_test import DBDakTestCase from daklib.dbconn import DBConn, Uid -from sqlalchemy import func import time import unittest @@ -16,15 +15,6 @@ class TimestampTestCase(DBDakTestCase): TODO: Should we check all tables? """ - def now(self): - "returns the current time at the db server" - - # we fetch a fresh session each time to avoid caching - local_session = DBConn().session() - current_time = local_session.query(func.now()).scalar() - local_session.close() - return current_time - def sleep(self): time.sleep(0.001) -- 2.39.5