+ # 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()
+ 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())
+ # 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, '', \
+ location.location_id, self.session))
+ self.assertEqual((False, None), \
+ check_poolfile('foobar', 0, '', location.location_id, self.session))
+ self.assertEqual((False, self.file['sl']), \
+ check_poolfile('main/s/sl/sl_3.03-16.dsc', 42, '', \
+ location.location_id, self.session))
+ self.assertEqual((False, self.file['sl']), \
+ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \
+ location.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))