]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_contents.py
Test the backrefs of class Override.
[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     Override, get_override
8
9 from sqlalchemy.exc import FlushError, IntegrityError
10 import unittest
11
12 class ContentsTestCase(DBDakTestCase):
13     """
14     This TestCase checks the behaviour of contents generation.
15     """
16
17     def test_duplicates1(self):
18         '''
19         Test the BinContents class for duplication problems.
20         '''
21         self.setup_binaries()
22         contents1 = BinContents(file = 'usr/bin/hello', \
23             binary = self.binary['hello_2.2-1_i386'])
24         self.session.add(contents1)
25         self.session.flush()
26         # test duplicates
27         contents2 = BinContents(file = 'usr/bin/hello', \
28             binary = self.binary['hello_2.2-1_i386'])
29         self.session.add(contents2)
30         self.assertRaises(FlushError, self.session.flush)
31
32     def test_duplicates2(self):
33         '''
34         Test the BinContents class for more duplication problems.
35         '''
36         self.setup_binaries()
37         contents1 = BinContents(file = 'usr/bin/hello', \
38             binary = self.binary['hello_2.2-1_i386'])
39         self.session.add(contents1)
40         contents2 = BinContents(file = 'usr/bin/gruezi', \
41             binary = self.binary['hello_2.2-1_i386'])
42         self.session.add(contents2)
43         self.session.flush()
44         # test duplicates
45         contents2.file = 'usr/bin/hello'
46         self.assertRaises(IntegrityError, self.session.flush)
47
48     def test_duplicates3(self):
49         '''
50         Test the BinContents class even more.
51         '''
52         self.setup_binaries()
53         contents1 = BinContents(file = 'usr/bin/hello', \
54             binary = self.binary['hello_2.2-1_i386'])
55         self.session.add(contents1)
56         # same file in different binary packages should be okay
57         contents2 = BinContents(file = 'usr/bin/hello', \
58             binary = self.binary['gnome-hello_2.2-1_i386'])
59         self.session.add(contents2)
60         self.session.flush()
61
62     def test_overridetype(self):
63         '''
64         Test the OverrideType class.
65         '''
66         self.setup_overridetypes()
67         self.assertEqual('deb', self.otype['deb'].overridetype)
68         self.assertEqual(0, self.otype['deb'].overrides.count())
69         self.assertEqual(self.otype['deb'], get_override_type('deb', self.session))
70
71     def test_section(self):
72         '''
73         Test Section class.
74         '''
75         self.setup_sections()
76         self.assertEqual('python', self.section['python'].section)
77         self.assertEqual('python', self.section['python'])
78         self.assertTrue(self.section['python'] != 'java')
79         self.assertEqual(self.section['python'], get_section('python', self.session))
80         all_sections = get_sections(self.session)
81         self.assertEqual(self.section['python'].section_id, all_sections['python'])
82         self.assertEqual(0, self.section['python'].overrides.count())
83
84     def test_priority(self):
85         '''
86         Test Priority class.
87         '''
88         self.setup_priorities()
89         self.assertEqual('standard', self.prio['standard'].priority)
90         self.assertEqual(7, self.prio['standard'].level)
91         self.assertEqual('standard', self.prio['standard'])
92         self.assertTrue(self.prio['standard'] != 'extra')
93         self.assertEqual(self.prio['standard'], get_priority('standard', self.session))
94         all_priorities = get_priorities(self.session)
95         self.assertEqual(self.prio['standard'].priority_id, all_priorities['standard'])
96         self.assertEqual(0, self.prio['standard'].overrides.count())
97
98     def test_override(self):
99         '''
100         Test Override class.
101         '''
102         self.setup_overrides()
103         list = get_override('hello', session = self.session)
104         self.assertEqual(3, len(list))
105         self.assertTrue(self.override['hello_sid_main_udeb'] in list)
106         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
107         list = get_override('hello', suite = 'sid', session = self.session)
108         self.assertEqual([self.override['hello_sid_main_udeb']], list)
109         list = get_override('hello', suite = ['sid'], session = self.session)
110         self.assertEqual([self.override['hello_sid_main_udeb']], list)
111         list = get_override('hello', component = 'contrib', session = self.session)
112         self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
113         list = get_override('hello', component = ['contrib'], session = self.session)
114         self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
115         list = get_override('hello', overridetype = 'deb', session = self.session)
116         self.assertEqual(2, len(list))
117         self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
118         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
119         list = get_override('hello', overridetype = ['deb'], session = self.session)
120         self.assertEqual(2, len(list))
121         self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
122         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
123         # test the backrefs
124         self.assertEqual(self.override['hello_sid_main_udeb'], \
125             self.suite['sid'].overrides.one())
126         self.assertEqual(2, self.comp['main'].overrides.count())
127         self.assertEqual(self.override['hello_sid_main_udeb'], \
128             self.comp['main'].overrides.filter_by(suite = self.suite['sid']).one())
129         self.assertEqual(self.override['hello_sid_main_udeb'], \
130             self.otype['udeb'].overrides.one())
131
132 if __name__ == '__main__':
133     unittest.main()