def test_generate_media_xml_windows(self, mock_sys): """ Raise error when generating media info xml for windows. """ mock_sys.platform = 'windows' with self.assertRaises(InvalidMediaInfoError): MediaInfoFetcher.generate_media_xml(MockSample())
def test_generate_media_xml_not_file(self, mock_sys, mock_subprocess, mock_open): """Raise error when media_info_path is not a file.""" mock_sys.platform = 'linux' with self.assertRaises(InvalidMediaInfoError): MediaInfoFetcher.generate_media_xml(MockSample()) mock_open.assert_called_once() mock_subprocess.Popen.assert_called_once()
def test_generate_media_xml(self, mock_sys, mock_subprocess, mock_open, mock_os, mock_etree, mock_media_info_fetcher): """Test generate_media_xml method with valid information.""" mock_sys.platform = 'linux' mock_os.path.isfile.return_value = True response = MediaInfoFetcher.generate_media_xml(MockSample()) self.assertEqual(response, mock_media_info_fetcher()) mock_open.assert_called_once() mock_subprocess.Popen.assert_called_once() mock_os.path.isfile.assert_called_once() mock_etree.parse.assert_called_once()
def display_sample_info(sample) -> Dict[str, Any]: """ Fetch the media info. :param sample: sample entry from the database :type sample: Model Sample :return: sample information if successful :rtype: dict """ try: media_info_fetcher = MediaInfoFetcher(sample) media_info = media_info_fetcher.get_media_info() except InvalidMediaInfoError: # Try to regenerate the file try: media_info_fetcher = MediaInfoFetcher.generate_media_xml(sample) media_info = media_info_fetcher.get_media_info() except InvalidMediaInfoError: # in case no media info present in the sample media_info = None latest_commit = GeneralData.query.filter( GeneralData.key == 'last_commit').first().value last_release = CCExtractorVersion.query.order_by( CCExtractorVersion.released.desc()).first().commit test_commit = Test.query.filter(Test.commit == latest_commit).first() test_release = Test.query.filter(Test.commit == last_release).first() regression_tests = RegressionTest.query.filter( RegressionTest.sample_id == sample.id).all() status = 'Unknown' status_release = 'Unknown' if len(regression_tests) > 0: if test_commit is not None: sq = g.db.query(RegressionTest.id).filter( RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter( and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq)))).first() not_null = g.db.query(TestResultFile.got).filter( and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq)))).first() if exit_code is None and not_null is None: status = 'Pass' else: status = 'Fail' if test_release is not None: sq = g.db.query(RegressionTest.id).filter( RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter( and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq)))).first() not_null = g.db.query(TestResultFile.got).filter( and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq)))).first() if exit_code is None and not_null is None: status_release = 'Pass' else: status_release = 'Fail' else: status = 'Not present in regression tests' status_release = 'Not present in regression tests' return { 'sample': sample, 'media': media_info, 'additional_files': ExtraFile.query.filter(ExtraFile.sample_id == sample.id).all(), 'latest_commit': status, 'latest_commit_test': test_commit, 'latest_release': status_release, 'latest_release_test': test_release, 'issues': Issue.query.filter(Issue.sample_id == sample.id).all() }
def display_sample_info(sample): try: media_info_fetcher = MediaInfoFetcher(sample) except InvalidMediaInfoError: # Try to regenerate the file try: media_info_fetcher = MediaInfoFetcher.generate_media_xml(sample) except InvalidMediaInfoError as i: raise SampleNotFoundException(i.message) try: media_info = media_info_fetcher.get_media_info() except InvalidMediaInfoError as i: raise SampleNotFoundException(i.message) latest_commit = GeneralData.query.filter( GeneralData.key == 'last_commit').first().value last_release = CCExtractorVersion.query.order_by( CCExtractorVersion.released.desc()).first().commit test_commit = Test.query.filter(Test.commit == latest_commit).first() test_release = Test.query.filter(Test.commit == last_release).first() regression_tests = RegressionTest.query.filter( RegressionTest.sample_id == sample.id).all() status = 'Unknown' status_release = 'Unknown' if len(regression_tests) > 0: if test_commit is not None: sq = g.db.query(RegressionTest.id).filter( RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter( and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq)))).first() not_null = g.db.query(TestResultFile.got).filter( and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq)))).first() if exit_code is None and not_null is None: status = 'Pass' else: status = 'Fail' if test_release is not None: sq = g.db.query(RegressionTest.id).filter( RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter( and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq)))).first() not_null = g.db.query(TestResultFile.got).filter( and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq)))).first() if exit_code is None and not_null is None: status = 'Pass' else: status = 'Fail' else: status = 'Not present in regression tests' status_release = 'Not present in regression tests' return { 'sample': sample, 'media': media_info, 'additional_files': ExtraFile.query.filter(ExtraFile.sample_id == sample.id).all(), 'latest_commit': status, 'latest_commit_test': test_commit, 'latest_release': status_release, 'latest_release_test': test_release }
def display_sample_info(sample): # Fetching the media info try: media_info_fetcher = MediaInfoFetcher(sample) media_info = media_info_fetcher.get_media_info() except InvalidMediaInfoError: # Try to regenerate the file try: media_info_fetcher = MediaInfoFetcher.generate_media_xml(sample) media_info = media_info_fetcher.get_media_info() except InvalidMediaInfoError: # in case no media info present in the sample media_info = None latest_commit = GeneralData.query.filter(GeneralData.key == 'last_commit').first().value last_release = CCExtractorVersion.query.order_by(CCExtractorVersion.released.desc()).first().commit test_commit = Test.query.filter(Test.commit == latest_commit).first() test_release = Test.query.filter(Test.commit == last_release).first() regression_tests = RegressionTest.query.filter(RegressionTest.sample_id == sample.id).all() status = 'Unknown' status_release = 'Unknown' if len(regression_tests) > 0: if test_commit is not None: sq = g.db.query(RegressionTest.id).filter(RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter(and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq)) )).first() not_null = g.db.query(TestResultFile.got).filter(and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq)) )).first() if exit_code is None and not_null is None: status = 'Pass' else: status = 'Fail' if test_release is not None: sq = g.db.query(RegressionTest.id).filter( RegressionTest.sample_id == sample.id).subquery() exit_code = g.db.query(TestResult.exit_code).filter( and_( TestResult.exit_code != TestResult.expected_rc, and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq)) ) ).first() not_null = g.db.query(TestResultFile.got).filter(and_( TestResultFile.got.isnot(None), and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq)) )).first() if exit_code is None and not_null is None: status_release = 'Pass' else: status_release = 'Fail' else: status = 'Not present in regression tests' status_release = 'Not present in regression tests' return { 'sample': sample, 'media': media_info, 'additional_files': ExtraFile.query.filter( ExtraFile.sample_id == sample.id).all(), 'latest_commit': status, 'latest_commit_test': test_commit, 'latest_release': status_release, 'latest_release_test': test_release, 'issues': Issue.query.filter(Issue.sample_id == sample.id).all() }