]> git.decadent.org.uk Git - dak.git/commitdiff
Convert class Section to ORMObject.
authorTorsten Werner <twerner@debian.org>
Sat, 12 Feb 2011 20:54:50 +0000 (21:54 +0100)
committerTorsten Werner <twerner@debian.org>
Sat, 12 Feb 2011 20:54:50 +0000 (21:54 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_contents.py

index 73b1b48d0ae770d96075744c9192f8051acbf2bf..47b933e43728bafe73850a4922ab429cc8a0cc92 100755 (executable)
@@ -1878,7 +1878,7 @@ class OverrideType(ORMObject):
         self.overridetype = overridetype
 
     def properties(self):
-        return ['overridetype', 'overridetype_id']
+        return ['overridetype', 'overridetype_id', 'overrides_count']
 
     def not_null_constraints(self):
         return ['overridetype']
@@ -2148,9 +2148,15 @@ __all__.append('get_priorities')
 
 ################################################################################
 
-class Section(object):
-    def __init__(self, *args, **kwargs):
-        pass
+class Section(ORMObject):
+    def __init__(self, section = None):
+        self.section = section
+
+    def properties(self):
+        return ['section', 'section_id', 'overrides_count']
+
+    def not_null_constraints(self):
+        return ['section']
 
     def __eq__(self, val):
         if isinstance(val, str):
@@ -2164,9 +2170,6 @@ class Section(object):
         # This signals to use the normal comparison operator
         return NotImplemented
 
-    def __repr__(self):
-        return '<Section %s>' % self.section
-
 __all__.append('Section')
 
 @session_wrapper
@@ -3166,7 +3169,8 @@ class DBConn(object):
                                  priority_id = self.tbl_override.c.priority,
                                  priority = relation(Priority),
                                  section_id = self.tbl_override.c.section,
-                                 section = relation(Section),
+                                 section = relation(Section, \
+                                    backref=backref('overrides', lazy='dynamic')),
                                  overridetype_id = self.tbl_override.c.type,
                                  overridetype = relation(OverrideType, \
                                     backref=backref('overrides', lazy='dynamic'))))
index 9844513227357534d4f44f321848790496ab2cee..7ce61cd2eb2add993a84d37d594df1bba9c09bce 100755 (executable)
@@ -2,7 +2,8 @@
 
 from db_test import DBDakTestCase
 
-from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type
+from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \
+    Section, get_section, get_sections
 
 from sqlalchemy.exc import FlushError, IntegrityError
 import unittest
@@ -68,5 +69,20 @@ class ContentsTestCase(DBDakTestCase):
         self.assertEqual(0, debtype.overrides.count())
         self.assertEqual(debtype, get_override_type('deb', self.session))
 
+    def test_section(self):
+        '''
+        Test Section class.
+        '''
+        section = Section(section = 'python')
+        self.session.add(section)
+        self.session.flush()
+        self.assertEqual('python', section.section)
+        self.assertEqual('python', section)
+        self.assertTrue(section != 'java')
+        self.assertEqual(section, get_section('python', self.session))
+        all_sections = get_sections(self.session)
+        self.assertEqual(section.section_id, all_sections['python'])
+        self.assertEqual(0, section.overrides.count())
+
 if __name__ == '__main__':
     unittest.main()