]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_contents.py
Update ContentsTestCase to the current formatting.
[dak.git] / tests / dbtest_contents.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import *
6 from daklib.contents import ContentsWriter, ContentsScanner
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         self.setup_overridetypes()
66         self.assertEqual('deb', self.otype['deb'].overridetype)
67         self.assertEqual(0, self.otype['deb'].overrides.count())
68         self.assertEqual(self.otype['deb'], get_override_type('deb', self.session))
69
70     def test_section(self):
71         '''
72         Test Section class.
73         '''
74         self.setup_sections()
75         self.assertEqual('python', self.section['python'].section)
76         self.assertEqual('python', self.section['python'])
77         self.assertTrue(self.section['python'] != 'java')
78         self.assertEqual(self.section['python'], get_section('python', self.session))
79         all_sections = get_sections(self.session)
80         self.assertEqual(self.section['python'].section_id, all_sections['python'])
81         self.assertEqual(0, self.section['python'].overrides.count())
82
83     def test_priority(self):
84         '''
85         Test Priority class.
86         '''
87         self.setup_priorities()
88         self.assertEqual('standard', self.prio['standard'].priority)
89         self.assertEqual(7, self.prio['standard'].level)
90         self.assertEqual('standard', self.prio['standard'])
91         self.assertTrue(self.prio['standard'] != 'extra')
92         self.assertEqual(self.prio['standard'], get_priority('standard', self.session))
93         all_priorities = get_priorities(self.session)
94         self.assertEqual(self.prio['standard'].priority_id, all_priorities['standard'])
95         self.assertEqual(0, self.prio['standard'].overrides.count())
96
97     def test_override(self):
98         '''
99         Test Override class.
100         '''
101         self.setup_overrides()
102         list = get_override('hello', session = self.session)
103         self.assertEqual(3, len(list))
104         self.assertTrue(self.override['hello_sid_main_udeb'] in list)
105         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
106         list = get_override('hello', suite = 'sid', session = self.session)
107         self.assertEqual([self.override['hello_sid_main_udeb']], list)
108         list = get_override('hello', suite = ['sid'], session = self.session)
109         self.assertEqual([self.override['hello_sid_main_udeb']], list)
110         list = get_override('hello', component = 'contrib', session = self.session)
111         self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
112         list = get_override('hello', component = ['contrib'], session = self.session)
113         self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
114         list = get_override('hello', overridetype = 'deb', session = self.session)
115         self.assertEqual(2, len(list))
116         self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
117         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
118         list = get_override('hello', overridetype = ['deb'], session = self.session)
119         self.assertEqual(2, len(list))
120         self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
121         self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
122         # test the backrefs
123         self.assertEqual(self.override['hello_sid_main_udeb'], \
124             self.suite['sid'].overrides.one())
125         self.assertEqual(2, self.comp['main'].overrides.count())
126         self.assertEqual(self.override['hello_sid_main_udeb'], \
127             self.comp['main'].overrides.filter_by(suite = self.suite['sid']).one())
128         self.assertEqual(self.override['hello_sid_main_udeb'], \
129             self.otype['udeb'].overrides.one())
130
131     def test_contentswriter(self):
132         '''
133         Test the ContentsWriter class.
134         '''
135         self.setup_suites()
136         self.setup_architectures()
137         self.setup_overridetypes()
138         self.setup_binaries()
139         self.setup_overrides()
140         self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '/usr/bin/hello'))
141         self.session.commit()
142         cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], self.otype['deb'])
143         self.assertEqual(['/usr/bin/hello                                          python/hello\n'], \
144             cw.get_list())
145         # test formatline and sort order
146         self.assertEqual('/usr/bin/hello                                          python/hello\n', \
147             cw.formatline('/usr/bin/hello', ['python/hello']))
148         self.assertEqual('/usr/bin/hello                                          editors/emacs,python/hello,utils/sl\n', \
149             cw.formatline('/usr/bin/hello', ['editors/emacs', 'python/hello', 'utils/sl']))
150         # test output_filename
151         self.assertEqual('tests/fixtures/ftp/squeeze/Contents-i386.gz', \
152             cw.output_filename())
153         cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], \
154             self.otype['udeb'], self.comp['main'])
155         self.assertEqual('tests/fixtures/ftp/squeeze/main/Contents-i386.gz', \
156             cw.output_filename())
157         # test unicode support
158         self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '\xc3\xb6'))
159         self.session.commit()
160         # test delete cascading
161         self.session.delete(self.binary['hello_2.2-1_i386'])
162         self.session.commit()
163
164     def test_scan_contents(self):
165         self.setup_binaries()
166         filelist = [f for f in self.binary['hello_2.2-1_i386'].scan_contents()]
167         self.assertEqual(['usr/bin/hello', 'usr/share/doc/hello/copyright'],
168             filelist)
169         self.session.commit()
170         ContentsScanner(self.binary['hello_2.2-1_i386']).scan()
171         bin_contents_list = self.binary['hello_2.2-1_i386'].contents.all()
172         self.assertEqual(2, len(bin_contents_list))
173         self.assertEqual('usr/bin/hello', bin_contents_list[0].file)
174         self.assertEqual('usr/share/doc/hello/copyright', bin_contents_list[1].file)
175
176     def classes_to_clean(self):
177         return [Override, Suite, BinContents, DBBinary, DBSource, Architecture, Section, \
178             OverrideType, Maintainer, Component, Priority, PoolFile]
179
180 if __name__ == '__main__':
181     unittest.main()