From: Torsten Werner Date: Sat, 19 Feb 2011 12:56:42 +0000 (+0100) Subject: Convert class Override to ORMObject. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4a42d41b7f9c48159861e143d7a2021a7579d25;p=dak Convert class Override to ORMObject. + Add a test. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 7221d243..e53da961 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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 '' % (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') diff --git a/tests/db_test.py b/tests/db_test.py index b73ae7d3..2ce786ab 100644 --- a/tests/db_test.py +++ b/tests/db_test.py @@ -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() diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index 44864edc..99b8a739 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -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()