From 0881b94be7b98c6b8f7e3590f3648793e50e78fa Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Sat, 19 Feb 2011 13:03:56 +0100 Subject: [PATCH] Refactor dbtest_contents.py. Signed-off-by: Torsten Werner --- tests/db_test.py | 33 ++++++++++++++++++++++++++++++ tests/dbtest_contents.py | 44 +++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/tests/db_test.py b/tests/db_test.py index dfd9c538..b73ae7d3 100644 --- a/tests/db_test.py +++ b/tests/db_test.py @@ -235,6 +235,39 @@ class DBDakTestCase(DakTestCase): self.binary['python-hello_2.2-1_i386'].suites.append(self.suite['squeeze']) self.session.add_all(self.binary.values()) + def setup_overridetypes(self): + ''' + Setup self.otype of class OverrideType. + ''' + if 'otype' in self.__dict__: + return + self.otype = {} + self.otype['deb'] = OverrideType(overridetype = 'deb') + self.session.add_all(self.otype.values()) + self.session.flush() + + def setup_sections(self): + ''' + Setup self.section of class Section. + ''' + if 'section' in self.__dict__: + return + self.section = {} + self.section['python'] = Section(section = 'python') + self.session.add_all(self.section.values()) + self.session.flush() + + def setup_priorities(self): + ''' + Setup self.prio of class Priority. + ''' + if 'prio' in self.__dict__: + return + self.prio = {} + self.prio['standard'] = Priority(priority = 'standard', level = 7) + self.session.add_all(self.prio.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 d4f57adf..44864edc 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -62,43 +62,37 @@ class ContentsTestCase(DBDakTestCase): ''' Test the OverrideType class. ''' - debtype = OverrideType(overridetype = 'deb') - self.session.add(debtype) - self.session.flush() - self.assertEqual('deb', debtype.overridetype) - self.assertEqual(0, debtype.overrides.count()) - self.assertEqual(debtype, get_override_type('deb', self.session)) + self.setup_overridetypes() + self.assertEqual('deb', self.otype['deb'].overridetype) + self.assertEqual(0, self.otype['deb'].overrides.count()) + self.assertEqual(self.otype['deb'], 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)) + self.setup_sections() + self.assertEqual('python', self.section['python'].section) + self.assertEqual('python', self.section['python']) + self.assertTrue(self.section['python'] != 'java') + self.assertEqual(self.section['python'], 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()) + self.assertEqual(self.section['python'].section_id, all_sections['python']) + self.assertEqual(0, self.section['python'].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)) + self.setup_priorities() + self.assertEqual('standard', self.prio['standard'].priority) + self.assertEqual(7, self.prio['standard'].level) + self.assertEqual('standard', self.prio['standard']) + self.assertTrue(self.prio['standard'] != 'extra') + self.assertEqual(self.prio['standard'], 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()) + self.assertEqual(self.prio['standard'].priority_id, all_priorities['standard']) + self.assertEqual(0, self.prio['standard'].overrides.count()) if __name__ == '__main__': unittest.main() -- 2.39.5