예제 #1
0
    def test_fetch_available_3pm_transcripts_success(self):
        """
        Test available 3PlayMedia transcripts fetching (success case).
        """
        # Arrange:
        test_feedback = {'status': Status.success, 'message': 'test_message'}
        test_transcripts_list = [{'id': 'test_id', 'language_id': '2'}]
        test_args = ['id', 'label', 'lang', 'lang_id', 'content', 'format', 'video_id', 'source', 'url']

        with patch.object(self.xblock, 'get_3pm_transcripts_list') as threepm_transcripts_mock, \
                patch.object(self.xblock, 'fetch_single_3pm_translation') as fetch_3pm_translation_mock, \
                patch.object(self.xblock, 'threeplaymedia_file_id') as file_id_mock, \
                patch.object(self.xblock, 'threeplaymedia_apikey') as apikey_mock:
            threepm_transcripts_mock.return_value = test_feedback, test_transcripts_list
            fetch_3pm_translation_mock.return_value = Transcript(*test_args)

            # Act:
            transcripts_gen = self.xblock.fetch_available_3pm_transcripts()
            transcripts = list(transcripts_gen)

            # Assert:
            self.assertIsInstance(transcripts[0], OrderedDict)
            self.assertSequenceEqual(test_args, transcripts[0].keys())
            threepm_transcripts_mock.assert_called_once_with(file_id_mock, apikey_mock)
            fetch_3pm_translation_mock.assert_called_once_with(test_transcripts_list[0])
예제 #2
0
    def test_fetch_single_3pm_translation_success(self, requests_get_mock, player_mock):
        """
        Test single 3PlayMedia transcript fetching (success case).
        """
        # Arrange:
        test_lang_id = '1'
        test_transcript_text = 'test_transcript_text'
        test_format = 51
        test_transcript_id = 'test_id'
        test_video_id = 'test_video_id'
        test_source = '3play-media'
        file_id = 'test_file_id'
        api_key = 'test_api_key'

        test_transcript_data = {'id': test_transcript_id, 'language_id': test_lang_id}
        test_lang_code = TPMApiLanguage(test_lang_id)
        test_api_url = 'https://static.3playmedia.com/files/test_file_id/transcripts/test_id?' \
                       'apikey=test_api_key&format_id=51'

        requests_get_mock.return_value = ResponseStub(body=test_transcript_text)
        media_id_mock = player_mock.return_value.media_id
        media_id_mock.return_value = test_video_id
        self.xblock.threeplaymedia_file_id = file_id
        self.xblock.threeplaymedia_apikey = api_key

        test_args = [
            test_transcript_id,
            test_lang_code.name,
            test_lang_code.iso_639_1_code,
            test_lang_id,
            test_transcript_text,
            test_format,
            test_video_id,
            test_source,
            test_api_url
        ]

        # Act:
        transcript = self.xblock.fetch_single_3pm_translation(test_transcript_data)
        # Assert:
        self.assertEqual(transcript, Transcript(*test_args))