From: Torsten Werner Date: Sat, 12 Feb 2011 16:07:14 +0000 (+0100) Subject: Convert class OverrideType to ORMObject. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=0856760278c13dfe42ddffa54a7cdd1df5db9d1d;p=dak.git Convert class OverrideType to ORMObject. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 3b99227d..73b1b48d 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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 '' % 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, diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index d6619e70..f36138db 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -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()