from daklib.dbconn import Architecture, Suite, get_suite_architectures, \
get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \
- check_poolfile, get_poolfile_like_name
+ check_poolfile, get_poolfile_like_name, get_source_in_suite
+from sqlalchemy.orm.exc import MultipleResultsFound
import unittest
class PackageTestCase(DBDakTestCase):
self.file = {}
self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \
location = self.loc['main'], filesize = 0, md5sum = '')
+ self.file['hello_old'] = PoolFile(filename = 'main/h/hello/hello_2.2-1.dsc', \
+ location = self.loc['main'], filesize = 0, md5sum = '')
self.file['sl'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \
location = self.loc['main'], filesize = 0, md5sum = '')
+ self.file['python'] = PoolFile( \
+ filename = 'main/p/python2.6/python2.6_2.6.6-8.dsc', \
+ location = self.loc['main'], filesize = 0, md5sum = '')
self.session.add_all(self.file.values())
def test_poolfiles(self):
self.setup_poolfiles()
location = self.session.query(Location)[0]
self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', location.path)
- self.assertEqual(2, location.files.count())
+ self.assertEqual(4, location.files.count())
poolfile = location.files. \
- filter(PoolFile.filename.like('%/hello/hello%')).one()
+ 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(location, poolfile.location)
# test get()
# TODO: deletion should cascade automatically
self.session.delete(self.file['sl'])
self.session.refresh(location)
- self.assertEqual(1, location.files.count())
+ self.assertEqual(3, location.files.count())
# please note that we intentionally do not specify 'location' here
self.file['sl'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \
filesize = 0, md5sum = '')
location.files.append(self.file['sl'])
self.session.refresh(location)
- self.assertEqual(2, location.files.count())
+ self.assertEqual(4, location.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)
self.setup_maintainers()
self.setup_poolfiles()
- self.source = DBSource(source = 'hello', version = '2.2-2', \
+ self.setup_suites()
+ self.source = {}
+ self.source['hello'] = DBSource(source = 'hello', version = '2.2-2', \
maintainer = self.maintainer['maintainer'], \
changedby = self.maintainer['uploader'], \
poolfile = self.file['hello'], install_date = self.now())
+ self.source['hello'].suites.append(self.suite['sid'])
+ self.source['hello_old'] = DBSource(source = 'hello', version = '2.2-1', \
+ maintainer = self.maintainer['maintainer'], \
+ changedby = self.maintainer['uploader'], \
+ poolfile = self.file['hello_old'], install_date = self.now())
+ self.source['hello_old'].suites.append(self.suite['sid'])
+ self.source['sl'] = DBSource(source = 'sl', version = '3.03-16', \
+ maintainer = self.maintainer['maintainer'], \
+ changedby = self.maintainer['uploader'], \
+ poolfile = self.file['sl'], install_date = self.now())
+ self.source['sl'].suites.append(self.suite['squeeze'])
+ self.source['sl'].suites.append(self.suite['sid'])
def test_maintainers(self):
'''
lazyguy = self.maintainer['lazyguy']
self.assertEqual(lazyguy,
self.session.query(Maintainer).get(lazyguy.maintainer_id))
- self.assertEqual(maintainer.maintains_sources, [self.source])
+ 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(uploader.changed_sources, [self.source])
+ 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'
+ 'test relation between DBSource and PoolFile or Suite'
self.setup_sources()
- self.assertEqual(self.file['hello'], self.source.poolfile)
- self.assertEqual(self.source, self.file['hello'].source)
- self.assertEqual(None, self.file['sl'].source)
+ # 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))
if __name__ == '__main__':