X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Fdbtest_packages.py;h=44ec0efe028ffa56f2556f889a1d793f4c90a603;hb=463d5ef1536b2af10a0990c5d9ee56e9380a66a4;hp=7150866b65f47a005ebd04dd6e278da5346242d7;hpb=bd446acbd6d2e5f500ef73e4ffd0fb894ec74b87;p=dak.git diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index 7150866b..44ec0efe 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -6,9 +6,11 @@ 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, add_deb_to_db + get_suites_binary_in, add_deb_to_db, Component, \ + get_component_by_package_suite 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 +63,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): @@ -86,12 +101,21 @@ class PackageTestCase(DBDakTestCase): location = self.loc['main'], filesize = 0, md5sum = '') 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['gnome-hello_3.0-1.dsc'] = PoolFile( \ + filename = 'main/g/gnome-hello/gnome-hello_3.0-1.dsc', \ + location = self.loc['contrib'], 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-1_i386.deb'] = PoolFile( \ filename = 'main/h/hello/gnome-hello_2.2-1_i386.deb', \ location = self.loc['main'], filesize = 0, md5sum = '') + 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['gnome-hello_3.0-1_i386.deb'] = PoolFile( \ + filename = 'main/g/gnome-hello/gnome-hello_3.0-1_i386.deb', \ + location = self.loc['contrib'], 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 = '') self.file['python2.6_2.6.6-8.dsc'] = PoolFile( \ @@ -129,6 +153,11 @@ class PackageTestCase(DBDakTestCase): changedby = self.maintainer['uploader'], \ poolfile = self.file['hello_2.2-1.dsc'], install_date = self.now()) self.source['hello_2.2-1'].suites.append(self.suite['sid']) + self.source['gnome-hello_3.0-1'] = DBSource(source = 'gnome-hello', \ + version = '3.0-1', maintainer = self.maintainer['maintainer'], \ + changedby = self.maintainer['uploader'], \ + poolfile = self.file['gnome-hello_3.0-1.dsc'], install_date = self.now()) + self.source['gnome-hello_3.0-1'].suites.append(self.suite['sid']) self.source['sl_3.03-16'] = DBSource(source = 'sl', version = '3.03-16', \ maintainer = self.maintainer['maintainer'], \ changedby = self.maintainer['uploader'], \ @@ -159,6 +188,18 @@ class PackageTestCase(DBDakTestCase): 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['gnome-hello_3.0-1_i386'] = DBBinary(package = 'gnome-hello', \ + source = self.source['gnome-hello_3.0-1'], version = '3.0-1', \ + maintainer = self.maintainer['maintainer'], \ + architecture = self.arch['i386'], \ + poolfile = self.file['gnome-hello_3.0-1_i386.deb']) + self.binary['gnome-hello_3.0-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): @@ -214,9 +255,9 @@ class PackageTestCase(DBDakTestCase): main = self.loc['main'] contrib = self.loc['contrib'] self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', main.path) - count = len(self.file.keys()) + count = len(self.file.keys()) - 2 self.assertEqual(count, main.files.count()) - self.assertEqual(0, contrib.files.count()) + self.assertEqual(2, contrib.files.count()) poolfile = main.files. \ filter(PoolFile.filename.like('%/hello/hello%')). \ order_by(PoolFile.filename)[0] @@ -230,7 +271,7 @@ class PackageTestCase(DBDakTestCase): main.files.remove(self.file['sl_3.03-16.dsc']) contrib.files.append(self.file['sl_3.03-16.dsc']) self.assertEqual(count - 1, main.files.count()) - self.assertEqual(1, contrib.files.count()) + self.assertEqual(3, 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_3.03-16.dsc'].fullpath) @@ -267,11 +308,11 @@ class PackageTestCase(DBDakTestCase): lazyguy = self.maintainer['lazyguy'] self.assertEqual(lazyguy, self.session.query(Maintainer).get(lazyguy.maintainer_id)) - self.assertEqual(3, len(maintainer.maintains_sources)) + 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(3, len(uploader.changed_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, []) @@ -394,14 +435,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) @@ -413,12 +454,12 @@ class PackageTestCase(DBDakTestCase): ''' # test Suite relation - self.assertEqual(2, self.suite['sid'].binaries.count()) + 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(2, 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)) @@ -469,5 +510,49 @@ class PackageTestCase(DBDakTestCase): 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) + + def test_get_component_by_package_suite(self): + 'test get_component_by_package_suite()' + + result = get_component_by_package_suite('hello', ['sid'], self.session) + self.assertEqual('main', result) + result = get_component_by_package_suite('hello', ['hamm'], self.session) + self.assertEqual(None, result) + result = get_component_by_package_suite('foobar', ['sid'], self.session) + self.assertEqual(None, result) + # test that the newest version is returend + result = get_component_by_package_suite('gnome-hello', ['sid'], self.session) + self.assertEqual('contrib', result) + if __name__ == '__main__': unittest.main()