Beispiel #1
0
    def test_update_transcription_service_credentials_exceptions(self, mock_client, mock_logger):
        """
        Tests that the update transcription service credentials logs the exception occurring
        during communication with edx-video-pipeline.
        """
        error_content = '{"error_type": "1"}'
        resp = Mock()
        resp.content = error_content
        resp.raise_for_status.side_effect = HTTPError(response=resp)
        mock_client.return_value.post.return_value = resp

        # try updating the transcription service credentials
        credentials_payload = {
            'org': 'mit',
            'provider': 'ABC Provider',
            'api_key': '61c56a8d0'
        }
        error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)

        # Assert the results.
        assert not is_updated
        self.assertDictEqual(error_response, json.loads(error_content))
        mock_logger.exception.assert_called_with(
            'Unable to update transcript credentials -- org=%s, provider=%s, response=%s',
            credentials_payload['org'],
            credentials_payload['provider'],
            error_content
        )
Beispiel #2
0
    def test_update_transcription_service_credentials_exceptions(
            self, mock_client, mock_logger):
        """
        Tests that the update transcription service credentials logs the exception occurring
        during communication with edx-video-pipeline.
        """
        error_content = '{"error_type": "1"}'
        mock_client.return_value.request = Mock(side_effect=HttpClientError(
            content=error_content))

        # try updating the transcription service credentials
        credentials_payload = {
            'org': 'mit',
            'provider': 'ABC Provider',
            'api_key': '61c56a8d0'
        }
        error_response, is_updated = update_3rd_party_transcription_service_credentials(
            **credentials_payload)

        # Assert the results.
        self.assertFalse(is_updated)
        self.assertDictEqual(error_response, json.loads(error_content))
        mock_logger.exception.assert_called_with(
            'Unable to update transcript credentials -- org={}, provider={}, response={}'
            .format(credentials_payload['org'],
                    credentials_payload['provider'], error_content))
Beispiel #3
0
    def test_update_transcription_service_credentials_exceptions(self, mock_client, mock_logger):
        """
        Tests that the update transcription service credentials logs the exception occurring
        during communication with edx-video-pipeline.
        """
        error_content = '{"error_type": "1"}'
        # Mock the post request
        mock_credentials_endpoint = mock_client.return_value.transcript_credentials
        mock_credentials_endpoint.post = Mock(side_effect=HttpClientError(content=error_content))
        # try updating the transcription service credentials
        credentials_payload = {
            'org': 'mit',
            'provider': 'ABC Provider',
            'api_key': '61c56a8d0'
        }
        error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)

        mock_credentials_endpoint.post.assert_called_with(credentials_payload)
        # Assert the results.
        self.assertFalse(is_updated)
        self.assertDictEqual(error_response, json.loads(error_content))
        mock_logger.exception.assert_called_with(
            '[video-pipeline-service] Unable to update transcript credentials -- org=%s -- provider=%s -- response=%s.',
            credentials_payload['org'],
            credentials_payload['provider'],
            error_content
        )
Beispiel #4
0
    def test_update_transcription_service_credentials(self,
                                                      credentials_payload,
                                                      mock_client,
                                                      mock_logger):
        """
        Tests that the update transcription service credentials api util works as expected.
        """
        mock_client.request.return_value.ok = True

        # Try updating the transcription service credentials
        error_response, is_updated = update_3rd_party_transcription_service_credentials(
            **credentials_payload)

        # Making sure log.exception is not called.
        self.assertDictEqual(error_response, {})
        self.assertFalse(mock_logger.exception.called)
        self.assertTrue(is_updated)

        mock_logger.info.assert_any_call(
            'Sending transcript credentials to VEM for org: {} and provider: {}'
            .format(credentials_payload.get('org'),
                    credentials_payload.get('provider')))
        mock_logger.info.assert_any_call(
            'Sending transcript credentials to VEDA for org: {} and provider: {}'
            .format(credentials_payload.get('org'),
                    credentials_payload.get('provider')))
Beispiel #5
0
 def test_update_transcription_service_credentials_with_integration_disabled(self):
     """
     Test updating the credentials when service integration is disabled.
     """
     self.pipeline_integration.enabled = False
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #6
0
 def test_update_transcription_service_credentials_with_unknown_oauth_client(self):
     """
     Test updating the credentials when expected oauth cleint is not present.
     """
     self.pipeline_integration.client_name = 'non_existent_client'
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #7
0
 def test_update_transcription_service_credentials_with_unknown_user(self):
     """
     Test updating the credentials when expected service user is not registered.
     """
     self.pipeline_integration.service_username = '******'
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #8
0
 def test_update_transcription_service_credentials_with_unknown_oauth_client(self):
     """
     Test updating the credentials when expected oauth cleint is not present.
     """
     self.pipeline_integration.client_name = 'non_existent_client'
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #9
0
 def test_update_transcription_service_credentials_with_integration_disabled(self):
     """
     Test updating the credentials when service integration is disabled.
     """
     self.pipeline_integration.enabled = False
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #10
0
 def test_update_transcription_service_credentials_with_unknown_user(self):
     """
     Test updating the credentials when expected service user is not registered.
     """
     self.pipeline_integration.service_username = '******'
     self.pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #11
0
 def test_update_transcription_service_credentials_when_one_service_fails(
         self):
     """
     Test that if one of the transcription service fails to update credentials,
     response from `update_3rd_party_transcription_service_credentials` is False.
     """
     self.vem_pipeline_integration.client_name = 'non_existent_client'
     self.vem_pipeline_integration.save()
     __, is_updated = update_3rd_party_transcription_service_credentials()
     self.assertFalse(is_updated)
Beispiel #12
0
    def test_update_transcription_service_credentials_with_vem_disabled(self):
        """
        Test updating the credentials when VEM integration is disabled.
        """
        # Disabling VEM
        self.vem_pipeline_integration.enabled = False
        self.vem_pipeline_integration.save()

        __, is_updated = update_3rd_party_transcription_service_credentials()
        assert not is_updated
Beispiel #13
0
def transcript_credentials_handler(request, course_key_string):
    """
    JSON view handler to update the transcript organization credentials.

    Arguments:
        request: WSGI request object
        course_key_string: A course identifier to extract the org.

    Returns:
        - A 200 response if credentials are valid and successfully updated in edx-video-pipeline.
        - A 404 response if transcript feature is not enabled for this course.
        - A 400 if credentials do not pass validations, hence not updated in edx-video-pipeline.
    """
    course_key = CourseKey.from_string(course_key_string)
    if not VideoTranscriptEnabledFlag.feature_enabled(course_key):
        return HttpResponseNotFound()

    provider = request.json.pop('provider')
    error_message, validated_credentials = validate_transcript_credentials(
        provider=provider, **request.json)
    if error_message:
        response = JsonResponse({'error': error_message}, status=400)
    else:
        # Send the validated credentials to edx-video-pipeline.
        credentials_payload = dict(validated_credentials,
                                   org=course_key.org,
                                   provider=provider)
        if waffle_flags()[SAVE_CREDENTIALS_IN_VAL].is_enabled(course_key):
            from edxval.api import create_or_update_transcript_credentials
            response = create_or_update_transcript_credentials(
                **credentials_payload)
            error_response, is_updated = response, not response.get(
                'error_type')
        else:
            error_response, is_updated = update_3rd_party_transcription_service_credentials(
                **credentials_payload)
        # Send appropriate response based on whether credentials were updated or not.
        if is_updated:
            # Cache credentials state in edx-val.
            update_transcript_credentials_state_for_org(org=course_key.org,
                                                        provider=provider,
                                                        exists=is_updated)
            response = JsonResponse(status=200)
        else:
            # Error response would contain error types and the following
            # error type is received from edx-video-pipeline whenever we've
            # got invalid credentials for a provider. Its kept this way because
            # edx-video-pipeline doesn't support i18n translations yet.
            error_type = error_response.get('error_type')
            if error_type == TranscriptionProviderErrorType.INVALID_CREDENTIALS:
                error_message = _('The information you entered is incorrect.')

            response = JsonResponse({'error': error_message}, status=400)

    return response
Beispiel #14
0
    def test_update_transcription_service_credentials(self, credentials_payload, mock_client, mock_logger):
        """
        Tests that the update transcription service credentials api util works as expected.
        """
        mock_client.request.return_value.ok = True

        # Try updating the transcription service credentials
        error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)

        # Making sure log.exception is not called.
        self.assertDictEqual(error_response, {})
        self.assertFalse(mock_logger.exception.called)
        self.assertTrue(is_updated)
Beispiel #15
0
    def test_update_transcription_service_credentials(self, credentials_payload, mock_client, mock_logger):
        """
        Tests that the update transcription service credentials api util works as expected.
        """
        # Mock the post request
        mock_credentials_endpoint = mock_client.return_value.transcript_credentials
        # Try updating the transcription service credentials
        error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)

        mock_credentials_endpoint.post.assert_called_with(credentials_payload)
        # Making sure log.exception is not called.
        self.assertDictEqual(error_response, {})
        self.assertFalse(mock_logger.exception.called)
        self.assertTrue(is_updated)
Beispiel #16
0
    def test_update_transcription_service_credentials_with_both_integration_disabled(
            self):
        """
        Test updating the credentials when both service integration are disabled.
        """
        # Disabling VEDA
        self.veda_pipeline_integration.enabled = False
        self.veda_pipeline_integration.save()

        # Disabling VEM
        self.vem_pipeline_integration.enabled = False
        self.vem_pipeline_integration.save()

        __, is_updated = update_3rd_party_transcription_service_credentials()
        self.assertFalse(is_updated)
def transcript_credentials_handler(request, course_key_string):
    """
    JSON view handler to update the transcript organization credentials.

    Arguments:
        request: WSGI request object
        course_key_string: A course identifier to extract the org.

    Returns:
        - A 200 response if credentials are valid and successfully updated in edx-video-pipeline.
        - A 404 response if transcript feature is not enabled for this course.
        - A 400 if credentials do not pass validations, hence not updated in edx-video-pipeline.
    """
    course_key = CourseKey.from_string(course_key_string)
    if not VideoTranscriptEnabledFlag.feature_enabled(course_key):
        return HttpResponseNotFound()

    provider = request.json.pop('provider')
    error_message, validated_credentials = validate_transcript_credentials(provider=provider, **request.json)
    if error_message:
        response = JsonResponse({'error': error_message}, status=400)
    else:
        # Send the validated credentials to edx-video-pipeline.
        credentials_payload = dict(validated_credentials, org=course_key.org, provider=provider)
        error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)
        # Send appropriate response based on whether credentials were updated or not.
        if is_updated:
            # Cache credentials state in edx-val.
            update_transcript_credentials_state_for_org(org=course_key.org, provider=provider, exists=is_updated)
            response = JsonResponse(status=200)
        else:
            # Error response would contain error types and the following
            # error type is received from edx-video-pipeline whenever we've
            # got invalid credentials for a provider. Its kept this way because
            # edx-video-pipeline doesn't support i18n translations yet.
            error_type = error_response.get('error_type')
            if error_type == TranscriptionProviderErrorType.INVALID_CREDENTIALS:
                error_message = _('The information you entered is incorrect.')

            response = JsonResponse({'error': error_message}, status=400)

    return response
Beispiel #18
0
    def test_update_transcription_service_credentials_for_vem(self, mock_client, mock_logger):
        """
        Test that if waffle flag `ENABLE_VEM_PIPELINE` is on for course, then credentials
        are successfully posted to VEM.
        """
        self.add_vem_client()
        course_key = CourseLocator("test_org", "test_course_num", "test_run")
        credentials_payload = {
            'username': '******',
            'api_key': '12345678',
            'course_key': course_key
        }
        mock_client.request.return_value.ok = True

        # Try updating the transcription service credentials
        with override_waffle_flag(waffle_flags()[ENABLE_VEM_PIPELINE], active=True):
            error_response, is_updated = update_3rd_party_transcription_service_credentials(**credentials_payload)

        # Making sure log.exception is not called.
        self.assertDictEqual(error_response, {})
        self.assertFalse(mock_logger.exception.called)
        self.assertTrue(is_updated)
Beispiel #19
0
    def test_update_transcription_service_credentials_with_one_integration_disabled(
            self, mock_client, mock_logger):
        """
        Test that updating the credentials when one of the service integration is disabled, allows
        the credentials to be updated for other pipeline.
        """
        mock_client.request.return_value.ok = True
        credentials_payload = {
            'org': 'mit',
            'provider': 'ABC Provider',
            'api_key': '61c56a8d0'
        }

        self.veda_pipeline_integration.enabled = False
        self.veda_pipeline_integration.save()
        __, is_updated = update_3rd_party_transcription_service_credentials(
            **credentials_payload)
        mock_logger.info.assert_called_with(
            'Sending transcript credentials to VEM for org: {} and provider: {}'
            .format(credentials_payload.get('org'),
                    credentials_payload.get('provider')))
        self.assertTrue(is_updated)