From: Torsten Werner Date: Sat, 22 Jan 2011 21:52:13 +0000 (+0100) Subject: Create, test, and improve get_suite_version(). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab5c226f539f8fd9680a21128d75e1354121064c;p=dak Create, test, and improve get_suite_version(). Signed-off-by: Torsten Werner --- diff --git a/daklib/queue.py b/daklib/queue.py index 9130c3a3..08ac23fa 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -383,6 +383,12 @@ def get_newest_source(source, session): order_by(desc('source.version')) return q.first() +def get_suite_version(source, session): + 'returns a list of tuples (suite_name, version) for source package' + q = session.query(Suite.suite_name, DBSource.version). \ + join(Suite.sources).filter_by(source = source) + return q.all() + class Upload(object): """ Everything that has to do with an upload processed. @@ -2515,10 +2521,7 @@ distribution.""" version = self.pkg.dsc.get("version") # Ensure version is sane - q = session.query(SrcAssociation) - q = q.join(DBSource).filter(DBSource.source==source) - - self.cross_suite_version_check([ (x.suite.suite_name, x.source.version) for x in q.all() ], + self.cross_suite_version_check(get_suite_version(source, session), filename, version, sourceful=True) ################################################################################ diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 5f5b89c6..0f5f6e88 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -7,7 +7,7 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \ check_poolfile, get_poolfile_like_name, get_source_in_suite, \ get_suites_source_in, add_dsc_to_db, source_exists from daklib.queue_install import package_to_suite -from daklib.queue import get_newest_source +from daklib.queue import get_newest_source, get_suite_version from sqlalchemy.orm.exc import MultipleResultsFound import unittest @@ -369,15 +369,26 @@ class PackageTestCase(DBDakTestCase): self.assertTrue(package_to_suite(upload, 'lenny', self.session)) def test_get_newest_source(self): - 'test function get_newest_source' + 'test function get_newest_source()' self.setup_sources() - self.session.flush() import daklib.queue daklib.queue.dm_suites = ['sid'] self.assertEqual(self.source['hello'], get_newest_source('hello', self.session)) self.assertEqual(None, get_newest_source('foobar', self.session)) + def test_get_suite_version(self): + 'test function get_suite_version()' + + self.setup_sources() + result = get_suite_version('hello', self.session) + self.assertEqual(2, len(result)) + self.assertTrue(('sid', '2.2-1') in result) + self.assertTrue(('sid', '2.2-2') in result) + result = get_suite_version('sl', self.session) + self.assertEqual(2, len(result)) + self.assertTrue(('squeeze', '3.03-16') in result) + self.assertTrue(('sid', '3.03-16') in result) if __name__ == '__main__': unittest.main()