]> git.decadent.org.uk Git - dak.git/commitdiff
Make a bidirectional relation DBSource - PoolFile.
authorTorsten Werner <twerner@debian.org>
Thu, 20 Jan 2011 21:08:35 +0000 (22:08 +0100)
committerTorsten Werner <twerner@debian.org>
Thu, 20 Jan 2011 21:08:35 +0000 (22:08 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_packages.py

index a1c282105f32960eab934e30cdfdf8eada0445e2..6d8d3bd69b230a1a61ceec456cdfbb18a6311d31 100755 (executable)
@@ -3041,7 +3041,7 @@ class DBConn(object):
                                  version = self.tbl_source.c.version,
                                  maintainer_id = self.tbl_source.c.maintainer,
                                  poolfile_id = self.tbl_source.c.file,
-                                 poolfile = relation(PoolFile),
+                                 poolfile = relation(PoolFile, backref=backref('source', uselist = False)),
                                  fingerprint_id = self.tbl_source.c.sig_fpr,
                                  fingerprint = relation(Fingerprint),
                                  changedby_id = self.tbl_source.c.changedby,
index 249ad81eabf4c96d7e21df93966e863ac2791c66..de5b7369c978d188925c921717bcc60313c5cfba 100755 (executable)
@@ -180,6 +180,7 @@ class PackageTestCase(DBDakTestCase):
     def setup_sources(self):
         'create a DBSource object; but it cannot be stored in the DB yet'
 
+        self.setup_maintainers()
         self.setup_poolfiles()
         self.source = DBSource(source = 'hello', version = '2.2-2', \
             maintainer = self.maintainer['maintainer'], \
@@ -193,7 +194,7 @@ class PackageTestCase(DBDakTestCase):
         TODO: add relations to changes_pending_source
         '''
 
-        self.setup_maintainers()
+        self.setup_sources()
         maintainer = self.maintainer['maintainer']
         self.assertEqual(maintainer,
             self.session.query(Maintainer).get(maintainer.maintainer_id))
@@ -203,7 +204,6 @@ class PackageTestCase(DBDakTestCase):
         lazyguy = self.maintainer['lazyguy']
         self.assertEqual(lazyguy,
             self.session.query(Maintainer).get(lazyguy.maintainer_id))
-        self.setup_sources()
         self.assertEqual(maintainer.maintains_sources, [self.source])
         self.assertEqual(maintainer.changed_sources, [])
         self.assertEqual(uploader.maintains_sources, [])
@@ -211,6 +211,17 @@ class PackageTestCase(DBDakTestCase):
         self.assertEqual(lazyguy.maintains_sources, [])
         self.assertEqual(lazyguy.changed_sources, [])
 
+    def test_sources(self):
+        'test relation between DBSource and PoolFile'
+
+        self.setup_sources()
+        poolfile_hello = self.session.query(DBSource)[0].poolfile
+        self.assertEqual(self.file['hello'], poolfile_hello)
+        self.assertEqual(self.source, poolfile_hello.source)
+        poolfile_sl = self.session.query(PoolFile). \
+            filter(PoolFile.filename.like('%/sl/%'))[0]
+        self.assertEqual(None, poolfile_sl.source)
+
 
 if __name__ == '__main__':
     unittest.main()