]> git.decadent.org.uk Git - dak.git/commitdiff
Convert class Override to ORMObject.
authorTorsten Werner <twerner@debian.org>
Sat, 19 Feb 2011 12:56:42 +0000 (13:56 +0100)
committerTorsten Werner <twerner@debian.org>
Sat, 19 Feb 2011 12:58:11 +0000 (13:58 +0100)
+ Add a test.

Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/db_test.py
tests/dbtest_contents.py

index 7221d243f226970ad91fcfce89992098d04dbe7a..e53da961d870fe6f06b77331f9ac65377ec47183 100755 (executable)
@@ -1814,12 +1814,22 @@ __all__.append('get_new_comments')
 
 ################################################################################
 
-class Override(object):
-    def __init__(self, *args, **kwargs):
-        pass
+class Override(ORMObject):
+    def __init__(self, package = None, suite = None, component = None, overridetype = None, \
+        section = None, priority = None):
+        self.package = package
+        self.suite = suite
+        self.component = component
+        self.overridetype = overridetype
+        self.section = section
+        self.priority = priority
 
-    def __repr__(self):
-        return '<Override %s (%s)>' % (self.package, self.suite_id)
+    def properties(self):
+        return ['package', 'suite', 'component', 'overridetype', 'section', \
+            'priority']
+
+    def not_null_constraints(self):
+        return ['package', 'suite', 'component', 'overridetype', 'section']
 
 __all__.append('Override')
 
index b73ae7d310cccfdcadc869903d98276945aa7838..2ce786ab685b2cc2418a21cfe9d12dd7fd5c0678 100644 (file)
@@ -242,7 +242,8 @@ class DBDakTestCase(DakTestCase):
         if 'otype' in self.__dict__:
             return
         self.otype = {}
-        self.otype['deb'] = OverrideType(overridetype = 'deb')
+        for type_ in ('deb', 'udeb'):
+            self.otype[type_] = OverrideType(overridetype = type_)
         self.session.add_all(self.otype.values())
         self.session.flush()
 
@@ -268,6 +269,33 @@ class DBDakTestCase(DakTestCase):
         self.session.add_all(self.prio.values())
         self.session.flush()
 
+    def setup_overrides(self):
+        '''
+        Setup self.override of class Override.
+        '''
+        if 'override' in self.__dict__:
+            return
+        self.setup_suites()
+        self.setup_components()
+        self.setup_overridetypes()
+        self.setup_sections()
+        self.setup_priorities()
+        self.override = {}
+        self.override['hello_sid_main_udeb'] = Override(package = 'hello', \
+            suite = self.suite['sid'], component = self.comp['main'], \
+            overridetype = self.otype['udeb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.override['hello_squeeze_main_deb'] = Override(package = 'hello', \
+            suite = self.suite['squeeze'], component = self.comp['main'], \
+            overridetype = self.otype['deb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.override['hello_lenny_contrib_deb'] = Override(package = 'hello', \
+            suite = self.suite['lenny'], component = self.comp['contrib'], \
+            overridetype = self.otype['deb'], \
+            section = self.section['python'], priority = self.prio['standard'])
+        self.session.add_all(self.override.values())
+        self.session.flush()
+
     def setUp(self):
         if self.metadata is None:
             self.initialize()
index 44864edc93a0d4e74b5d916bdd3806c919d8d35f..99b8a73925300a6d1dd7b4c502e586a3fff9eeb7 100755 (executable)
@@ -3,7 +3,8 @@
 from db_test import DBDakTestCase
 
 from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \
-    Section, get_section, get_sections, Priority, get_priority, get_priorities
+    Section, get_section, get_sections, Priority, get_priority, get_priorities, \
+    Override, get_override
 
 from sqlalchemy.exc import FlushError, IntegrityError
 import unittest
@@ -94,5 +95,31 @@ class ContentsTestCase(DBDakTestCase):
         self.assertEqual(self.prio['standard'].priority_id, all_priorities['standard'])
         self.assertEqual(0, self.prio['standard'].overrides.count())
 
+    def test_override(self):
+        '''
+        Test Override class.
+        '''
+        self.setup_overrides()
+        list = get_override('hello', session = self.session)
+        self.assertEqual(3, len(list))
+        self.assertTrue(self.override['hello_sid_main_udeb'] in list)
+        self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
+        list = get_override('hello', suite = 'sid', session = self.session)
+        self.assertEqual([self.override['hello_sid_main_udeb']], list)
+        list = get_override('hello', suite = ['sid'], session = self.session)
+        self.assertEqual([self.override['hello_sid_main_udeb']], list)
+        list = get_override('hello', component = 'contrib', session = self.session)
+        self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
+        list = get_override('hello', component = ['contrib'], session = self.session)
+        self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
+        list = get_override('hello', overridetype = 'deb', session = self.session)
+        self.assertEqual(2, len(list))
+        self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
+        self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
+        list = get_override('hello', overridetype = ['deb'], session = self.session)
+        self.assertEqual(2, len(list))
+        self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
+        self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
+
 if __name__ == '__main__':
     unittest.main()