From: Torsten Werner Date: Sat, 12 Feb 2011 21:10:44 +0000 (+0100) Subject: Convert class Priority to ORMObject. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=911e09c4a2d398265659c35c3a90c9edef4bff0d;p=dak.git Convert class Priority to ORMObject. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 47b933e4..524f85c8 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2078,9 +2078,16 @@ __all__.append('get_policy_queue_from_path') ################################################################################ -class Priority(object): - def __init__(self, *args, **kwargs): - pass +class Priority(ORMObject): + def __init__(self, priority = None, level = None): + self.priority = priority + self.level = level + + def properties(self): + return ['priority', 'priority_id', 'level', 'overrides_count'] + + def not_null_constraints(self): + return ['priority', 'level'] def __eq__(self, val): if isinstance(val, str): @@ -2094,9 +2101,6 @@ class Priority(object): # This signals to use the normal comparison operator return NotImplemented - def __repr__(self): - return '' % (self.priority, self.priority_id) - __all__.append('Priority') @session_wrapper @@ -3167,7 +3171,8 @@ class DBConn(object): component_id = self.tbl_override.c.component, component = relation(Component), priority_id = self.tbl_override.c.priority, - priority = relation(Priority), + priority = relation(Priority, \ + backref=backref('overrides', lazy='dynamic')), section_id = self.tbl_override.c.section, section = relation(Section, \ backref=backref('overrides', lazy='dynamic')), diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 7ce61cd2..d4f57adf 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -3,7 +3,7 @@ from db_test import DBDakTestCase from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \ - Section, get_section, get_sections + Section, get_section, get_sections, Priority, get_priority, get_priorities from sqlalchemy.exc import FlushError, IntegrityError import unittest @@ -84,5 +84,21 @@ class ContentsTestCase(DBDakTestCase): self.assertEqual(section.section_id, all_sections['python']) self.assertEqual(0, section.overrides.count()) + def test_priority(self): + ''' + Test Priority class. + ''' + priority = Priority(priority = 'standard', level = 7) + self.session.add(priority) + self.session.flush() + self.assertEqual('standard', priority.priority) + self.assertEqual(7, priority.level) + self.assertEqual('standard', priority) + self.assertTrue(priority != 'extra') + self.assertEqual(priority, get_priority('standard', self.session)) + all_priorities = get_priorities(self.session) + self.assertEqual(priority.priority_id, all_priorities['standard']) + self.assertEqual(0, priority.overrides.count()) + if __name__ == '__main__': unittest.main()