Commit 5900b349 by Qubad786 Committed by muzaffaryousaf

Backend changes for video source language in transcript preferences.

parent 9c06bb65
...@@ -889,6 +889,18 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -889,6 +889,18 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
VIEW_NAME = 'transcript_preferences_handler' VIEW_NAME = 'transcript_preferences_handler'
def test_405_with_not_allowed_request_method(self):
"""
Verify that 405 is returned in case of not-allowed request methods.
Allowed request methods are POST and DELETE.
"""
video_transcript_url = self.get_url_for_course_key(self.course.id)
response = self.client.get(
video_transcript_url,
content_type='application/json'
)
self.assertEqual(response.status_code, 405)
@ddt.data( @ddt.data(
# Video transcript feature disabled # Video transcript feature disabled
( (
...@@ -901,7 +913,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -901,7 +913,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
( (
{}, {},
True, True,
'Invalid provider.', u"Invalid provider None.",
400 400
), ),
( (
...@@ -909,7 +921,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -909,7 +921,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'provider': '' 'provider': ''
}, },
True, True,
'Invalid provider.', u"Invalid provider .",
400 400
), ),
( (
...@@ -917,7 +929,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -917,7 +929,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'provider': 'dummy-provider' 'provider': 'dummy-provider'
}, },
True, True,
'Invalid provider.', u"Invalid provider dummy-provider.",
400 400
), ),
( (
...@@ -925,7 +937,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -925,7 +937,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'provider': TranscriptProvider.CIELO24 'provider': TranscriptProvider.CIELO24
}, },
True, True,
'Invalid cielo24 fidelity.', u"Invalid cielo24 fidelity None.",
400 400
), ),
( (
...@@ -934,7 +946,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -934,7 +946,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'cielo24_fidelity': 'PROFESSIONAL', 'cielo24_fidelity': 'PROFESSIONAL',
}, },
True, True,
'Invalid cielo24 turnaround.', u"Invalid cielo24 turnaround None.",
400 400
), ),
( (
...@@ -944,7 +956,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -944,7 +956,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'cielo24_turnaround': 'STANDARD' 'cielo24_turnaround': 'STANDARD'
}, },
True, True,
'Invalid languages.', u"Invalid languages [].",
400 400
), ),
( (
...@@ -955,7 +967,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -955,7 +967,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'preferred_languages': ['es', 'ur'] 'preferred_languages': ['es', 'ur']
}, },
True, True,
'Invalid languages.', u"Invalid languages [u'es', u'ur'].",
400 400
), ),
( (
...@@ -963,26 +975,39 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -963,26 +975,39 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'provider': TranscriptProvider.THREE_PLAY_MEDIA 'provider': TranscriptProvider.THREE_PLAY_MEDIA
}, },
True, True,
'Invalid 3play turnaround.', u"Invalid 3play turnaround None.",
400
),
(
{
'provider': TranscriptProvider.THREE_PLAY_MEDIA,
'three_play_turnaround': 'default',
'video_source_language': 'zh',
},
True,
u"Unsupported source language zh.",
400 400
), ),
( (
{ {
'provider': TranscriptProvider.THREE_PLAY_MEDIA, 'provider': TranscriptProvider.THREE_PLAY_MEDIA,
'three_play_turnaround': 'default' 'three_play_turnaround': 'default',
'video_source_language': 'es',
'preferred_languages': ['es', 'ur']
}, },
True, True,
'Invalid languages.', u"Invalid languages [u'es', u'ur'].",
400 400
), ),
( (
{ {
'provider': TranscriptProvider.THREE_PLAY_MEDIA, 'provider': TranscriptProvider.THREE_PLAY_MEDIA,
'three_play_turnaround': 'default', 'three_play_turnaround': 'default',
'video_source_language': 'en',
'preferred_languages': ['es', 'ur'] 'preferred_languages': ['es', 'ur']
}, },
True, True,
'Invalid languages.', u"Invalid languages [u'es', u'ur'].",
400 400
), ),
# Success # Success
...@@ -1002,7 +1027,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase): ...@@ -1002,7 +1027,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
'provider': TranscriptProvider.THREE_PLAY_MEDIA, 'provider': TranscriptProvider.THREE_PLAY_MEDIA,
'three_play_turnaround': 'default', 'three_play_turnaround': 'default',
'preferred_languages': ['en'], 'preferred_languages': ['en'],
'video_source_language': None, # TODO change this once we support source language in platform. 'video_source_language': 'en',
}, },
True, True,
'', '',
......
...@@ -256,9 +256,8 @@ def video_images_handler(request, course_key_string, edx_video_id=None): ...@@ -256,9 +256,8 @@ def video_images_handler(request, course_key_string, edx_video_id=None):
return JsonResponse({'image_url': image_url}) return JsonResponse({'image_url': image_url})
def validate_transcript_preferences( def validate_transcript_preferences(provider, cielo24_fidelity, cielo24_turnaround,
provider, cielo24_fidelity, cielo24_turnaround, three_play_turnaround, preferred_languages three_play_turnaround, video_source_language, preferred_languages):
):
""" """
Validate 3rd Party Transcription Preferences. Validate 3rd Party Transcription Preferences.
...@@ -267,6 +266,7 @@ def validate_transcript_preferences( ...@@ -267,6 +266,7 @@ def validate_transcript_preferences(
cielo24_fidelity: Cielo24 transcription fidelity. cielo24_fidelity: Cielo24 transcription fidelity.
cielo24_turnaround: Cielo24 transcription turnaround. cielo24_turnaround: Cielo24 transcription turnaround.
three_play_turnaround: 3PlayMedia transcription turnaround. three_play_turnaround: 3PlayMedia transcription turnaround.
video_source_language: Source/Speech language of the videos that are going to be submitted to 3PlayMedia.
preferred_languages: list of language codes. preferred_languages: list of language codes.
Returns: Returns:
...@@ -286,43 +286,49 @@ def validate_transcript_preferences( ...@@ -286,43 +286,49 @@ def validate_transcript_preferences(
# Validate transcription turnaround # Validate transcription turnaround
if cielo24_turnaround not in transcription_plans[provider]['turnaround']: if cielo24_turnaround not in transcription_plans[provider]['turnaround']:
error = _('Invalid cielo24 turnaround.') error = 'Invalid cielo24 turnaround {}.'.format(cielo24_turnaround)
return error, preferences return error, preferences
# Validate transcription languages # Validate transcription languages
supported_languages = transcription_plans[provider]['fidelity'][cielo24_fidelity]['languages'] supported_languages = transcription_plans[provider]['fidelity'][cielo24_fidelity]['languages']
if not len(preferred_languages) or not (set(preferred_languages) <= set(supported_languages.keys())): if not len(preferred_languages) or not (set(preferred_languages) <= set(supported_languages.keys())):
error = _('Invalid languages.') error = 'Invalid languages {}.'.format(preferred_languages)
return error, preferences return error, preferences
# Validated Cielo24 preferences # Validated Cielo24 preferences
preferences = { preferences = {
'cielo24_fidelity': cielo24_fidelity, 'cielo24_fidelity': cielo24_fidelity,
'cielo24_turnaround': cielo24_turnaround, 'cielo24_turnaround': cielo24_turnaround,
'preferred_languages': list(preferred_languages), 'preferred_languages': preferred_languages,
} }
else: else:
error = _('Invalid cielo24 fidelity.') error = 'Invalid cielo24 fidelity {}.'.format(cielo24_fidelity)
elif provider == TranscriptProvider.THREE_PLAY_MEDIA: elif provider == TranscriptProvider.THREE_PLAY_MEDIA:
# Validate transcription turnaround # Validate transcription turnaround
if three_play_turnaround not in transcription_plans[provider]['turnaround']: if three_play_turnaround not in transcription_plans[provider]['turnaround']:
error = _('Invalid 3play turnaround.') error = 'Invalid 3play turnaround {}.'.format(three_play_turnaround)
return error, preferences return error, preferences
# Validate transcription languages # Validate transcription languages
supported_languages = transcription_plans[provider]['languages'] valid_translations_map = transcription_plans[provider]['translations']
if not len(preferred_languages) or not (set(preferred_languages) <= set(supported_languages.keys())): if video_source_language not in valid_translations_map.keys():
error = _('Invalid languages.') error = 'Unsupported source language {}.'.format(video_source_language)
return error, preferences
valid_target_languages = valid_translations_map[video_source_language]
if not len(preferred_languages) or not (set(preferred_languages) <= set(valid_target_languages)):
error = 'Invalid languages {}.'.format(preferred_languages)
return error, preferences return error, preferences
# Validated 3PlayMedia preferences # Validated 3PlayMedia preferences
preferences = { preferences = {
'three_play_turnaround': three_play_turnaround, 'three_play_turnaround': three_play_turnaround,
'preferred_languages': list(preferred_languages), 'video_source_language': video_source_language,
'preferred_languages': preferred_languages,
} }
else: else:
error = _('Invalid provider.') error = 'Invalid provider {}.'.format(provider)
return error, preferences return error, preferences
...@@ -353,6 +359,7 @@ def transcript_preferences_handler(request, course_key_string): ...@@ -353,6 +359,7 @@ def transcript_preferences_handler(request, course_key_string):
cielo24_fidelity=data.get('cielo24_fidelity', ''), cielo24_fidelity=data.get('cielo24_fidelity', ''),
cielo24_turnaround=data.get('cielo24_turnaround', ''), cielo24_turnaround=data.get('cielo24_turnaround', ''),
three_play_turnaround=data.get('three_play_turnaround', ''), three_play_turnaround=data.get('three_play_turnaround', ''),
video_source_language=data.get('video_source_language'),
preferred_languages=data.get('preferred_languages', []) preferred_languages=data.get('preferred_languages', [])
) )
if error: if error:
...@@ -361,11 +368,11 @@ def transcript_preferences_handler(request, course_key_string): ...@@ -361,11 +368,11 @@ def transcript_preferences_handler(request, course_key_string):
preferences.update({'provider': provider}) preferences.update({'provider': provider})
transcript_preferences = create_or_update_transcript_preferences(course_key_string, **preferences) transcript_preferences = create_or_update_transcript_preferences(course_key_string, **preferences)
response = JsonResponse({'transcript_preferences': transcript_preferences}, status=200) response = JsonResponse({'transcript_preferences': transcript_preferences}, status=200)
return response
elif request.method == 'DELETE': elif request.method == 'DELETE':
remove_transcript_preferences(course_key_string) remove_transcript_preferences(course_key_string)
response = JsonResponse() return JsonResponse()
return response
@login_required @login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment