def test_compute_md5_hash(self): with open('hash_test.txt', 'w') as file: file.write('hash_test') file.close() hash_value = compute_md5_hash('hash_test.txt') os.remove('hash_test.txt') expected = '2a29b291e1c47197860e5efae100a9ab' self.assertEqual(expected, hash_value)
def post(self) -> (str, int): cfg = current_app.config payload = json.loads(request.data) if self.PayloadKey.Project not in payload: return 'invalid payload', HttpStatus.BadRequest project = payload[self.PayloadKey.Project] artefact = self.find_artefact(payload, self.Artefact.Apk) if artefact is not None: success, file_path = download_file(artefact[self.PayloadKey.Url], cfg['DOWNLOAD_DIR'], artefact[self.PayloadKey.Filename]) if success and os.path.exists(file_path): md5_hash = compute_md5_hash(file_path) if md5_hash == artefact[self.PayloadKey.Checksum]: now = datetime.datetime.today() file_name = self.generate_file_name(project, artefact, now) upload_to_google_drive.delay(file_path=file_path, credentials_dir=cfg['CREDENTIALS_DIR'], file_name=file_name, drive_dir=self.GoogleDriveConfig.BuildDir) self.insert_project_if_not_exists(project) self.insert_build_history_entry(project) return 'upload started', HttpStatus.OK else: if os.path.exists(file_path): os.remove(file_path) return 'could not download the artefact: invalid checksum [{0}]'.format(md5_hash),\ HttpStatus.Forbidden return 'could not download the artefact', HttpStatus.Forbidden else: return 'invalid payload', HttpStatus.BadRequest
def test_compute_md5_hash_none_file_path(self): compute_md5_hash(None)
def test_compute_md5_hash_file_not_found(self): compute_md5_hash("12345abcdef.png")
def test_compute_md5_hash_empty_file_path(self): compute_md5_hash('')