Beispiel #1
0
    def test__process_track_missing_type(self):
        """Test _process_track method for track missing type."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = OrderedDict()

        with self.assertRaises(InvalidMediaInfoError):
            MediaInfoFetcher._process_track(MOCK_MediaInfoFetcher, track)
Beispiel #2
0
    def test__process_tracks_no_track(self):
        """Test _process_tracks method with no track in media info file."""
        # set new mocks to eradicate interference with other usage
        MOCK_MediaInfoFetcher = mock.MagicMock()
        MOCK_MediaInfoFetcher.media_info = {'media': OrderedDict()}

        with self.assertRaises(InvalidMediaInfoError):
            MediaInfoFetcher._process_tracks(MOCK_MediaInfoFetcher)
Beispiel #3
0
    def test__process_tracks_file_key_error(self):
        """Test _process_tracks method with key error in self.media_info."""
        # set new mocks to eradicate interference with other usage
        MOCK_MediaInfoFetcher = mock.MagicMock()
        MOCK_MediaInfoFetcher.media_info = {}

        with self.assertRaises(InvalidMediaInfoError):
            MediaInfoFetcher._process_tracks(MOCK_MediaInfoFetcher)
Beispiel #4
0
    def test__process_track_text(self):
        """Test _process_track method for text track."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = OrderedDict([('@type', 'Text')])

        MediaInfoFetcher._process_track(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher._process_text.assert_called_once_with(track)
Beispiel #5
0
    def test__process_track_general(self):
        """Test _process_track method for general track."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = OrderedDict([('@type', 'General')])

        MediaInfoFetcher._process_track(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher._process_general.assert_called_once_with(track)
    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())
Beispiel #7
0
    def test__process_general(self):
        """Test _process_general method."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = {}
        key_list = ['Format', 'FileSize', 'Duration', 'CodecID']

        MediaInfoFetcher._process_general(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher._process_generic.assert_called_once_with(track, key_list)
Beispiel #8
0
    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()
Beispiel #9
0
    def test__process_tracks(self):
        """Test _process_tracks method with valid information."""
        # set new mocks to eradicate interference with other usage
        MOCK_MediaInfoFetcher = mock.MagicMock()
        MOCK_MediaInfoFetcher.media_info = {'media': OrderedDict([('track', ['track1'])])}

        MediaInfoFetcher._process_tracks(MOCK_MediaInfoFetcher)

        MOCK_MediaInfoFetcher._process_track.assert_called_once_with('track1')
Beispiel #10
0
    def test__process_text(self):
        """Test _process_text method."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = {'ID': 'test'}
        key_list = ['Format', 'MenuID', 'MuxingMode']

        MediaInfoFetcher._process_text(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher.caption_tracks.append.assert_called_once()
        MOCK_MediaInfoFetcher._process_generic.assert_called_once_with(track, key_list)
    def test__process_track_audio(self):
        """
        Test _process_track method for audio track.

        This is currently not supported.
        """
        MOCK_MediaInfoFetcher.reset_mock()
        track = OrderedDict([('@type', 'Audio')])

        MediaInfoFetcher._process_track(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher._process_audio.assert_not_called()
Beispiel #12
0
    def test__process_track_not_ordereddict(self):
        """Test _process_track method for invalid track."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = {}

        result = MediaInfoFetcher._process_track(MOCK_MediaInfoFetcher, track)

        self.assertIsNone(result)
Beispiel #13
0
    def test_get_media_info_forced(self):
        """Test get_media_info with forced parsing."""
        MOCK_MediaInfoFetcher.reset_mock()

        result = MediaInfoFetcher.get_media_info(MOCK_MediaInfoFetcher, True)

        MOCK_MediaInfoFetcher._process_tracks.assert_called_once()
        self.assertEqual(len(result), 4)
Beispiel #14
0
    def test_init(self, mock_xml, mock_os, mock_open):
        """Test initialisation of MediaInfoFetcher."""
        mock_xml.parse.return_value = {'MediaInfo': 'test'}

        MediaInfoFetcher(MockSample())

        mock_os.path.join.assert_called_once()
        mock_os.path.isfile.assert_called_once()
        mock_xml.parse.assert_called_once_with(mock_open().__enter__().read())
Beispiel #15
0
    def test__process_generic(self):
        """Test replacement of key '_' with " " using _process_generic method."""
        MOCK_MediaInfoFetcher.reset_mock()
        keys = ['some_key', 'FileSize', 'Duration']
        track = OrderedDict([('some_key', 'test'), ('FileSize', '1048576'), ('Duration', '60')])

        result = MediaInfoFetcher._process_generic(MOCK_MediaInfoFetcher, track, keys)
        self.assertEqual(result['some key'], track['some_key'])
        self.assertEqual(result['FileSize'], '1.0 MB')
        self.assertEqual(result['Duration'], '1m 0s')
Beispiel #16
0
    def test__process_video(self):
        """Test _process_video method."""
        MOCK_MediaInfoFetcher.reset_mock()
        track = {
            'Width': 10,
            'Height': 10,
            'Format': 'mp4',
            'FrameRate': '30',
            'FrameRate_mode': 'fps',
            'ScanType': 'test',
            'ScanOrder': 'vertical',
            'ID': 'test'
        }
        key_list = ['DisplayAspectRatio', 'Encoded_Library', 'Duration', 'CodecID']

        MediaInfoFetcher._process_video(MOCK_MediaInfoFetcher, track)

        MOCK_MediaInfoFetcher._process_generic.assert_called_once_with(track, key_list)
        MOCK_MediaInfoFetcher.video_tracks.append.assert_called_once()
Beispiel #17
0
    def test_init_invalid_media_info_path(self, mock_xml, mock_os, mock_open):
        """Test initialisation of MediaInfoFetcher with wrong media info file."""
        mock_os.path.isfile.return_value = False

        with self.assertRaises(InvalidMediaInfoError):
            MediaInfoFetcher(MockSample())

        mock_os.path.join.assert_called_once()
        mock_os.path.isfile.assert_called_once()
        mock_xml.parse.assert_not_called()
Beispiel #18
0
    def test_init_invalid_media_xml(self, mock_xml, mock_os, mock_open):
        """Test initialisation of MediaInfoFetcher with wrong media xml."""
        mock_xml.parse.side_effect = Exception

        with self.assertRaises(InvalidMediaInfoError):
            MediaInfoFetcher(MockSample())

        mock_os.path.join.assert_called_once()
        mock_os.path.isfile.assert_called_once()
        mock_xml.parse.assert_called_once_with(mock_open().__enter__().read())
    def test__process_generic(self):
        """
        Test replacement of key '_' with " " using _process_generic method.
        """
        MOCK_MediaInfoFetcher.reset_mock()
        keys = ['some_key']
        track = OrderedDict([('some_key', 'test')])

        result = MediaInfoFetcher._process_generic(MOCK_MediaInfoFetcher, track, keys)
        self.assertEqual(result['some key'], track['some_key'])
Beispiel #20
0
    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):
    # 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()
    }
Beispiel #23
0
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
    }