]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_packages.py
Test and refactor get_component_by_package_suite().
[dak.git] / tests / dbtest_packages.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import Architecture, Suite, get_suite_architectures, \
6     get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \
7     check_poolfile, get_poolfile_like_name, get_source_in_suite, \
8     get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \
9     get_suites_binary_in, add_deb_to_db, Component, \
10     get_component_by_package_suite
11 from daklib.queue_install import package_to_suite
12 from daklib.queue import get_newest_source, get_suite_version_by_source, \
13     get_source_by_package_and_suite, get_suite_version_by_package
14
15 from sqlalchemy.orm.exc import MultipleResultsFound
16 import unittest
17
18 class Pkg():
19     'fake package class used for testing'
20
21     def __init__(self):
22         self.dsc = {}
23         self.files = {}
24         self.changes = {}
25
26 class Upload():
27     'fake Upload class used for testing'
28
29     def __init__(self, pkg):
30         self.pkg = pkg
31
32 class PackageTestCase(DBDakTestCase):
33     """
34     PackageTestCase checks the handling of source and binary packages in dak's
35     database.
36     """
37
38     def setup_suites(self):
39         "setup a hash of Suite objects in self.suite"
40
41         if 'suite' in self.__dict__:
42             return
43         self.suite = {}
44         for suite_name in ('lenny', 'squeeze', 'sid'):
45             self.suite[suite_name] = Suite(suite_name = suite_name, version = '-')
46         self.session.add_all(self.suite.values())
47
48     def setup_architectures(self):
49         "setup Architecture objects in self.arch and connect to suites"
50
51         if 'arch' in self.__dict__:
52             return
53         self.setup_suites()
54         self.arch = {}
55         for arch_string in ('source', 'all', 'i386', 'amd64', 'kfreebsd-i386'):
56             self.arch[arch_string] = Architecture(arch_string)
57             if arch_string != 'kfreebsd-i386':
58                 self.arch[arch_string].suites = self.suite.values()
59             else:
60                 self.arch[arch_string].suites = [self.suite['squeeze'], self.suite['sid']]
61         # hard code ids for source and all
62         self.arch['source'].arch_id = 1
63         self.arch['all'].arch_id = 2
64         self.session.add_all(self.arch.values())
65
66     def setup_components(self):
67         'create some Component objects'
68
69         if 'comp' in self.__dict__:
70             return
71         self.comp = {}
72         self.comp['main'] = Component(component_name = 'main')
73         self.comp['contrib'] = Component(component_name = 'contrib')
74         self.session.add_all(self.comp.values())
75
76     def setup_locations(self):
77         'create some Location objects'
78
79         if 'loc' in self.__dict__:
80             return
81         self.setup_components()
82         self.loc = {}
83         self.loc['main'] = Location( \
84             path = '/srv/ftp-master.debian.org/ftp/pool/', \
85             component = self.comp['main'])
86         self.loc['contrib'] = Location( \
87             path = '/srv/ftp-master.debian.org/ftp/pool/', \
88             component = self.comp['contrib'])
89         self.session.add_all(self.loc.values())
90
91     def setup_poolfiles(self):
92         'create some PoolFile objects'
93
94         if 'file' in self.__dict__:
95             return
96         self.setup_locations()
97         self.file = {}
98         self.file['hello_2.2-3.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-3.dsc', \
99             location = self.loc['main'], filesize = 0, md5sum = '')
100         self.file['hello_2.2-2.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \
101             location = self.loc['main'], filesize = 0, md5sum = '')
102         self.file['hello_2.2-1.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-1.dsc', \
103             location = self.loc['main'], filesize = 0, md5sum = '')
104         self.file['hello_2.2-1_i386.deb'] = PoolFile( \
105             filename = 'main/h/hello/hello_2.2-1_i386.deb', \
106             location = self.loc['main'], filesize = 0, md5sum = '')
107         self.file['gnome-hello_2.2-1_i386.deb'] = PoolFile( \
108             filename = 'main/h/hello/gnome-hello_2.2-1_i386.deb', \
109             location = self.loc['main'], filesize = 0, md5sum = '')
110         self.file['python-hello_2.2-1_all.deb'] = PoolFile( \
111             filename = 'main/h/hello/python-hello_2.2-1_all.deb', \
112             location = self.loc['main'], filesize = 0, md5sum = '')
113         self.file['sl_3.03-16.dsc'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \
114             location = self.loc['main'], filesize = 0, md5sum = '')
115         self.file['python2.6_2.6.6-8.dsc'] = PoolFile( \
116             filename = 'main/p/python2.6/python2.6_2.6.6-8.dsc', \
117             location = self.loc['main'], filesize = 0, md5sum = '')
118         self.session.add_all(self.file.values())
119
120     def setup_maintainers(self):
121         'create some Maintainer objects'
122
123         if 'maintainer' in self.__dict__:
124             return
125         self.maintainer = {}
126         self.maintainer['maintainer'] = Maintainer(name = 'Mr. Maintainer')
127         self.maintainer['uploader'] = Maintainer(name = 'Mrs. Uploader')
128         self.maintainer['lazyguy'] = Maintainer(name = 'Lazy Guy')
129         self.session.add_all(self.maintainer.values())
130
131     def setup_sources(self):
132         'create DBSource objects'
133
134         if 'source' in self.__dict__:
135             return
136         self.setup_maintainers()
137         self.setup_suites()
138         self.setup_poolfiles()
139         self.source = {}
140         self.source['hello_2.2-2'] = DBSource(source = 'hello', version = '2.2-2', \
141             maintainer = self.maintainer['maintainer'], \
142             changedby = self.maintainer['uploader'], \
143             poolfile = self.file['hello_2.2-2.dsc'], install_date = self.now())
144         self.source['hello_2.2-2'].suites.append(self.suite['sid'])
145         self.source['hello_2.2-1'] = DBSource(source = 'hello', version = '2.2-1', \
146             maintainer = self.maintainer['maintainer'], \
147             changedby = self.maintainer['uploader'], \
148             poolfile = self.file['hello_2.2-1.dsc'], install_date = self.now())
149         self.source['hello_2.2-1'].suites.append(self.suite['sid'])
150         self.source['sl_3.03-16'] = DBSource(source = 'sl', version = '3.03-16', \
151             maintainer = self.maintainer['maintainer'], \
152             changedby = self.maintainer['uploader'], \
153             poolfile = self.file['sl_3.03-16.dsc'], install_date = self.now())
154         self.source['sl_3.03-16'].suites.append(self.suite['squeeze'])
155         self.source['sl_3.03-16'].suites.append(self.suite['sid'])
156         self.session.add_all(self.source.values())
157
158     def setup_binaries(self):
159         'create DBBinary objects'
160
161         if 'binary' in self.__dict__:
162             return
163         self.setup_sources()
164         self.setup_architectures()
165         self.binary = {}
166         self.binary['hello_2.2-1_i386'] = DBBinary(package = 'hello', \
167             source = self.source['hello_2.2-1'], version = '2.2-1', \
168             maintainer = self.maintainer['maintainer'], \
169             architecture = self.arch['i386'], \
170             poolfile = self.file['hello_2.2-1_i386.deb'])
171         self.binary['hello_2.2-1_i386'].suites.append(self.suite['squeeze'])
172         self.binary['hello_2.2-1_i386'].suites.append(self.suite['sid'])
173         self.binary['gnome-hello_2.2-1_i386'] = DBBinary(package = 'gnome-hello', \
174             source = self.source['hello_2.2-1'], version = '2.2-1', \
175             maintainer = self.maintainer['maintainer'], \
176             architecture = self.arch['i386'], \
177             poolfile = self.file['gnome-hello_2.2-1_i386.deb'])
178         self.binary['gnome-hello_2.2-1_i386'].suites.append(self.suite['squeeze'])
179         self.binary['gnome-hello_2.2-1_i386'].suites.append(self.suite['sid'])
180         self.binary['python-hello_2.2-1_i386'] = DBBinary(package = 'python-hello', \
181             source = self.source['hello_2.2-1'], version = '2.2-1', \
182             maintainer = self.maintainer['maintainer'], \
183             architecture = self.arch['all'], \
184             poolfile = self.file['python-hello_2.2-1_all.deb'])
185         self.binary['python-hello_2.2-1_i386'].suites.append(self.suite['squeeze'])
186         self.session.add_all(self.binary.values())
187
188     def setUp(self):
189         super(PackageTestCase, self).setUp()
190         self.setup_binaries()
191         # flush to make sure that the setup is correct
192         self.session.flush()
193
194     def test_suite_architecture(self):
195         # check the id for architectures source and all
196         self.assertEqual(1, self.arch['source'].arch_id)
197         self.assertEqual(2, self.arch['all'].arch_id)
198         # check the many to many relation between Suite and Architecture
199         self.assertEqual('source', self.suite['lenny'].architectures[0])
200         self.assertEqual(4, len(self.suite['lenny'].architectures))
201         self.assertEqual(3, len(self.arch['i386'].suites))
202         # check the function get_suite_architectures()
203         architectures = get_suite_architectures('lenny', session = self.session)
204         self.assertEqual(4, len(architectures))
205         self.assertTrue(self.arch['source'] in architectures)
206         self.assertTrue(self.arch['all'] in architectures)
207         self.assertTrue(self.arch['kfreebsd-i386'] not in architectures)
208         architectures = get_suite_architectures('sid', session = self.session)
209         self.assertEqual(5, len(architectures))
210         self.assertTrue(self.arch['kfreebsd-i386'] in architectures)
211         architectures = get_suite_architectures('lenny', skipsrc = True, session = self.session)
212         self.assertEqual(3, len(architectures))
213         self.assertTrue(self.arch['source'] not in architectures)
214         architectures = get_suite_architectures('lenny', skipall = True, session = self.session)
215         self.assertEqual(3, len(architectures))
216         self.assertTrue(self.arch['all'] not in architectures)
217         # check the function get_architecture_suites()
218         suites = get_architecture_suites('i386', self.session)
219         self.assertEqual(3, len(suites))
220         self.assertTrue(self.suite['lenny'] in suites)
221         suites = get_architecture_suites('kfreebsd-i386', self.session)
222         self.assertEqual(2, len(suites))
223         self.assertTrue(self.suite['lenny'] not in suites)
224
225     def test_poolfiles(self):
226         '''
227         Test the relation of the classes PoolFile and Location.
228
229         The code needs some explaination. The property Location.files is not a
230         list as in other relations because such a list would become rather
231         huge. It is a query object that can be queried, filtered, and iterated
232         as usual.  But list like methods like append() and remove() are
233         supported as well which allows code like:
234
235         somelocation.files.append(somefile)
236         '''
237
238         main = self.loc['main']
239         contrib = self.loc['contrib']
240         self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', main.path)
241         count = len(self.file.keys())
242         self.assertEqual(count, main.files.count())
243         self.assertEqual(0, contrib.files.count())
244         poolfile = main.files. \
245                 filter(PoolFile.filename.like('%/hello/hello%')). \
246                 order_by(PoolFile.filename)[0]
247         self.assertEqual('main/h/hello/hello_2.2-1.dsc', poolfile.filename)
248         self.assertEqual(main, poolfile.location)
249         # test get()
250         self.assertEqual(poolfile, \
251                 self.session.query(PoolFile).get(poolfile.file_id))
252         self.assertEqual(None, self.session.query(PoolFile).get(-1))
253         # test remove() and append()
254         main.files.remove(self.file['sl_3.03-16.dsc'])
255         contrib.files.append(self.file['sl_3.03-16.dsc'])
256         self.assertEqual(count - 1, main.files.count())
257         self.assertEqual(1, contrib.files.count())
258         # test fullpath
259         self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/main/s/sl/sl_3.03-16.dsc', \
260             self.file['sl_3.03-16.dsc'].fullpath)
261         # test check_poolfile()
262         self.assertEqual((True, self.file['sl_3.03-16.dsc']), \
263             check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, '', \
264                 contrib.location_id, self.session))
265         self.assertEqual((False, None), \
266             check_poolfile('foobar', 0, '', contrib.location_id, self.session))
267         self.assertEqual((False, self.file['sl_3.03-16.dsc']), \
268             check_poolfile('main/s/sl/sl_3.03-16.dsc', 42, '', \
269                 contrib.location_id, self.session))
270         self.assertEqual((False, self.file['sl_3.03-16.dsc']), \
271             check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \
272                 contrib.location_id, self.session))
273         # test get_poolfile_like_name()
274         self.assertEqual([self.file['sl_3.03-16.dsc']], \
275             get_poolfile_like_name('sl_3.03-16.dsc', self.session))
276         self.assertEqual([], get_poolfile_like_name('foobar', self.session))
277
278     def test_maintainers(self):
279         '''
280         tests relation between Maintainer and DBSource
281
282         TODO: add relations to changes_pending_source
283         '''
284
285         maintainer = self.maintainer['maintainer']
286         self.assertEqual(maintainer,
287             self.session.query(Maintainer).get(maintainer.maintainer_id))
288         uploader = self.maintainer['uploader']
289         self.assertEqual(uploader,
290             self.session.query(Maintainer).get(uploader.maintainer_id))
291         lazyguy = self.maintainer['lazyguy']
292         self.assertEqual(lazyguy,
293             self.session.query(Maintainer).get(lazyguy.maintainer_id))
294         self.assertEqual(3, len(maintainer.maintains_sources))
295         self.assertTrue(self.source['hello_2.2-2'] in maintainer.maintains_sources)
296         self.assertEqual(maintainer.changed_sources, [])
297         self.assertEqual(uploader.maintains_sources, [])
298         self.assertEqual(3, len(uploader.changed_sources))
299         self.assertTrue(self.source['sl_3.03-16'] in uploader.changed_sources)
300         self.assertEqual(lazyguy.maintains_sources, [])
301         self.assertEqual(lazyguy.changed_sources, [])
302
303     def get_source_in_suite_fail(self):
304         '''
305         This function throws the MultipleResultsFound exception because
306         get_source_in_suite is broken.
307
308         TODO: fix get_source_in_suite
309         '''
310
311         return get_source_in_suite('hello', 'sid', self.session)
312
313     def test_sources(self):
314         'test relation between DBSource and PoolFile or Suite'
315
316         # test PoolFile
317         self.assertEqual(self.file['hello_2.2-2.dsc'], self.source['hello_2.2-2'].poolfile)
318         self.assertEqual(self.source['hello_2.2-2'], self.file['hello_2.2-2.dsc'].source)
319         self.assertEqual(None, self.file['python2.6_2.6.6-8.dsc'].source)
320         # test Suite
321         squeeze = self.session.query(Suite). \
322             filter(Suite.sources.contains(self.source['sl_3.03-16'])). \
323             order_by(Suite.suite_name)[1]
324         self.assertEqual(self.suite['squeeze'], squeeze)
325         self.assertEqual(1, squeeze.sources.count())
326         self.assertEqual(self.source['sl_3.03-16'], squeeze.sources[0])
327         sl = self.session.query(DBSource). \
328             filter(DBSource.suites.contains(self.suite['squeeze'])).one()
329         self.assertEqual(self.source['sl_3.03-16'], sl)
330         self.assertEqual(2, len(sl.suites))
331         self.assertTrue(self.suite['sid'] in sl.suites)
332         # test get_source_in_suite()
333         self.assertRaises(MultipleResultsFound, self.get_source_in_suite_fail)
334         self.assertEqual(None, \
335             get_source_in_suite('hello', 'squeeze', self.session))
336         self.assertEqual(self.source['sl_3.03-16'], \
337             get_source_in_suite('sl', 'sid', self.session))
338         # test get_suites_source_in()
339         self.assertEqual([self.suite['sid']], \
340             get_suites_source_in('hello', self.session))
341         self.assertEqual(2, len(get_suites_source_in('sl', self.session)))
342         self.assertTrue(self.suite['squeeze'] in \
343             get_suites_source_in('sl', self.session))
344
345     def test_add_dsc_to_db(self):
346         'tests function add_dsc_to_db()'
347
348         pkg = Pkg()
349         pkg.dsc['source'] = 'hello'
350         pkg.dsc['version'] = '2.2-3'
351         pkg.dsc['maintainer'] = self.maintainer['maintainer'].name
352         pkg.changes['changed-by'] = self.maintainer['uploader'].name
353         pkg.changes['fingerprint'] = 'deadbeef'
354         pkg.changes['distribution'] = { 'sid': '' }
355         pkg.files['hello_2.2-3.dsc'] = { \
356             'component': 'main',
357             'location id': self.loc['main'].location_id,
358             'files id': self.file['hello_2.2-3.dsc'].file_id }
359         pkg.dsc_files = {}
360         upload = Upload(pkg)
361         (source, dsc_component, dsc_location_id, pfs) = \
362             add_dsc_to_db(upload, 'hello_2.2-3.dsc', self.session)
363         self.assertEqual('hello', source.source)
364         self.assertEqual('2.2-3', source.version)
365         self.assertEqual('sid', source.suites[0].suite_name)
366         self.assertEqual('main', dsc_component)
367         self.assertEqual(self.loc['main'].location_id, dsc_location_id)
368         self.assertEqual([], pfs)
369
370     def test_source_exists(self):
371         'test function source_exists()'
372
373         hello = self.source['hello_2.2-2']
374         self.assertTrue(source_exists(hello.source, hello.version, \
375             suites = ['sid'], session = self.session))
376         # binNMU
377         self.assertTrue(source_exists(hello.source, hello.version + '+b7', \
378             suites = ['sid'], session = self.session))
379         self.assertTrue(not source_exists(hello.source, hello.version, \
380             suites = ['lenny', 'squeeze'], session = self.session))
381         self.assertTrue(not source_exists(hello.source, hello.version, \
382             suites = ['lenny', 'sid'], session = self.session))
383         self.assertTrue(not source_exists(hello.source, hello.version, \
384             suites = ['sid', 'lenny'], session = self.session))
385         self.assertTrue(not source_exists(hello.source, '0815', \
386             suites = ['sid'], session = self.session))
387         # 'any' suite
388         self.assertTrue(source_exists(hello.source, hello.version, \
389             session = self.session))
390
391     def test_package_to_suite(self):
392         'test function package_to_suite()'
393
394         pkg = Pkg()
395         pkg.changes = { 'distribution': {} }
396         upload = Upload(pkg)
397         self.assertTrue(not package_to_suite(upload, 'sid', self.session))
398         pkg.changes['distribution'] = { 'sid': '' }
399         pkg.changes['architecture'] = { 'source': '' }
400         self.assertTrue(package_to_suite(upload, 'sid', self.session))
401         pkg.changes['architecture'] = {}
402         pkg.changes['source'] = self.source['hello_2.2-2'].source
403         pkg.changes['version'] = self.source['hello_2.2-2'].version
404         self.assertTrue(not package_to_suite(upload, 'sid', self.session))
405         pkg.changes['version'] = '42'
406         self.assertTrue(package_to_suite(upload, 'sid', self.session))
407         pkg.changes['source'] = 'foobar'
408         pkg.changes['version'] = self.source['hello_2.2-2'].version
409         self.assertTrue(package_to_suite(upload, 'sid', self.session))
410         pkg.changes['distribution'] = { 'lenny': '' }
411         self.assertTrue(package_to_suite(upload, 'lenny', self.session))
412
413     def test_get_newest_source(self):
414         'test function get_newest_source()'
415
416         import daklib.queue
417         daklib.queue.dm_suites = ['sid']
418         self.assertEqual(self.source['hello_2.2-2'], get_newest_source('hello', self.session))
419         self.assertEqual(None, get_newest_source('foobar', self.session))
420
421     def test_get_suite_version_by_source(self):
422         'test function get_suite_version_by_source()'
423
424         result = get_suite_version_by_source('hello', self.session)
425         self.assertEqual(2, len(result))
426         self.assertTrue(('sid', '2.2-1') in result)
427         self.assertTrue(('sid', '2.2-2') in result)
428         result = get_suite_version_by_source('sl', self.session)
429         self.assertEqual(2, len(result))
430         self.assertTrue(('squeeze', '3.03-16') in result)
431         self.assertTrue(('sid', '3.03-16') in result)
432
433     def test_binaries(self):
434         '''
435         tests class DBBinary; TODO: test relation with Architecture, Maintainer,
436         PoolFile, and Fingerprint
437         '''
438
439         # test Suite relation
440         self.assertEqual(2, self.suite['sid'].binaries.count())
441         self.assertTrue(self.binary['hello_2.2-1_i386'] in \
442             self.suite['sid'].binaries.all())
443         self.assertEqual(0, self.suite['lenny'].binaries.count())
444         # test DBSource relation
445         self.assertEqual(3, len(self.source['hello_2.2-1'].binaries))
446         self.assertTrue(self.binary['hello_2.2-1_i386'] in \
447             self.source['hello_2.2-1'].binaries)
448         self.assertEqual(0, len(self.source['hello_2.2-2'].binaries))
449         # test get_suites_binary_in()
450         self.assertEqual(2, len(get_suites_binary_in('hello', self.session)))
451         self.assertTrue(self.suite['sid'] in \
452             get_suites_binary_in('hello', self.session))
453         self.assertEqual(2, len(get_suites_binary_in('gnome-hello', self.session)))
454         self.assertTrue(self.suite['squeeze'] in \
455             get_suites_binary_in('gnome-hello', self.session))
456         self.assertEqual(0, len(get_suites_binary_in('sl', self.session)))
457
458     def test_add_deb_to_db(self):
459         'tests function add_deb_to_db()'
460
461         pkg = Pkg()
462         pkg.changes['fingerprint'] = 'deadbeef'
463         pkg.changes['distribution'] = { 'sid': '' }
464         pkg.files['hello_2.2-2_i386.deb'] = { \
465             'package': 'hello',
466             'version': '2.2-2',
467             'maintainer': self.maintainer['maintainer'].name,
468             'architecture': 'i386',
469             'dbtype': 'deb',
470             'pool name': 'main/h/hello/',
471             'location id': self.loc['main'].location_id,
472             'source package': 'hello',
473             'source version': '2.2-2',
474             'size': 0,
475             'md5sum': 'deadbeef',
476             'sha1sum': 'deadbeef',
477             'sha256sum': 'deadbeef'}
478         upload = Upload(pkg)
479         poolfile = add_deb_to_db(upload, 'hello_2.2-2_i386.deb', self.session)
480         self.session.refresh(poolfile)
481         self.session.refresh(poolfile.binary)
482         self.assertEqual('main/h/hello/hello_2.2-2_i386.deb', poolfile.filename)
483         self.assertEqual('hello', poolfile.binary.package)
484         self.assertEqual('2.2-2', poolfile.binary.version)
485         self.assertEqual(['sid'], poolfile.binary.suites)
486         self.assertEqual('Mr. Maintainer', poolfile.binary.maintainer.name)
487         self.assertEqual('i386', poolfile.binary.architecture.arch_string)
488         self.assertEqual('deb', poolfile.binary.binarytype)
489         self.assertEqual(self.loc['main'], poolfile.location)
490         self.assertEqual(self.source['hello_2.2-2'], poolfile.binary.source)
491         self.assertEqual(0, poolfile.filesize)
492         self.assertEqual('deadbeef', poolfile.md5sum)
493         self.assertEqual('deadbeef', poolfile.sha1sum)
494         self.assertEqual('deadbeef', poolfile.sha256sum)
495
496     def test_get_source_by_package_and_suite(self):
497         'test get_source_by_package_and_suite()'
498
499         query = get_source_by_package_and_suite('hello', 'sid', self.session)
500         self.assertEqual(self.source['hello_2.2-1'], query.one())
501         query = get_source_by_package_and_suite('gnome-hello', 'squeeze', self.session)
502         self.assertEqual(self.source['hello_2.2-1'], query.one())
503         query = get_source_by_package_and_suite('hello', 'hamm', self.session)
504         self.assertEqual(0, query.count())
505         query = get_source_by_package_and_suite('foobar', 'squeeze', self.session)
506         self.assertEqual(0, query.count())
507
508     def test_get_suite_version_by_package(self):
509         'test function get_suite_version_by_package()'
510
511         result = get_suite_version_by_package('hello', 'i386', self.session)
512         self.assertEqual(2, len(result))
513         self.assertTrue(('sid', '2.2-1') in result)
514         result = get_suite_version_by_package('hello', 'amd64', self.session)
515         self.assertEqual(0, len(result))
516         result = get_suite_version_by_package('python-hello', 'i386', self.session)
517         self.assertEqual([('squeeze', '2.2-1')], result)
518         result = get_suite_version_by_package('python-hello', 'amd64', self.session)
519         self.assertEqual([('squeeze', '2.2-1')], result)
520
521     def test_components(self):
522         'test class Component'
523
524         self.assertEqual(self.loc['main'], self.comp['main'].location)
525         self.assertEqual(self.loc['contrib'], self.comp['contrib'].location)
526
527     def test_get_component_by_package_suite(self):
528         'test get_component_by_package_suite()'
529
530         result = get_component_by_package_suite('hello', ['sid'], self.session)
531         self.assertEqual('main', result)
532         result = get_component_by_package_suite('hello', ['hamm'], self.session)
533         self.assertEqual(None, result)
534         result = get_component_by_package_suite('foobar', ['sid'], self.session)
535         self.assertEqual(None, result)
536
537 if __name__ == '__main__':
538     unittest.main()