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) ''' main = self.loc['main'] contrib = self.loc['contrib'] self.assertEqual(fixture('ftp/pool/'), main.path) count = len(self.file.keys()) - 2 self.assertEqual(count, main.files.count()) self.assertEqual(2, contrib.files.count()) poolfile = main.files. \ filter(PoolFile.filename.like('%/hello/hello%')). \ 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, \ self.session.query(PoolFile).get(poolfile.file_id)) self.assertEqual(None, self.session.query(PoolFile).get(-1)) # test remove() and append() 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(3, contrib.files.count()) # test fullpath self.assertEqual(fixture('ftp/pool/main/s/sl/sl_3.03-16.dsc'), \ self.file['sl_3.03-16.dsc'].fullpath) # test check_poolfile() self.assertEqual((True, self.file['sl_3.03-16.dsc']), \ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, '', \ contrib.location_id, self.session)) # test string value of 2nd argument self.assertEqual((True, self.file['sl_3.03-16.dsc']), \ check_poolfile('main/s/sl/sl_3.03-16.dsc', '0', '', \ contrib.location_id, self.session)) self.assertEqual((False, None), \ check_poolfile('foobar', 0, '', contrib.location_id, self.session)) self.assertEqual((False, self.file['sl_3.03-16.dsc']), \ check_poolfile('main/s/sl/sl_3.03-16.dsc', 42, '', \ contrib.location_id, self.session)) self.assertEqual((False, self.file['sl_3.03-16.dsc']), \ check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \ contrib.location_id, self.session)) # test get_poolfile_like_name() self.assertEqual([self.file['sl_3.03-16.dsc']], \ get_poolfile_like_name('sl_3.03-16.dsc', self.session)) self.assertEqual([], get_poolfile_like_name('foobar', self.session))
def setup_locations(self): 'create some Location objects' if 'loc' in self.__dict__: return self.setup_components() self.loc = {} self.loc['main'] = Location( \ path = fixture('ftp/pool/'), component = self.comp['main']) self.loc['contrib'] = Location( \ path = fixture('ftp/pool/'), component = self.comp['contrib']) self.session.add_all(self.loc.values())
def initialize(self): cnf = Config() if cnf["DB::Name"] in ('backports', 'obscurity', 'projectb'): self.fail("You have configured an invalid database name: '%s'." % \ cnf["DB::Name"]) if cnf["DB::Host"]: # TCP/IP connstr = "postgres://%s" % cnf["DB::Host"] if cnf["DB::Port"] and cnf["DB::Port"] != "-1": connstr += ":%s" % cnf["DB::Port"] connstr += "/%s" % cnf["DB::Name"] else: # Unix Socket connstr = "postgres:///%s" % cnf["DB::Name"] if cnf["DB::Port"] and cnf["DB::Port"] != "-1": connstr += "?port=%s" % cnf["DB::Port"] pickle_filename = 'db-metadata-%s.pkl' % __version__ pickle_file = open(fixture(pickle_filename), 'r') DBDakTestCase.metadata = pickle.load(pickle_file) self.metadata.ddl_listeners = pickle.load(pickle_file) pickle_file.close() self.metadata.bind = create_engine(connstr) self.metadata.create_all() self.create_all_triggers()
def test_poolfiles(self): main = self.comp['main'] contrib = self.comp['contrib'] poolfile = self.session.query(PoolFile).filter( PoolFile.filename.like('%/hello/hello%')). \ order_by(PoolFile.filename)[0] self.assertEqual('h/hello/hello_2.2-1.dsc', poolfile.filename) self.assertEqual(main, poolfile.component) # test get() self.assertEqual(poolfile, self.session.query(PoolFile).get(poolfile.file_id)) self.assertEqual(None, self.session.query(PoolFile).get(-1)) # test fullpath self.assertEqual(fixture('tmpdak/ftp/pool/main/s/sl/sl_3.03-16.dsc'), self.file['sl_3.03-16.dsc'].fullpath)
def assertParse(self, filename, *args): return parse_changes(fixture(filename), *args)
def verify(filename, require_signature=True): with open(fixture(filename)) as fh: data = fh.read() return SignedFile(data, [keyring], require_signature)
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import datetime import unittest from base_test import DakTestCase, fixture from daklib.gpg import GpgException, SignedFile keyring = fixture('gpg/gnupghome/pubring.gpg') fpr_valid = '0ABB89079CB58F8F94F6F310CB9D5C5828606E84' fpr_expired = '05A558AE65B77B559BBE0C4D543B2BAEDA044F0B' fpr_expired_subkey = '8865D9EC71713394ADBD8F729F7A24B7F6388CE1' def verify(filename, require_signature=True): with open(fixture(filename)) as fh: data = fh.read() return SignedFile(data, [keyring], require_signature) class GpgTest(DakTestCase): def test_valid(self): result = verify('gpg/valid.asc') self.assertTrue(result.valid) self.assertEqual(result.primary_fingerprint, fpr_valid) self.assertEqual(result.contents, "Valid: yes\n")
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import datetime import unittest from base_test import DakTestCase, fixture from daklib.gpg import GpgException, SignedFile keyring = fixture('gpg/gnupghome/pubring.gpg') fpr_valid = '0ABB89079CB58F8F94F6F310CB9D5C5828606E84' fpr_expired = '05A558AE65B77B559BBE0C4D543B2BAEDA044F0B' fpr_expired_subkey = '8865D9EC71713394ADBD8F729F7A24B7F6388CE1' def verify(filename, require_signature=True): with open(fixture(filename)) as fh: data = fh.read() return SignedFile(data, [keyring], require_signature) class GpgTest(DakTestCase): def test_valid(self): result = verify('gpg/valid.asc') self.assertTrue(result.valid) self.assertFalse(result.weak_signature) self.assertEqual(result.primary_fingerprint, fpr_valid)
def verify(filename, require_signature=True): with open(fixture(filename), mode='rb') as fh: data = fh.read() return SignedFile(data, [keyring], require_signature)