def test_remove_transcript_preferences(self): """ Test that transcript handler removes transcript preferences correctly. """ # First add course wide transcript preferences. preferences = create_or_update_transcript_preferences( unicode(self.course.id)) # Verify transcript preferences exist self.assertIsNotNone(preferences) response = self.client.delete(self.get_url_for_course_key( self.course.id), content_type='application/json') self.assertEqual(response.status_code, 204) # Verify transcript preferences no loger exist preferences = get_transcript_preferences(unicode(self.course.id)) self.assertIsNone(preferences)
def test_remove_transcript_preferences(self): """ Test that transcript handler removes transcript preferences correctly. """ # First add course wide transcript preferences. preferences = create_or_update_transcript_preferences(unicode(self.course.id)) # Verify transcript preferences exist self.assertIsNotNone(preferences) response = self.client.delete( self.get_url_for_course_key(self.course.id), content_type='application/json' ) self.assertEqual(response.status_code, 204) # Verify transcript preferences no loger exist preferences = get_transcript_preferences(unicode(self.course.id)) self.assertIsNone(preferences)
def transcript_preferences_handler(request, course_key_string): """ JSON view handler to post the transcript preferences. Arguments: request: WSGI request object course_key_string: string for course key Returns: valid json response or 400 with error message """ course_key = CourseKey.from_string(course_key_string) is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled( course_key) if not is_video_transcript_enabled: return HttpResponseNotFound() if request.method == 'POST': data = request.json provider = data.get('provider') error, preferences = validate_transcript_preferences( provider=provider, cielo24_fidelity=data.get('cielo24_fidelity', ''), cielo24_turnaround=data.get('cielo24_turnaround', ''), three_play_turnaround=data.get('three_play_turnaround', ''), video_source_language=data.get('video_source_language'), preferred_languages=list( map(str, data.get('preferred_languages', [])))) if error: response = JsonResponse({'error': error}, status=400) else: preferences.update({'provider': provider}) transcript_preferences = create_or_update_transcript_preferences( course_key_string, **preferences) response = JsonResponse( {'transcript_preferences': transcript_preferences}, status=200) return response elif request.method == 'DELETE': remove_transcript_preferences(course_key_string) return JsonResponse()
def transcript_preferences_handler(request, course_key_string): """ JSON view handler to post the transcript preferences. Arguments: request: WSGI request object course_key_string: string for course key Returns: valid json response or 400 with error message """ course_key = CourseKey.from_string(course_key_string) is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(course_key) if not is_video_transcript_enabled: return HttpResponseNotFound() if request.method == 'POST': data = request.json provider = data.get('provider') error, preferences = validate_transcript_preferences( provider=provider, cielo24_fidelity=data.get('cielo24_fidelity', ''), cielo24_turnaround=data.get('cielo24_turnaround', ''), three_play_turnaround=data.get('three_play_turnaround', ''), video_source_language=data.get('video_source_language'), preferred_languages=data.get('preferred_languages', []) ) if error: response = JsonResponse({'error': error}, status=400) else: preferences.update({'provider': provider}) transcript_preferences = create_or_update_transcript_preferences(course_key_string, **preferences) response = JsonResponse({'transcript_preferences': transcript_preferences}, status=200) return response elif request.method == 'DELETE': remove_transcript_preferences(course_key_string) return JsonResponse()