]> 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 *
6 from daklib.contents import ContentsWriter, ContentsScanner
7
8 from os.path import normpath
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     def test_contentswriter(self):
133         '''
134         Test the ContentsWriter class.
135         '''
136         self.setup_suites()
137         self.setup_architectures()
138         self.setup_overridetypes()
139         self.setup_binaries()
140         self.setup_overrides()
141         self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '/usr/bin/hello'))
142         self.session.commit()
143         cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], self.otype['deb'])
144         self.assertEqual(['/usr/bin/hello                                          python/hello\n'], \
145             cw.get_list())
146         # test formatline and sort order
147         self.assertEqual('/usr/bin/hello                                          python/hello\n', \
148             cw.formatline('/usr/bin/hello', ['python/hello']))
149         self.assertEqual('/usr/bin/hello                                          editors/emacs,python/hello,utils/sl\n', \
150             cw.formatline('/usr/bin/hello', ['editors/emacs', 'python/hello', 'utils/sl']))
151         # test output_filename
152         self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \
153             normpath(cw.output_filename()))
154         cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], \
155             self.otype['udeb'], self.comp['main'])
156         self.assertEqual('tests/fixtures/ftp/dists/squeeze/main/Contents-i386.gz', \
157             normpath(cw.output_filename()))
158         # test unicode support
159         self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '\xc3\xb6'))
160         self.session.commit()
161         # test delete cascading
162         self.session.delete(self.binary['hello_2.2-1_i386'])
163         self.session.commit()
164
165     def test_scan_contents(self):
166         self.setup_binaries()
167         filelist = [f for f in self.binary['hello_2.2-1_i386'].scan_contents()]
168         self.assertEqual(['usr/bin/hello', 'usr/share/doc/hello/copyright'],
169             filelist)
170         self.session.commit()
171         ContentsScanner(self.binary['hello_2.2-1_i386']).scan()
172         bin_contents_list = self.binary['hello_2.2-1_i386'].contents.all()
173         self.assertEqual(2, len(bin_contents_list))
174         self.assertEqual('usr/bin/hello', bin_contents_list[0].file)
175         self.assertEqual('usr/share/doc/hello/copyright', bin_contents_list[1].file)
176
177     def classes_to_clean(self):
178         return [Override, Suite, BinContents, DBBinary, DBSource, Architecture, Section, \
179             OverrideType, Maintainer, Component, Priority, PoolFile]
180
181 if __name__ == '__main__':
182     unittest.main()