X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Fdbtest_packages.py;h=439c9a2e0f49382debb375cb41a6d96d811f3677;hb=22b0b5b1963b6c298f6f619ad7cbbd262bf9ea77;hp=deca4812d3bc08ac6a158f30ad1f100432103ba4;hpb=d6fb77d2760192195245e87d6f60a418c465d0b1;p=dak.git diff --git a/tests/dbtest_packages.py b/tests/dbtest_packages.py index deca4812..439c9a2e 100755 --- a/tests/dbtest_packages.py +++ b/tests/dbtest_packages.py @@ -3,7 +3,7 @@ from db_test import DBDakTestCase from daklib.dbconn import Architecture, Suite, get_suite_architectures, \ - get_architecture_suites, Maintainer, DBSource + get_architecture_suites, Maintainer, DBSource, Location, PoolFile import unittest @@ -90,6 +90,57 @@ class PackageTestCase(DBDakTestCase): self.assertEqual(2, len(suites)) self.assertTrue(self.suite['lenny'] not in suites) + def setup_locations(self): + 'create some Location objects, TODO: add component' + + self.loc = {} + self.loc['main'] = Location(path = \ + '/srv/ftp-master.debian.org/ftp/pool/') + self.session.add(self.loc['main']) + + def setup_poolfiles(self): + 'create some PoolFile objects' + + self.file = {} + self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.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.session.add_all(self.file.values()) + + 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) + ''' + self.setup_locations() + 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()) + poolfile = location.files. \ + filter(PoolFile.filename.like('%/hello/hello%')).one() + self.assertEqual('main/h/hello/hello_2.2-2.dsc', poolfile.filename) + self.assertEqual(location, poolfile.location) + location.files.remove(self.file['sl']) + # TODO: deletion should cascade automatically + self.session.delete(self.file['sl']) + self.session.refresh(location) + self.assertEqual(1, 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()) + def setup_maintainers(self): 'create some Maintainer objects'