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

index 3b99227d00f998cfdb8fc1a365c48cb689763733..73b1b48d0ae770d96075744c9192f8051acbf2bf 100755 (executable)
@@ -1873,12 +1873,15 @@ __all__.append('get_override')
 
 ################################################################################
 
-class OverrideType(object):
-    def __init__(self, *args, **kwargs):
-        pass
+class OverrideType(ORMObject):
+    def __init__(self, overridetype = None):
+        self.overridetype = overridetype
 
-    def __repr__(self):
-        return '<OverrideType %s>' % self.overridetype
+    def properties(self):
+        return ['overridetype', 'overridetype_id']
+
+    def not_null_constraints(self):
+        return ['overridetype']
 
 __all__.append('OverrideType')
 
@@ -3165,7 +3168,8 @@ class DBConn(object):
                                  section_id = self.tbl_override.c.section,
                                  section = relation(Section),
                                  overridetype_id = self.tbl_override.c.type,
-                                 overridetype = relation(OverrideType)))
+                                 overridetype = relation(OverrideType, \
+                                    backref=backref('overrides', lazy='dynamic'))))
 
         mapper(OverrideType, self.tbl_override_type,
                properties = dict(overridetype = self.tbl_override_type.c.type,
index d6619e70e630d1d46970da8799b52ec8fe33c438..f36138dbf57852dd9cb384f63036e5ac9719c63c 100755 (executable)
@@ -2,7 +2,7 @@
 
 from db_test import DBDakTestCase
 
-from daklib.dbconn import DBConn, BinContents
+from daklib.dbconn import DBConn, BinContents, OverrideType
 
 from sqlalchemy.exc import FlushError, IntegrityError
 import unittest
@@ -57,5 +57,15 @@ class ContentsTestCase(DBDakTestCase):
         self.session.add(contents2)
         self.session.flush()
 
+    def test_overridetype(self):
+        '''
+        Test the OverrideType class.
+        '''
+        debtype = OverrideType(overridetype = 'deb')
+        self.session.add(debtype)
+        self.session.flush()
+        self.assertEqual('deb', debtype.overridetype)
+        self.assertEqual(0, debtype.overrides.count())
+
 if __name__ == '__main__':
     unittest.main()