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

index 47b933e43728bafe73850a4922ab429cc8a0cc92..524f85c83816f0400323e488760eb659fdb3bfe6 100755 (executable)
@@ -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 '<Priority %s (%s)>' % (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')),
index 7ce61cd2eb2add993a84d37d594df1bba9c09bce..d4f57adf2a4e3d6793f96af0c585116b8d418033 100755 (executable)
@@ -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()