From: Torsten Werner Date: Wed, 26 Jan 2011 20:01:59 +0000 (+0100) Subject: Create, test, and refactor get_source_by_package_and_suite(). X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=f92dee5ccd013494f09f20454eb027d6f8e1d8f7;p=dak.git Create, test, and refactor get_source_by_package_and_suite(). Signed-off-by: Torsten Werner --- diff --git a/daklib/queue.py b/daklib/queue.py index 08ac23fa..fa092547 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -389,6 +389,15 @@ def get_suite_version(source, session): join(Suite.sources).filter_by(source = source) return q.all() +def get_source_by_package_and_suite(package, suite_name, session): + ''' + returns a DBSource query filtered by DBBinary.package and this package's + suite_name + ''' + return session.query(DBSource). \ + join(DBSource.binaries).filter_by(package = package). \ + join(DBBinary.suites).filter_by(suite_name = suite_name) + class Upload(object): """ Everything that has to do with an upload processed. @@ -1738,11 +1747,7 @@ class Upload(object): ## none of the packages are being taken over from other source packages for b in self.pkg.changes["binary"].keys(): for suite in self.pkg.changes["distribution"].keys(): - q = session.query(DBSource) - q = q.join(DBBinary).filter_by(package=b) - q = q.join(BinAssociation).join(Suite).filter_by(suite_name=suite) - - for s in q.all(): + for s in get_source_by_package_and_suite(b, suite, session): if s.source != self.pkg.changes["source"]: self.rejects.append("%s may not hijack %s from source package %s in suite %s" % (fpr.uid.uid, b, s, suite)) diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 7150866b..91e48398 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -8,7 +8,8 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \ get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \ get_suites_binary_in, add_deb_to_db from daklib.queue_install import package_to_suite -from daklib.queue import get_newest_source, get_suite_version +from daklib.queue import get_newest_source, get_suite_version, \ + get_source_by_package_and_suite from sqlalchemy.orm.exc import MultipleResultsFound import unittest @@ -469,5 +470,17 @@ class PackageTestCase(DBDakTestCase): self.assertEqual('deadbeef', poolfile.sha1sum) self.assertEqual('deadbeef', poolfile.sha256sum) + def test_get_source_by_package_and_suite(self): + 'test get_source_by_package_and_suite()' + + query = get_source_by_package_and_suite('hello', 'sid', self.session) + self.assertEqual(self.source['hello_2.2-1'], query.one()) + query = get_source_by_package_and_suite('gnome-hello', 'squeeze', self.session) + self.assertEqual(self.source['hello_2.2-1'], query.one()) + query = get_source_by_package_and_suite('hello', 'hamm', self.session) + self.assertEqual(0, query.count()) + query = get_source_by_package_and_suite('foobar', 'squeeze', self.session) + self.assertEqual(0, query.count()) + if __name__ == '__main__': unittest.main()