+ maintainer = self.maintainer['maintainer']
+ self.assertEqual(maintainer,
+ self.session.query(Maintainer).get(maintainer.maintainer_id))
+ uploader = self.maintainer['uploader']
+ self.assertEqual(uploader,
+ self.session.query(Maintainer).get(uploader.maintainer_id))
+ lazyguy = self.maintainer['lazyguy']
+ self.assertEqual(lazyguy,
+ self.session.query(Maintainer).get(lazyguy.maintainer_id))
+ self.assertEqual(4, len(maintainer.maintains_sources))
+ self.assertTrue(self.source['hello_2.2-2'] in maintainer.maintains_sources)
+ self.assertEqual(maintainer.changed_sources, [])
+ self.assertEqual(uploader.maintains_sources, [])
+ self.assertEqual(4, len(uploader.changed_sources))
+ self.assertTrue(self.source['sl_3.03-16'] in uploader.changed_sources)
+ self.assertEqual(lazyguy.maintains_sources, [])
+ self.assertEqual(lazyguy.changed_sources, [])
+
+ def get_source_in_suite_fail(self):
+ '''
+ This function throws the MultipleResultsFound exception because
+ get_source_in_suite is broken.
+
+ TODO: fix get_source_in_suite
+ '''
+
+ return get_source_in_suite('hello', 'sid', self.session)
+
+ def test_sources(self):
+ 'test relation between DBSource and PoolFile or Suite'
+
+ # test PoolFile
+ self.assertEqual(self.file['hello_2.2-2.dsc'], self.source['hello_2.2-2'].poolfile)
+ self.assertEqual(self.source['hello_2.2-2'], self.file['hello_2.2-2.dsc'].source)
+ self.assertEqual(None, self.file['python2.6_2.6.6-8.dsc'].source)
+ # test Suite
+ squeeze = self.session.query(Suite). \
+ filter(Suite.sources.contains(self.source['sl_3.03-16'])). \
+ order_by(Suite.suite_name)[1]
+ self.assertEqual(self.suite['squeeze'], squeeze)
+ self.assertEqual(1, squeeze.sources.count())
+ self.assertEqual(self.source['sl_3.03-16'], squeeze.sources[0])
+ sl = self.session.query(DBSource). \
+ filter(DBSource.suites.contains(self.suite['squeeze'])).one()
+ self.assertEqual(self.source['sl_3.03-16'], sl)
+ self.assertEqual(2, len(sl.suites))
+ self.assertTrue(self.suite['sid'] in sl.suites)
+ # test get_source_in_suite()
+ self.assertRaises(MultipleResultsFound, self.get_source_in_suite_fail)
+ self.assertEqual(None, \
+ get_source_in_suite('hello', 'squeeze', self.session))
+ self.assertEqual(self.source['sl_3.03-16'], \
+ get_source_in_suite('sl', 'sid', self.session))
+ # test get_suites_source_in()
+ self.assertEqual([self.suite['sid']], \
+ get_suites_source_in('hello', self.session))
+ self.assertEqual(2, len(get_suites_source_in('sl', self.session)))
+ self.assertTrue(self.suite['squeeze'] in \
+ get_suites_source_in('sl', self.session))
+
+ def test_add_dsc_to_db(self):
+ 'tests function add_dsc_to_db()'
+
+ pkg = Pkg()
+ pkg.dsc['source'] = 'hello'
+ pkg.dsc['version'] = '2.2-3'
+ pkg.dsc['maintainer'] = self.maintainer['maintainer'].name
+ pkg.changes['changed-by'] = self.maintainer['uploader'].name
+ pkg.changes['fingerprint'] = 'deadbeef'
+ pkg.changes['distribution'] = { 'sid': '' }
+ pkg.files['hello_2.2-3.dsc'] = { \
+ 'component': 'main',
+ 'location id': self.loc['main'].location_id,
+ 'files id': self.file['hello_2.2-3.dsc'].file_id }
+ pkg.dsc_files = {}
+ upload = Upload(pkg)
+ (source, dsc_component, dsc_location_id, pfs) = \
+ add_dsc_to_db(upload, 'hello_2.2-3.dsc', self.session)
+ self.assertEqual('hello', source.source)
+ self.assertEqual('2.2-3', source.version)
+ self.assertEqual('sid', source.suites[0].suite_name)
+ self.assertEqual('main', dsc_component)
+ self.assertEqual(self.loc['main'].location_id, dsc_location_id)
+ self.assertEqual([], pfs)
+
+ def test_get_suite_version_by_source(self):
+ 'test function get_suite_version_by_source()'
+
+ result = get_suite_version_by_source('hello', self.session)
+ self.assertEqual(2, len(result))
+ self.assertTrue(('sid', '2.2-1') in result)
+ self.assertTrue(('sid', '2.2-2') in result)
+ result = get_suite_version_by_source('sl', self.session)
+ self.assertEqual(2, len(result))
+ self.assertTrue(('squeeze', '3.03-16') in result)
+ self.assertTrue(('sid', '3.03-16') in result)
+
+ def test_binaries(self):
+ '''
+ tests class DBBinary; TODO: test relation with Architecture, Maintainer,
+ PoolFile, and Fingerprint
+ '''
+
+ # test Suite relation
+ self.assertEqual(3, self.suite['sid'].binaries.count())
+ self.assertTrue(self.binary['hello_2.2-1_i386'] in \
+ self.suite['sid'].binaries.all())
+ self.assertEqual(0, self.suite['lenny'].binaries.count())
+ # test DBSource relation
+ self.assertEqual(3, len(self.source['hello_2.2-1'].binaries))
+ self.assertTrue(self.binary['hello_2.2-1_i386'] in \
+ self.source['hello_2.2-1'].binaries)
+ self.assertEqual(0, len(self.source['hello_2.2-2'].binaries))
+ # test get_suites_binary_in()
+ self.assertEqual(2, len(get_suites_binary_in('hello', self.session)))
+ self.assertTrue(self.suite['sid'] in \
+ get_suites_binary_in('hello', self.session))
+ self.assertEqual(2, len(get_suites_binary_in('gnome-hello', self.session)))
+ self.assertTrue(self.suite['squeeze'] in \
+ get_suites_binary_in('gnome-hello', self.session))
+ self.assertEqual(0, len(get_suites_binary_in('sl', self.session)))
+
+ def test_add_deb_to_db(self):
+ 'tests function add_deb_to_db()'
+
+ pkg = Pkg()
+ pkg.changes['fingerprint'] = 'deadbeef'
+ pkg.changes['distribution'] = { 'sid': '' }
+ pkg.files['hello_2.2-2_i386.deb'] = { \
+ 'package': 'hello',
+ 'version': '2.2-2',
+ 'maintainer': self.maintainer['maintainer'].name,
+ 'architecture': 'i386',
+ 'dbtype': 'deb',
+ 'pool name': 'main/h/hello/',
+ 'location id': self.loc['main'].location_id,
+ 'source package': 'hello',
+ 'source version': '2.2-2',
+ 'size': 0,
+ 'md5sum': 'deadbeef',
+ 'sha1sum': 'deadbeef',
+ 'sha256sum': 'deadbeef'}
+ upload = Upload(pkg)
+ bin, poolfile = add_deb_to_db(upload, 'hello_2.2-2_i386.deb', self.session)
+ self.session.refresh(poolfile)
+ self.session.refresh(poolfile.binary)
+ self.assertEqual('main/h/hello/hello_2.2-2_i386.deb', poolfile.filename)
+ self.assertEqual('hello', poolfile.binary.package)
+ self.assertEqual('2.2-2', poolfile.binary.version)
+ self.assertEqual(['sid'], poolfile.binary.suites)
+ self.assertEqual('Mr. Maintainer', poolfile.binary.maintainer.name)
+ self.assertEqual('i386', poolfile.binary.architecture.arch_string)
+ self.assertEqual('deb', poolfile.binary.binarytype)
+ self.assertEqual(self.loc['main'], poolfile.location)
+ self.assertEqual(self.source['hello_2.2-2'], poolfile.binary.source)
+ self.assertEqual(0, poolfile.filesize)
+ self.assertEqual('deadbeef', poolfile.md5sum)
+ self.assertEqual('deadbeef', poolfile.sha1sum)
+ self.assertEqual('deadbeef', poolfile.sha256sum)
+
+ def test_get_suite_version_by_package(self):
+ 'test function get_suite_version_by_package()'
+
+ result = get_suite_version_by_package('hello', 'i386', self.session)
+ self.assertEqual(2, len(result))
+ self.assertTrue(('sid', '2.2-1') in result)
+ result = get_suite_version_by_package('hello', 'amd64', self.session)
+ self.assertEqual(0, len(result))
+ result = get_suite_version_by_package('python-hello', 'i386', self.session)
+ self.assertEqual([('squeeze', '2.2-1')], result)
+ result = get_suite_version_by_package('python-hello', 'amd64', self.session)
+ self.assertEqual([('squeeze', '2.2-1')], result)
+
+ def test_components(self):
+ 'test class Component'
+
+ self.assertEqual([self.loc['main']], self.comp['main'].location)
+ self.assertEqual([self.loc['contrib']], self.comp['contrib'].location)
+ self.assertEqual(0, self.comp['main'].overrides.count())
+
+ def test_get_component_by_package_suite(self):
+ 'test get_component_by_package_suite()'