From: Torsten Werner Date: Thu, 20 Jan 2011 21:08:35 +0000 (+0100) Subject: Make a bidirectional relation DBSource - PoolFile. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=135ec5a0cc5797f1188779f075029df5f4ed1f43;p=dak Make a bidirectional relation DBSource - PoolFile. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index a1c28210..6d8d3bd6 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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, diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 249ad81e..de5b7369 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -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()