]> err.no Git - dak/commitdiff
Improve relation between Suite and Architecture.
authorTorsten Werner <twerner@debian.org>
Sun, 16 Jan 2011 15:06:01 +0000 (16:06 +0100)
committerTorsten Werner <twerner@debian.org>
Sun, 16 Jan 2011 15:06:01 +0000 (16:06 +0100)
Define a many to many relation between Suite and Architecture which makes
SuiteArchitecture obsolete.

Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_packages.py

index 4abfcc596f934fdefa52b4381d26a9e147bfc4f7..59fe5dc3c0f6fd5a1ce8c8ca1edda8958b4064cf 100755 (executable)
@@ -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 '<Suite %s>' % 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,
index 0df6eb29fe09a733c81468c521a9190f6be5839e..e36b3ba70598848acb2bf3c0ffbe40556d4d3879 100755 (executable)
@@ -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()