def download_build_log_file(test_id): """ Serve download of build log. :param test_id: id of the test :type test_id: int :raises TestNotFoundException: when build log not found :raises TestNotFoundException: when test id is not found :return: build log text file :rtype: Flask response """ from run import config test = Test.query.filter(Test.id == test_id).first() if test is not None: # Fetch logfile log_file_path = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'LogFiles', test_id + '.txt') if os.path.isfile(log_file_path): return serve_file_download(test_id + '.txt', 'LogFiles', 'logfile-download', content_type='text/plain') raise TestNotFoundException( 'Build log for Test {id} not found'.format(id=test_id)) raise TestNotFoundException( 'Test with id {id} not found'.format(id=test_id))
def download_sample_additional(sample_id, additional_id): """ Download sample file's additional files and information. :param sample_id: id of the sample :type sample_id: int :param additional_id: id of the additional file :type additional_id: int :raises SampleNotFoundException: when additional file id is not found :raises SampleNotFoundException: when sample id is not found :return: sample's additional information file :rtype: Flask response """ sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Fetch additional info extra = ExtraFile.query.filter(ExtraFile.id == additional_id).first() if extra is not None: return serve_file_download(extra.filename, 'TestFiles', 'media-download', 'extra') raise SampleNotFoundException( 'Extra file {a_id} for sample {s_id} not found'.format( a_id=additional_id, s_id=sample.id)) raise SampleNotFoundException( 'Sample with id {id} not found'.format(id=sample_id))
def download_sample_media_info(sample_id): """ Download sample file's media information as XML. :param sample_id: id of the sample file :type sample_id: int :raises SampleNotFoundException: when sample id is not found :return: sample file's media info file :rtype: Flask response """ from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Fetch media info media_info_path = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles', 'media', sample.sha + '.xml') if os.path.isfile(media_info_path): return serve_file_download(sample.sha + '.xml', 'TestFiles', 'media-download', 'media', 'text/xml') raise SampleNotFoundException( 'Media information for sample {id} not found'.format(id=sample.id)) raise SampleNotFoundException( 'Sample with id {id} not found'.format(id=sample_id))
def test_result_file(regression_test_output_id): """View the output files of the regression test.""" rto = RegressionTestOutput.query.filter( RegressionTestOutput.id == regression_test_output_id).first() if rto is None: g.log.error( f'requested regression test output with id: {regression_test_output_id} not found!' ) abort(404) return serve_file_download(rto.filename_correct, 'TestResults', 'regression-download')
def test_serve_file_download(self, mock_path): """ Test function serve_file_download. """ from utility import serve_file_download response = serve_file_download('to_download', 'folder', 'accl_folder') self.assert200(response) self.assertEqual(2, mock_path.join.call_count) mock_path.getsize.assert_called_once_with(mock_path.join())
def download_sample(sample_id): """ Download sample file. :param sample_id: id of the sample file :type sample_id: int :raises SampleNotFoundException: when sample id is not found :return: sample file :rtype: Flask response """ sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: return serve_file_download(sample.filename, 'TestFiles', 'media-download') raise SampleNotFoundException('Sample not found')