]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_contents.py
Merge branch 'master' into dbtests
[dak.git] / tests / dbtest_contents.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import DBConn, BinContents, OverrideType, get_override_type, \
6     Section, get_section, get_sections, Priority, get_priority, get_priorities
7
8 from sqlalchemy.exc import FlushError, IntegrityError
9 import unittest
10
11 class ContentsTestCase(DBDakTestCase):
12     """
13     This TestCase checks the behaviour of contents generation.
14     """
15
16     def test_duplicates1(self):
17         '''
18         Test the BinContents class for duplication problems.
19         '''
20         self.setup_binaries()
21         contents1 = BinContents(file = 'usr/bin/hello', \
22             binary = self.binary['hello_2.2-1_i386'])
23         self.session.add(contents1)
24         self.session.flush()
25         # test duplicates
26         contents2 = BinContents(file = 'usr/bin/hello', \
27             binary = self.binary['hello_2.2-1_i386'])
28         self.session.add(contents2)
29         self.assertRaises(FlushError, self.session.flush)
30
31     def test_duplicates2(self):
32         '''
33         Test the BinContents class for more duplication problems.
34         '''
35         self.setup_binaries()
36         contents1 = BinContents(file = 'usr/bin/hello', \
37             binary = self.binary['hello_2.2-1_i386'])
38         self.session.add(contents1)
39         contents2 = BinContents(file = 'usr/bin/gruezi', \
40             binary = self.binary['hello_2.2-1_i386'])
41         self.session.add(contents2)
42         self.session.flush()
43         # test duplicates
44         contents2.file = 'usr/bin/hello'
45         self.assertRaises(IntegrityError, self.session.flush)
46
47     def test_duplicates3(self):
48         '''
49         Test the BinContents class even more.
50         '''
51         self.setup_binaries()
52         contents1 = BinContents(file = 'usr/bin/hello', \
53             binary = self.binary['hello_2.2-1_i386'])
54         self.session.add(contents1)
55         # same file in different binary packages should be okay
56         contents2 = BinContents(file = 'usr/bin/hello', \
57             binary = self.binary['gnome-hello_2.2-1_i386'])
58         self.session.add(contents2)
59         self.session.flush()
60
61     def test_overridetype(self):
62         '''
63         Test the OverrideType class.
64         '''
65         debtype = OverrideType(overridetype = 'deb')
66         self.session.add(debtype)
67         self.session.flush()
68         self.assertEqual('deb', debtype.overridetype)
69         self.assertEqual(0, debtype.overrides.count())
70         self.assertEqual(debtype, get_override_type('deb', self.session))
71
72     def test_section(self):
73         '''
74         Test Section class.
75         '''
76         section = Section(section = 'python')
77         self.session.add(section)
78         self.session.flush()
79         self.assertEqual('python', section.section)
80         self.assertEqual('python', section)
81         self.assertTrue(section != 'java')
82         self.assertEqual(section, get_section('python', self.session))
83         all_sections = get_sections(self.session)
84         self.assertEqual(section.section_id, all_sections['python'])
85         self.assertEqual(0, section.overrides.count())
86
87     def test_priority(self):
88         '''
89         Test Priority class.
90         '''
91         priority = Priority(priority = 'standard', level = 7)
92         self.session.add(priority)
93         self.session.flush()
94         self.assertEqual('standard', priority.priority)
95         self.assertEqual(7, priority.level)
96         self.assertEqual('standard', priority)
97         self.assertTrue(priority != 'extra')
98         self.assertEqual(priority, get_priority('standard', self.session))
99         all_priorities = get_priorities(self.session)
100         self.assertEqual(priority.priority_id, all_priorities['standard'])
101         self.assertEqual(0, priority.overrides.count())
102
103 if __name__ == '__main__':
104     unittest.main()