add credentials saving in VAL (#23561)
This commit is contained in:
committed by
GitHub
parent
18c5333a68
commit
cd6549748b
@@ -15,6 +15,11 @@ from contentstore.tests.utils import CourseTestCase
|
||||
from contentstore.utils import reverse_course_url
|
||||
from contentstore.views.transcript_settings import TranscriptionProviderErrorType, validate_transcript_credentials
|
||||
from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file
|
||||
from openedx.core.djangoapps.video_pipeline.config.waffle import (
|
||||
SAVE_CREDENTIALS_IN_VAL,
|
||||
waffle_flags
|
||||
)
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
from student.roles import CourseStaffRole
|
||||
|
||||
|
||||
@@ -108,6 +113,56 @@ class TranscriptCredentialsTest(CourseTestCase):
|
||||
self.assertEqual(response.status_code, expected_status_code)
|
||||
self.assertEqual(response.content.decode('utf-8'), expected_response)
|
||||
|
||||
@override_waffle_flag(waffle_flags()[SAVE_CREDENTIALS_IN_VAL], True)
|
||||
@ddt.data(
|
||||
(
|
||||
{
|
||||
'provider': '3PlayMedia',
|
||||
'api_key': '11111',
|
||||
'api_secret_key': '44444'
|
||||
},
|
||||
{'error_type': TranscriptionProviderErrorType.INVALID_CREDENTIALS},
|
||||
400,
|
||||
'{\n "error": "The information you entered is incorrect."\n}'
|
||||
),
|
||||
(
|
||||
{
|
||||
'provider': 'Cielo24',
|
||||
'api_key': '12345',
|
||||
'username': 'test_user'
|
||||
},
|
||||
{'error_type': None},
|
||||
200,
|
||||
''
|
||||
),
|
||||
(
|
||||
{
|
||||
'provider': '3PlayMedia',
|
||||
'api_key': '12345',
|
||||
'api_secret_key': '44444'
|
||||
},
|
||||
{'error_type': None},
|
||||
200,
|
||||
''
|
||||
)
|
||||
)
|
||||
@ddt.unpack
|
||||
@patch('edxval.api.create_or_update_transcript_credentials')
|
||||
def test_val_transcript_credentials_handler(self, request_payload, update_credentials_response,
|
||||
expected_status_code, expected_response, api_patch):
|
||||
"""
|
||||
Test that credentials handler works fine with VAL api endpoint.
|
||||
"""
|
||||
api_patch.return_value = update_credentials_response
|
||||
transcript_credentials_url = self.get_url_for_course_key(self.course.id)
|
||||
response = self.client.post(
|
||||
transcript_credentials_url,
|
||||
data=json.dumps(request_payload),
|
||||
content_type='application/json'
|
||||
)
|
||||
self.assertEqual(response.status_code, expected_status_code)
|
||||
self.assertEqual(response.content.decode('utf-8'), expected_response)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TranscriptCredentialsValidationTest(TestCase):
|
||||
|
||||
@@ -23,6 +23,10 @@ from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from contentstore.views.videos import TranscriptProvider
|
||||
from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag
|
||||
from openedx.core.djangoapps.video_pipeline.config.waffle import (
|
||||
SAVE_CREDENTIALS_IN_VAL,
|
||||
waffle_flags
|
||||
)
|
||||
from openedx.core.djangoapps.video_pipeline.api import update_3rd_party_transcription_service_credentials
|
||||
from student.auth import has_studio_write_access
|
||||
from util.json_request import JsonResponse, expect_json
|
||||
@@ -110,7 +114,12 @@ def transcript_credentials_handler(request, course_key_string):
|
||||
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)
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user