]> git.decadent.org.uk Git - dak.git/commitdiff
Create, test, and improve get_newest_source().
authorTorsten Werner <twerner@debian.org>
Sat, 22 Jan 2011 20:41:57 +0000 (21:41 +0100)
committerTorsten Werner <twerner@debian.org>
Sat, 22 Jan 2011 20:41:57 +0000 (21:41 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/queue.py
tests/dbtest_packages.py

index ab688bf2a2f575b2b9268369195d0d2d5846a4ac..9130c3a38ab1758382c0bbc851039cf48773ab77 100755 (executable)
@@ -370,6 +370,19 @@ def edit_note(note, upload, session, trainee=False):
 
 ###############################################################################
 
+# suite names DMs can upload to
+dm_suites = ['unstable', 'experimental']
+
+def get_newest_source(source, session):
+    'returns the newest DBSource object in dm_suites'
+    ## the most recent version of the package uploaded to unstable or
+    ## experimental includes the field "DM-Upload-Allowed: yes" in the source
+    ## section of its control file
+    q = session.query(DBSource).filter_by(source = source). \
+        filter(DBSource.suites.any(Suite.suite_name.in_(dm_suites))). \
+        order_by(desc('source.version'))
+    return q.first()
+
 class Upload(object):
     """
     Everything that has to do with an upload processed.
@@ -1681,22 +1694,13 @@ class Upload(object):
         if rej:
             return
 
-        ## the most recent version of the package uploaded to unstable or
-        ## experimental includes the field "DM-Upload-Allowed: yes" in the source
-        ## section of its control file
-        q = session.query(DBSource).filter_by(source=self.pkg.changes["source"])
-        q = q.join(SrcAssociation)
-        q = q.join(Suite).filter(Suite.suite_name.in_(['unstable', 'experimental']))
-        q = q.order_by(desc('source.version')).limit(1)
-
-        r = q.all()
+        r = get_newest_source(self.pkg.changes["source"], session)
 
-        if len(r) != 1:
+        if r is None:
             rej = "Could not find existing source package %s in unstable or experimental and this is a DM upload" % self.pkg.changes["source"]
             self.rejects.append(rej)
             return
 
-        r = r[0]
         if not r.dm_upload_allowed:
             rej = "Source package %s does not have 'DM-Upload-Allowed: yes' in its most recent version (%s)" % (self.pkg.changes["source"], r.version)
             self.rejects.append(rej)
index fabb4152ff1672680e0e4d6a399cf70d5fa3cc1c..5f5b89c6a536c34dfbcb1d8ca14947d8b8227256 100755 (executable)
@@ -7,6 +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 sqlalchemy.orm.exc import MultipleResultsFound
 import unittest
@@ -348,7 +349,6 @@ class PackageTestCase(DBDakTestCase):
         'test function package_to_suite()'
 
         self.setup_sources()
-        self.session.flush()
         pkg = Pkg()
         pkg.changes = { 'distribution': {} }
         upload = Upload(pkg)
@@ -368,6 +368,16 @@ class PackageTestCase(DBDakTestCase):
         pkg.changes['distribution'] = { 'lenny': '' }
         self.assertTrue(package_to_suite(upload, 'lenny', self.session))
 
+    def test_get_newest_source(self):
+        '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))
+
 
 if __name__ == '__main__':
     unittest.main()