X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Fdbtest_packages.py;h=12ab5960ded9a9795604a6d84746d86f64f0b67d;hb=221c511735a22974ac5ee9e1d2d5d52bf29e263e;hp=449cd5519ac854d0bc35d61b5f8b5eba6e4041be;hpb=59a219acf70252880f5939ce44620ab4c153496e;p=dak.git diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 449cd551..12ab5960 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -6,9 +6,10 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \ get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \ check_poolfile, get_poolfile_like_name, get_source_in_suite, \ get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \ - get_suites_binary_in + get_suites_binary_in, add_deb_to_db, Component from daklib.queue_install import package_to_suite -from daklib.queue import get_newest_source, get_suite_version +from daklib.queue import get_newest_source, get_suite_version_by_source, \ + get_source_by_package_and_suite, get_suite_version_by_package from sqlalchemy.orm.exc import MultipleResultsFound import unittest @@ -61,16 +62,29 @@ class PackageTestCase(DBDakTestCase): self.arch['all'].arch_id = 2 self.session.add_all(self.arch.values()) + def setup_components(self): + 'create some Component objects' + + if 'comp' in self.__dict__: + return + self.comp = {} + self.comp['main'] = Component(component_name = 'main') + self.comp['contrib'] = Component(component_name = 'contrib') + self.session.add_all(self.comp.values()) + def setup_locations(self): - 'create some Location objects, TODO: add component' + 'create some Location objects' if 'loc' in self.__dict__: return + self.setup_components() self.loc = {} - self.loc['main'] = Location(path = \ - '/srv/ftp-master.debian.org/ftp/pool/') - self.loc['contrib'] = Location(path = \ - '/srv/ftp-master.debian.org/ftp/pool/') + self.loc['main'] = Location( \ + path = '/srv/ftp-master.debian.org/ftp/pool/', \ + component = self.comp['main']) + self.loc['contrib'] = Location( \ + path = '/srv/ftp-master.debian.org/ftp/pool/', \ + component = self.comp['contrib']) self.session.add_all(self.loc.values()) def setup_poolfiles(self): @@ -84,13 +98,16 @@ class PackageTestCase(DBDakTestCase): location = self.loc['main'], filesize = 0, md5sum = '') self.file['hello_2.2-2.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \ location = self.loc['main'], filesize = 0, md5sum = '') - self.file['hello_2.2-2_i386.deb'] = PoolFile( \ - filename = 'main/h/hello/hello_2.2-2_i386.deb', \ + self.file['hello_2.2-1.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-1.dsc', \ + location = self.loc['main'], filesize = 0, md5sum = '') + self.file['hello_2.2-1_i386.deb'] = PoolFile( \ + filename = 'main/h/hello/hello_2.2-1_i386.deb', \ location = self.loc['main'], filesize = 0, md5sum = '') - self.file['gnome-hello_2.2-2_i386.deb'] = PoolFile( \ - filename = 'main/h/hello/gnome-hello_2.2-2_i386.deb', \ + self.file['gnome-hello_2.2-1_i386.deb'] = PoolFile( \ + filename = 'main/h/hello/gnome-hello_2.2-1_i386.deb', \ location = self.loc['main'], filesize = 0, md5sum = '') - self.file['hello_2.2-1.dsc'] = PoolFile(filename = 'main/h/hello/hello_2.2-1.dsc', \ + self.file['python-hello_2.2-1_all.deb'] = PoolFile( \ + filename = 'main/h/hello/python-hello_2.2-1_all.deb', \ location = self.loc['main'], filesize = 0, md5sum = '') self.file['sl_3.03-16.dsc'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \ location = self.loc['main'], filesize = 0, md5sum = '') @@ -145,20 +162,26 @@ class PackageTestCase(DBDakTestCase): self.setup_sources() self.setup_architectures() self.binary = {} - self.binary['hello_2.2-2_i386'] = DBBinary(package = 'hello', \ - source = self.source['hello_2.2-2'], version = '2.2-2', \ + self.binary['hello_2.2-1_i386'] = DBBinary(package = 'hello', \ + source = self.source['hello_2.2-1'], version = '2.2-1', \ maintainer = self.maintainer['maintainer'], \ architecture = self.arch['i386'], \ - poolfile = self.file['hello_2.2-2_i386.deb']) - self.binary['hello_2.2-2_i386'].suites.append(self.suite['squeeze']) - self.binary['hello_2.2-2_i386'].suites.append(self.suite['sid']) - self.binary['gnome-hello_2.2-2_i386'] = DBBinary(package = 'gnome-hello', \ - source = self.source['hello_2.2-2'], version = '2.2-2', \ + poolfile = self.file['hello_2.2-1_i386.deb']) + self.binary['hello_2.2-1_i386'].suites.append(self.suite['squeeze']) + self.binary['hello_2.2-1_i386'].suites.append(self.suite['sid']) + self.binary['gnome-hello_2.2-1_i386'] = DBBinary(package = 'gnome-hello', \ + source = self.source['hello_2.2-1'], version = '2.2-1', \ maintainer = self.maintainer['maintainer'], \ architecture = self.arch['i386'], \ - poolfile = self.file['gnome-hello_2.2-2_i386.deb']) - self.binary['gnome-hello_2.2-2_i386'].suites.append(self.suite['squeeze']) - self.binary['gnome-hello_2.2-2_i386'].suites.append(self.suite['sid']) + poolfile = self.file['gnome-hello_2.2-1_i386.deb']) + self.binary['gnome-hello_2.2-1_i386'].suites.append(self.suite['squeeze']) + self.binary['gnome-hello_2.2-1_i386'].suites.append(self.suite['sid']) + self.binary['python-hello_2.2-1_i386'] = DBBinary(package = 'python-hello', \ + source = self.source['hello_2.2-1'], version = '2.2-1', \ + maintainer = self.maintainer['maintainer'], \ + architecture = self.arch['all'], \ + poolfile = self.file['python-hello_2.2-1_all.deb']) + self.binary['python-hello_2.2-1_i386'].suites.append(self.suite['squeeze']) self.session.add_all(self.binary.values()) def setUp(self): @@ -219,8 +242,8 @@ class PackageTestCase(DBDakTestCase): 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) + order_by(PoolFile.filename)[0] + self.assertEqual('main/h/hello/hello_2.2-1.dsc', poolfile.filename) self.assertEqual(main, poolfile.location) # test get() self.assertEqual(poolfile, \ @@ -318,7 +341,7 @@ class PackageTestCase(DBDakTestCase): self.assertTrue(self.suite['squeeze'] in \ get_suites_source_in('sl', self.session)) - def test_upload(self): + def test_add_dsc_to_db(self): 'tests function add_dsc_to_db()' pkg = Pkg() @@ -330,7 +353,7 @@ class PackageTestCase(DBDakTestCase): pkg.changes['distribution'] = { 'sid': '' } pkg.files['hello_2.2-3.dsc'] = { \ 'component': 'main', - 'location id': self.loc['main'].component_id, + 'location id': self.loc['main'].location_id, 'files id': self.file['hello_2.2-3.dsc'].file_id } pkg.dsc_files = {} upload = Upload(pkg) @@ -340,8 +363,7 @@ class PackageTestCase(DBDakTestCase): 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(self.loc['main'].location_id, dsc_location_id) self.assertEqual([], pfs) def test_source_exists(self): @@ -395,14 +417,14 @@ class PackageTestCase(DBDakTestCase): self.assertEqual(self.source['hello_2.2-2'], 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()' + def test_get_suite_version_by_source(self): + 'test function get_suite_version_by_source()' - result = get_suite_version('hello', self.session) + 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('sl', self.session) + 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) @@ -415,14 +437,14 @@ class PackageTestCase(DBDakTestCase): # test Suite relation self.assertEqual(2, self.suite['sid'].binaries.count()) - self.assertTrue(self.binary['hello_2.2-2_i386'] in \ + 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(2, len(self.source['hello_2.2-2'].binaries)) - self.assertTrue(self.binary['hello_2.2-2_i386'] in \ - self.source['hello_2.2-2'].binaries) - self.assertEqual(0, len(self.source['hello_2.2-1'].binaries)) + 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 \ @@ -432,5 +454,74 @@ class PackageTestCase(DBDakTestCase): 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) + 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_source_by_package_and_suite(self): + 'test get_source_by_package_and_suite()' + + query = get_source_by_package_and_suite('hello', 'sid', self.session) + self.assertEqual(self.source['hello_2.2-1'], query.one()) + query = get_source_by_package_and_suite('gnome-hello', 'squeeze', self.session) + self.assertEqual(self.source['hello_2.2-1'], query.one()) + query = get_source_by_package_and_suite('hello', 'hamm', self.session) + self.assertEqual(0, query.count()) + query = get_source_by_package_and_suite('foobar', 'squeeze', self.session) + self.assertEqual(0, query.count()) + + 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) + if __name__ == '__main__': unittest.main()