def test_upload_rejects(self): # Parse the changes file changes = upload.Changes(fixture('packages'), 'linux_42.0-1_amd64.changes', [fixture('packages/gpg/pubring.gpg')], True) # Insert the fingerprint, but without associating it to a keyring dbconn.get_or_set_fingerprint( changes.primary_fingerprint, self.session) self.session.commit() # Try to upload, it should fail with the key being unknown with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertFalse(result) self.assertEquals(attempt.reject_reasons, [u'.changes signed by unknown key.']) # Import the keyring self.setup_keys() # New attempt, it should fail with missing suite with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertFalse(result) self.assertEquals(attempt.reject_reasons, [u'No target suite found. Please check your target distribution and that you uploaded to the right archive.']) # Add the missing suite self.setup_suites([('unstable', 'sid')]) self.session.commit() # New attempt, it should fail with missing srcformat with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertFalse(result) self.assertEquals(attempt.reject_reasons, [u'source format 3.0 (quilt) is not allowed in suite unstable']) # Add the missing format self.setup_srcformats() # New attempt, it should fail with missing architecture with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertFalse(result) self.assertEquals(attempt.reject_reasons, [u'Architecture source is not allowed in suite unstable']) # Add the missing architecture / suites connection self.setup_architectures() self.session.commit() # New attempt, it should succeed and be a new package. with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertTrue(result) self.assertTrue(attempt.new) self.assertEquals(attempt.reject_reasons, [])
def test_upload_new(self): # Parse the changes file changes = upload.Changes(fixture('packages'), 'linux_42.0-1_amd64.changes', [fixture('packages/gpg/pubring.gpg')], True) # Do all the setup needed for the upload to be accepted dbconn.get_or_set_fingerprint(changes.primary_fingerprint, self.session) self.setup_keys() self.setup_suites([('unstable', 'sid')]) self.setup_srcformats() self.setup_architectures() self.session.commit() # First attempt, it should succeed and be a NEW package first_upload = self.attempt_upload(changes) with first_upload as attempt: result = attempt.check() self.assertTrue(result) self.assertTrue(attempt.new) self.assertEquals(attempt.reject_reasons, []) # Add the override for the source package override = {} override['package'] = changes.source_name override['priority'] = 'optional' override['section'] = 'kernel' override['component'] = changes.source.component override['type'] = 'dsc' queue = policy.PolicyQueueUploadHandler(changes, self.session) queue.add_overrides([override], self.suite['unstable']) self.session.commit() # Second attempt, it should succeed but be NEW because of new binaries with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertTrue(result) self.assertTrue(attempt.new) self.assertEquals(attempt.reject_reasons, []) # Add the binary overrides overrides = [] for binary in changes.binaries: override = {} override['package'] = binary.name override['priority'] = 'optional' override['section'] = 'kernel' override['component'] = binary.component override['type'] = binary.type overrides.append(override) queue.add_overrides(overrides, self.suite['unstable']) self.session.commit() # Third attempt, this time it should succeed and not be NEW with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertTrue(result) self.assertFalse(attempt.new) self.assertEquals(attempt.reject_reasons, [])
def setup_keys(self): ''' Inserts the fingerprints in the keyring into the database.''' if 'keyring' in self.__dict__: return self.keyring = dbconn.Keyring() self.keyring.keyring_id = 1 self.keyring.load_keys(fixture('packages/gpg/pubring.gpg')) _, _ = self.keyring.generate_users_from_keyring('%s', self.session) for key in self.keyring.keys.values(): fpr = key['fingerprints'][0] fp = dbconn.get_or_set_fingerprint(fpr, self.session) fp.keyring_id = self.keyring.keyring_id fp.uid_id = dbconn.get_or_set_uid(key['uid'], self.session).uid_id self.session.add(fp) self.session.commit()
def setup_keys(self): ''' Inserts the fingerprints in the keyring into the database.''' if 'keyring' in self.__dict__: return self.keyring = dbconn.Keyring() self.keyring.keyring_id = 1 self.keyring.load_keys(fixture('packages/gpg/pubring.gpg')) _, _ = self.keyring.generate_users_from_keyring('%s', self.session) for key in self.keyring.keys.values(): fpr = key['fingerprints'][0] fp = dbconn.get_or_set_fingerprint(fpr, self.session) fp.keyring_id = self.keyring.keyring_id fp.uid_id = dbconn.get_or_set_uid(key['uid'], self.session).uid_id self.session.add(fp) self.session.commit()
def test_unpack(self): ''' Tests the UnpackedSource class and the SourceContentsScanner. ''' self.setup_sources() source = self.source['hello_2.2-1'] dscfilename = fixture('ftp/pool/' + source.poolfile.filename) unpacked = UnpackedSource(dscfilename) self.assertTrue(len(unpacked.get_root_directory()) > 0) self.assertEqual('hello (2.2-1) unstable; urgency=low\n', unpacked.get_changelog_file().readline()) all_filenames = set(unpacked.get_all_filenames()) self.assertEqual(8, len(all_filenames)) self.assertTrue('debian/rules' in all_filenames) # method scan_contents() self.assertEqual(all_filenames, source.scan_contents()) # exception with invalid files self.assertRaises(CalledProcessError, lambda: UnpackedSource('invalidname')) # SourceContentsScanner self.session.commit() self.assertTrue(source.contents.count() == 0) SourceContentsScanner(source.source_id).scan() self.assertTrue(source.contents.count() > 0)
def test_unpack(self): ''' Tests the UnpackedSource class and the SourceContentsScanner. ''' self.setup_sources() source = self.source['hello_2.2-1'] dscfilename = fixture('ftp/pool/' + source.poolfile.filename) unpacked = UnpackedSource(dscfilename) self.assertTrue(len(unpacked.get_root_directory()) > 0) self.assertEqual('hello (2.2-1) unstable; urgency=low\n', unpacked.get_changelog_file().readline()) all_filenames = set(unpacked.get_all_filenames()) self.assertEqual(8, len(all_filenames)) self.assertTrue('debian/rules' in all_filenames) # method scan_contents() self.assertEqual(all_filenames, source.scan_contents()) # exception with invalid files self.assertRaises(CalledProcessError, lambda: UnpackedSource('invalidname')) # SourceContentsScanner self.session.commit() self.assertTrue(source.contents.count() == 0) SourceContentsScanner(source.source_id).scan() self.assertTrue(source.contents.count() > 0)
def attempt_upload(self, changes): '''Return an ArchiveUpload for the received changes.''' return archive.ArchiveUpload(fixture('packages'), changes, [fixture('packages/gpg/pubring.gpg')])
def attempt_upload(self, changes): '''Return an ArchiveUpload for the received changes.''' return archive.ArchiveUpload( fixture('packages'), changes, [fixture('packages/gpg/pubring.gpg')])
def test_upload_new(self): # Parse the changes file changes = upload.Changes(fixture('packages'), 'linux_42.0-1_amd64.changes', [fixture('packages/gpg/pubring.gpg')], True) # Do all the setup needed for the upload to be accepted dbconn.get_or_set_fingerprint( changes.primary_fingerprint, self.session) self.setup_keys() self.setup_suites([('unstable', 'sid')]) self.setup_srcformats() self.setup_architectures() self.session.commit() # First attempt, it should succeed and be a NEW package first_upload = self.attempt_upload(changes) with first_upload as attempt: result = attempt.check() self.assertTrue(result) self.assertTrue(attempt.new) self.assertEquals(attempt.reject_reasons, []) # Add the override for the source package override = {} override['package'] = changes.source_name override['priority'] = 'optional' override['section'] = 'kernel' override['component'] = changes.source.component override['type'] = 'dsc' queue = policy.PolicyQueueUploadHandler(changes, self.session) queue.add_overrides([override], self.suite['unstable']) self.session.commit() # Second attempt, it should succeed but be NEW because of new binaries with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertTrue(result) self.assertTrue(attempt.new) self.assertEquals(attempt.reject_reasons, []) # Add the binary overrides overrides = [] for binary in changes.binaries: override = {} override['package'] = binary.name override['priority'] = 'optional' override['section'] = 'kernel' override['component'] = binary.component override['type'] = binary.type overrides.append(override) queue.add_overrides(overrides, self.suite['unstable']) self.session.commit() # Third attempt, this time it should succeed and not be NEW with self.attempt_upload(changes) as attempt: result = attempt.check() self.assertTrue(result) self.assertFalse(attempt.new) self.assertEquals(attempt.reject_reasons, [])