From: Torsten Werner Date: Sat, 12 Feb 2011 20:54:50 +0000 (+0100) Subject: Convert class Section to ORMObject. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1549379cef7c649ab3b65f7b44baaddef9339c08;p=dak Convert class Section to ORMObject. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 73b1b48d..47b933e4 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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 '
' % 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')))) diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 98445132..7ce61cd2 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -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()