+ # check the many to many relation between Suite and Architecture
+ self.assertEqual('source', self.suite['lenny'].architectures[0])
+ self.assertEqual(4, len(self.suite['lenny'].architectures))
+ self.assertEqual(3, len(self.arch['i386'].suites))
+ # check the function get_suite_architectures()
+ architectures = get_suite_architectures('lenny', session = self.session)
+ self.assertEqual(4, len(architectures))
+ self.assertTrue(self.arch['source'] in architectures)
+ self.assertTrue(self.arch['all'] in architectures)
+ self.assertTrue(self.arch['kfreebsd-i386'] not in architectures)
+ architectures = get_suite_architectures('sid', session = self.session)
+ self.assertEqual(5, len(architectures))
+ self.assertTrue(self.arch['kfreebsd-i386'] in architectures)
+ architectures = get_suite_architectures('lenny', skipsrc = True, session = self.session)
+ self.assertEqual(3, len(architectures))
+ self.assertTrue(self.arch['source'] not in architectures)
+ architectures = get_suite_architectures('lenny', skipall = True, session = self.session)
+ self.assertEqual(3, len(architectures))
+ self.assertTrue(self.arch['all'] not in architectures)
+ # check the function get_architecture_suites()
+ suites = get_architecture_suites('i386', self.session)
+ self.assertEqual(3, len(suites))
+ self.assertTrue(self.suite['lenny'] in suites)
+ suites = get_architecture_suites('kfreebsd-i386', self.session)
+ self.assertEqual(2, len(suites))
+ self.assertTrue(self.suite['lenny'] not in suites)
+
+ def test_poolfiles(self):
+ '''
+ Test the relation of the classes PoolFile and Location.
+
+ The code needs some explaination. The property Location.files is not a
+ list as in other relations because such a list would become rather
+ huge. It is a query object that can be queried, filtered, and iterated
+ as usual. But list like methods like append() and remove() are
+ supported as well which allows code like:
+
+ somelocation.files.append(somefile)
+ '''
+
+ main = self.loc['main']
+ contrib = self.loc['contrib']
+ self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', main.path)
+ self.assertEqual(5, main.files.count())
+ self.assertEqual(0, contrib.files.count())
+ poolfile = main.files. \
+ filter(PoolFile.filename.like('%/hello/hello%')). \
+ order_by(PoolFile.filename)[1]
+ self.assertEqual('main/h/hello/hello_2.2-2.dsc', poolfile.filename)
+ self.assertEqual(main, poolfile.location)
+ # test get()
+ self.assertEqual(poolfile, \
+ self.session.query(PoolFile).get(poolfile.file_id))
+ self.assertEqual(None, self.session.query(PoolFile).get(-1))
+ # test remove() and append()
+ main.files.remove(self.file['sl'])
+ contrib.files.append(self.file['sl'])
+ self.assertEqual(4, main.files.count())
+ self.assertEqual(1, contrib.files.count())
+ # test fullpath
+ self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/main/s/sl/sl_3.03-16.dsc', \
+ self.file['sl'].fullpath)
+ # test check_poolfile()
+ self.assertEqual((True, self.file['sl']), \
+ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, '', \
+ contrib.location_id, self.session))
+ self.assertEqual((False, None), \
+ check_poolfile('foobar', 0, '', contrib.location_id, self.session))
+ self.assertEqual((False, self.file['sl']), \
+ check_poolfile('main/s/sl/sl_3.03-16.dsc', 42, '', \
+ contrib.location_id, self.session))
+ self.assertEqual((False, self.file['sl']), \
+ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \
+ contrib.location_id, self.session))
+ # test get_poolfile_like_name()
+ self.assertEqual([self.file['sl']], \
+ get_poolfile_like_name('sl_3.03-16.dsc', self.session))
+ self.assertEqual([], get_poolfile_like_name('foobar', self.session))
+
+ def test_maintainers(self):
+ '''
+ tests relation between Maintainer and DBSource
+
+ TODO: add relations to changes_pending_source
+ '''
+
+ 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(3, len(maintainer.maintains_sources))
+ self.assertTrue(self.source['hello'] in maintainer.maintains_sources)
+ self.assertEqual(maintainer.changed_sources, [])
+ self.assertEqual(uploader.maintains_sources, [])
+ self.assertEqual(3, len(uploader.changed_sources))
+ self.assertTrue(self.source['sl'] 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'], self.source['hello'].poolfile)
+ self.assertEqual(self.source['hello'], self.file['hello'].source)
+ self.assertEqual(None, self.file['python'].source)
+ # test Suite
+ squeeze = self.session.query(Suite). \
+ filter(Suite.sources.contains(self.source['sl'])). \
+ order_by(Suite.suite_name)[1]
+ self.assertEqual(self.suite['squeeze'], squeeze)
+ self.assertEqual(1, len(squeeze.sources))
+ self.assertEqual(self.source['sl'], squeeze.sources[0])
+ sl = self.session.query(DBSource). \
+ filter(DBSource.suites.contains(self.suite['squeeze'])).one()
+ self.assertEqual(self.source['sl'], 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'], \
+ 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_upload(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'].component_id,
+ 'files id': self.file['hello_new'].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)
+ # no dsc files defined above
+ self.assertEqual(None, dsc_location_id)
+ self.assertEqual([], pfs)
+
+ def test_source_exists(self):
+ 'test function source_exists()'
+
+ hello = self.source['hello']
+ self.assertTrue(source_exists(hello.source, hello.version, \
+ suites = ['sid'], session = self.session))
+ # binNMU
+ self.assertTrue(source_exists(hello.source, hello.version + '+b7', \
+ suites = ['sid'], session = self.session))
+ self.assertTrue(not source_exists(hello.source, hello.version, \
+ suites = ['lenny', 'squeeze'], session = self.session))
+ self.assertTrue(not source_exists(hello.source, hello.version, \
+ suites = ['lenny', 'sid'], session = self.session))
+ self.assertTrue(not source_exists(hello.source, hello.version, \
+ suites = ['sid', 'lenny'], session = self.session))
+ self.assertTrue(not source_exists(hello.source, '0815', \
+ suites = ['sid'], session = self.session))
+ # 'any' suite
+ self.assertTrue(source_exists(hello.source, hello.version, \
+ session = self.session))
+
+ def test_package_to_suite(self):
+ 'test function package_to_suite()'
+
+ pkg = Pkg()
+ pkg.changes = { 'distribution': {} }
+ upload = Upload(pkg)
+ self.assertTrue(not package_to_suite(upload, 'sid', self.session))
+ pkg.changes['distribution'] = { 'sid': '' }
+ pkg.changes['architecture'] = { 'source': '' }
+ self.assertTrue(package_to_suite(upload, 'sid', self.session))
+ pkg.changes['architecture'] = {}
+ pkg.changes['source'] = self.source['hello'].source
+ pkg.changes['version'] = self.source['hello'].version
+ self.assertTrue(not package_to_suite(upload, 'sid', self.session))
+ pkg.changes['version'] = '42'
+ self.assertTrue(package_to_suite(upload, 'sid', self.session))
+ pkg.changes['source'] = 'foobar'
+ pkg.changes['version'] = self.source['hello'].version
+ self.assertTrue(package_to_suite(upload, 'sid', self.session))
+ pkg.changes['distribution'] = { 'lenny': '' }
+ self.assertTrue(package_to_suite(upload, 'lenny', self.session))
+
+ def test_get_newest_source(self):
+ 'test function get_newest_source()'
+
+ import daklib.queue
+ daklib.queue.dm_suites = ['sid']
+ self.assertEqual(self.source['hello'], get_newest_source('hello', self.session))
+ self.assertEqual(None, get_newest_source('foobar', self.session))
+
+ def test_get_suite_version(self):
+ 'test function get_suite_version()'
+
+ result = get_suite_version('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('sl', self.session)
+ self.assertEqual(2, len(result))
+ self.assertTrue(('squeeze', '3.03-16') in result)
+ self.assertTrue(('sid', '3.03-16') in result)