3 from db_test import DBDakTestCase
5 from daklib.dbconn import *
6 from daklib.contents import ContentsWriter, ContentsScanner
8 from os.path import normpath
9 from sqlalchemy.exc import FlushError, IntegrityError
12 class ContentsTestCase(DBDakTestCase):
14 This TestCase checks the behaviour of contents generation.
17 def test_duplicates1(self):
19 Test the BinContents class for duplication problems.
22 contents1 = BinContents(file = 'usr/bin/hello', \
23 binary = self.binary['hello_2.2-1_i386'])
24 self.session.add(contents1)
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)
32 def test_duplicates2(self):
34 Test the BinContents class for more duplication problems.
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)
45 contents2.file = 'usr/bin/hello'
46 self.assertRaises(IntegrityError, self.session.flush)
48 def test_duplicates3(self):
50 Test the BinContents class even more.
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)
62 def test_overridetype(self):
64 Test the OverrideType class.
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))
71 def test_section(self):
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())
84 def test_priority(self):
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())
98 def test_override(self):
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)
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())
132 def test_contentswriter(self):
134 Test the ContentsWriter class.
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'], \
146 # test formatline and sort order
147 self.assertEqual('/usr/bin/hello python/hello\n', \
148 cw.formatline('/usr/bin/hello', 'python/hello'))
149 # test output_filename
150 self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \
151 normpath(cw.output_filename()))
152 cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], \
153 self.otype['udeb'], self.comp['main'])
154 self.assertEqual('tests/fixtures/ftp/dists/squeeze/main/Contents-i386.gz', \
155 normpath(cw.output_filename()))
156 # test unicode support
157 self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '\xc3\xb6'))
158 self.session.commit()
159 # test delete cascading
160 self.session.delete(self.binary['hello_2.2-1_i386'])
161 self.session.commit()
163 def test_scan_contents(self):
164 self.setup_binaries()
165 filelist = [f for f in self.binary['hello_2.2-1_i386'].scan_contents()]
166 self.assertEqual(['usr/bin/hello', 'usr/share/doc/hello/copyright'],
168 self.session.commit()
169 ContentsScanner(self.binary['hello_2.2-1_i386']).scan()
170 bin_contents_list = self.binary['hello_2.2-1_i386'].contents.all()
171 self.assertEqual(2, len(bin_contents_list))
172 self.assertEqual('usr/bin/hello', bin_contents_list[0].file)
173 self.assertEqual('usr/share/doc/hello/copyright', bin_contents_list[1].file)
175 def classes_to_clean(self):
176 return [Override, Suite, BinContents, DBBinary, DBSource, Architecture, Section, \
177 OverrideType, Maintainer, Component, Priority, PoolFile]
179 if __name__ == '__main__':