Exemple #1
0
    def test_generate_transcripts_exceptions(self, first_response,
                                             second_response, third_response,
                                             mock_log):
        """
        Tests the proper exceptions during transcript generation.
        """
        responses.add(responses.HEAD,
                      u'https://s3.amazonaws.com/bkt/video.mp4',
                      **first_response)
        responses.add(
            responses.GET,
            u'https://api.3playmedia.com/caption_imports/available_languages',
            **second_response)
        responses.add(responses.POST, u'https://api.3playmedia.com/files',
                      **third_response)
        three_play_client = ThreePlayMediaClient(
            **self.video_transcript_preferences)
        three_play_client.generate_transcripts()

        self.assertFalse(mock_log.info.called)
        mock_log.exception.assert_called_with(
            u'[3PlayMedia] Could not process transcripts for video=%s source_language=%s.',
            VIDEO_DATA['studio_id'],
            VIDEO_DATA['source_language'],
        )
        self.assertEqual(TranscriptProcessMetadata.objects.count(), 0)
Exemple #2
0
    def start_3play_transcription_process(self, encoded_file):
        """
        3PlayMedia Transcription Flow

        Arguments:
            encoded_file (str): name of encoded file to construct video url
        """
        try:
            # Picks the first course from the list as there may be multiple
            # course runs in that list (i.e. all having the same org).
            org = extract_course_org(self.video_proto.platform_course_url[0])
            transcript_secrets = TranscriptCredentials.objects.get(org=org, provider=self.video_query.provider)

            # update transcript status for video.
            val_api_client = VALAPICall(video_proto=None, val_status=None)
            utils.update_video_status(
                val_api_client=val_api_client,
                video=self.video_query,
                status=TranscriptStatus.IN_PROGRESS
            )

            # Initialize 3playMedia client and start transcription process
            s3_video_url = build_url(
                self.auth_dict['s3_base_url'],
                self.auth_dict['edx_s3_endpoint_bucket'],
                encoded_file
            )
            callback_url = build_url(
                self.auth_dict['veda_base_url'],
                reverse(
                    '3play_media_callback',
                    args=[self.auth_dict['transcript_provider_request_token']]
                ),
                # Additional attributes that'll come back with the callback
                org=org,
                edx_video_id=self.video_query.studio_id,
                lang_code=self.video_query.source_language,
            )
            three_play_media = ThreePlayMediaClient(
                org=org,
                video=self.video_query,
                media_url=s3_video_url,
                api_key=transcript_secrets.api_key,
                api_secret=transcript_secrets.api_secret,
                callback_url=callback_url,
                turnaround_level=self.video_query.three_play_turnaround,
                three_play_api_base_url=self.auth_dict['three_play_api_base_url'],
            )
            three_play_media.generate_transcripts()

        except TranscriptCredentials.DoesNotExist:
            LOGGER.warning(
                '[DELIVERY] : Transcript preference is not found for provider=%s, video=%s',
                self.video_query.provider,
                self.video_query.studio_id,
            )
Exemple #3
0
    def test_generate_transcripts_unknown_exceptions(self, mock_log):
        """
        Verify that the unknown exceptions are logged during transcript generation.
        """
        three_play_client = ThreePlayMediaClient(**self.video_transcript_preferences)

        with self.assertRaises(ValueError):
            three_play_client.generate_transcripts()

        self.assertFalse(mock_log.info.called)
        mock_log.exception.assert_called_with(
            u'[3PlayMedia] Unexpected error while transcription for video=%s source_language=%s.',
            VIDEO_DATA['studio_id'],
            VIDEO_DATA['source_language'],
        )
        self.assertEqual(TranscriptProcessMetadata.objects.count(), 0)
Exemple #4
0
    def test_transcription_flow(self, mock_logger):
        """
        Verify 3PlayMedia happy transcription flow
        """
        three_play_client = ThreePlayMediaClient(
            **self.video_transcript_preferences)

        responses.add(
            responses.HEAD,
            u'https://s3.amazonaws.com/bkt/video.mp4',
            headers={'Content-Type': u'video/mp4'},
            status=200,
        )

        responses.add(
            responses.GET,
            u'https://api.3playmedia.com/caption_imports/available_languages',
            body=json.dumps([{
                "iso_639_1_code": "en",
                "language_id": 1,
            }]),
            status=200,
        )

        responses.add(responses.POST,
                      u'https://api.3playmedia.com/files',
                      body=u'111222',
                      status=200)

        three_play_client.generate_transcripts()

        # Total of 3 HTTP requests are made
        self.assertEqual(len(responses.calls), 3)

        body = dict(
            # Mandatory attributes required for transcription
            link=self.video_transcript_preferences['media_url'],
            apikey=self.video_transcript_preferences['api_key'],
            api_secret_key=self.video_transcript_preferences['api_secret'],
            turnaround_level=self.
            video_transcript_preferences['turnaround_level'],
            callback_url=self.video_transcript_preferences['callback_url'],
            language_id=1,
            batch_name='Default',
        )

        expected_requests = [
            {
                'url': u'https://s3.amazonaws.com/bkt/video.mp4',
                'body': None,
                'method': 'HEAD',
            },
            {
                'url':
                u'https://api.3playmedia.com/caption_imports/available_languages?apikey=insecure_api_key',
                'body': None,
                'method': 'GET',
            },
            {
                'url': u'https://api.3playmedia.com/files',
                'body': body,
                'method': 'POST',
                'headers': {
                    'Content-Type': 'application/json'
                },
                'decode_func': json.loads
            },
        ]

        for position, expected_request in enumerate(expected_requests):
            self.assert_request(
                received_request=responses.calls[position].request,
                expected_request=expected_request,
                decode_func=expected_request.pop('decode_func', None))

        self.assertEqual(TranscriptProcessMetadata.objects.count(), 1)

        mock_logger.info.assert_called_with(
            '[3PlayMedia] Transcription process has been started for video=%s, source_language=%s.',
            VIDEO_DATA['studio_id'],
            VIDEO_DATA['source_language'],
        )