From c11e2b4f33f57e89d02e55a9216f9ae6f91b18ca Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Sun, 16 Jan 2011 16:06:01 +0100 Subject: [PATCH] Improve relation between Suite and Architecture. Define a many to many relation between Suite and Architecture which makes SuiteArchitecture obsolete. Signed-off-by: Torsten Werner --- daklib/dbconn.py | 8 +++++--- tests/dbtest_packages.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 4abfcc59..59fe5dc3 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2502,8 +2502,9 @@ SUITE_FIELDS = [ ('SuiteName', 'suite_name'), ('OverrideSuite', 'overridesuite')] class Suite(object): - def __init__(self, *args, **kwargs): - pass + def __init__(self, suite_name = None, version = None): + self.suite_name = suite_name + self.version = version def __repr__(self): return '' % self.suite_name @@ -2873,7 +2874,8 @@ class DBConn(object): def __setupmappers(self): mapper(Architecture, self.tbl_architecture, - properties = dict(arch_id = self.tbl_architecture.c.id)) + properties = dict(arch_id = self.tbl_architecture.c.id, + suites = relation(Suite, secondary=self.tbl_suite_architectures, backref='architectures'))) mapper(Archive, self.tbl_archive, properties = dict(archive_id = self.tbl_archive.c.id, diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 0df6eb29..e36b3ba7 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -8,7 +8,8 @@ import unittest class PackageTestCase(DBDakTestCase): """ - xxx + PackageTestCase checks the handling of source and binary packages in dak's + database. """ def setup_architectures(self): @@ -25,13 +26,29 @@ class PackageTestCase(DBDakTestCase): self.session.flush() self.session.refresh(architecture) + def setup_suites(self): + "setup a hash of Suite objects in self.suite" + + self.suite = {} + for suite_name in ('lenny', 'squeeze', 'sid'): + suite = Suite(suite_name = suite_name, version = '-') + self.suite[suite_name] = suite + self.session.add(suite) + self.session.flush() + self.session.refresh(suite) + def setUp(self): super(PackageTestCase, self).setUp() self.setup_architectures() + self.setup_suites() def test_packages(self): + # check the id for architectures source and all self.assertEqual(1, self.arch['source'].arch_id) self.assertEqual(2, self.arch['all'].arch_id) + # check the many to many relation between Suite and Architecture + self.arch['source'].suites.append(self.suite['lenny']) + self.assertEqual('source', self.suite['lenny'].architectures[0]) if __name__ == '__main__': unittest.main() -- 2.39.5