]> err.no Git - dak/commitdiff
Create, test, and refactor get_source_by_package_and_suite().
authorTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 20:01:59 +0000 (21:01 +0100)
committerTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 20:01:59 +0000 (21:01 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/queue.py
tests/dbtest_packages.py

index 08ac23fa8f96a414b9eb7f5c0e4a3f5e5eecbaab..fa0925470993f005525d448d07a5f0f8b093015f 100755 (executable)
@@ -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))
 
index 7150866b65f47a005ebd04dd6e278da5346242d7..91e483984c2ba797321dbdea088ae06ca65ec426 100755 (executable)
@@ -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()