From 36b6bec0832d3198e4df04627cbe200ca8dd32bd Mon Sep 17 00:00:00 2001 From: Syed Muhammad Dawoud Sheraz Ali <40599381+DawoudSheraz@users.noreply.github.com> Date: Thu, 2 Apr 2020 10:41:06 +0500 Subject: [PATCH] add transcript credentials fetch endpoint (#211) --- edxval/tests/test_views.py | 60 ++++++++++++++++++++++++++++++++++++++ edxval/urls.py | 6 ++++ edxval/views.py | 40 ++++++++++++++++++++++++- setup.py | 2 +- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/edxval/tests/test_views.py b/edxval/tests/test_views.py index 003b8625..1b37f358 100644 --- a/edxval/tests/test_views.py +++ b/edxval/tests/test_views.py @@ -14,6 +14,7 @@ EncodedVideo, Profile, TranscriptCredentials, + TranscriptPreference, TranscriptProviderType, Video, VideoTranscript, @@ -1140,3 +1141,62 @@ def test_successful_fetch(self): response = json.loads(response.content.decode('utf-8')) self.assertEqual(response['api_key'], credentials_dict['api_key']) self.assertEqual(response['api_secret_key'], credentials_dict['api_secret']) + + +class TranscriptPreferencesViewTest(APIAuthTestCase): + """ + Test Suite for TranscriptPreference API view. + """ + COURSE_ID = 'edX/DemoX/Demo_Course' + URL_NAME = 'transcript-preferences' + + def setUp(self): + super(TranscriptPreferencesViewTest, self).setUp() + TranscriptPreference.objects.create( + **constants.TRANSCRIPT_PREFERENCES_CIELO24 + ) + + def test_unauthorized_access(self): + """ + Test that if the user is not logged in, the data access is not authorized. + """ + self._logout() + url = reverse(self.URL_NAME, kwargs={'course_id': self.COURSE_ID}) + response = self.client.get(url) + self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) + + def test_forbidden_user_access(self): + """ + Test that if the user is not authorized to get the data, the data access is not allowed. + """ + self._login(unauthorized=True) + url = reverse(self.URL_NAME, kwargs={'course_id': self.COURSE_ID}) + response = self.client.get(url) + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_successful_fetch(self): + """ + Test the preferences are fetched successfully for an existing course. + """ + expected_preferences = constants.TRANSCRIPT_PREFERENCES_CIELO24 + expected_preferences['three_play_turnaround'] = None + + url = reverse(self.URL_NAME, kwargs={'course_id': self.COURSE_ID}) + response = self.client.get(url) + self.assertEqual(response.status_code, status.HTTP_200_OK) + response = json.loads(response.content.decode('utf-8')) + # modified is added by serializer and doesn't affect the actual data + response.pop('modified') + + self.assertDictEqual(response, constants.TRANSCRIPT_PREFERENCES_CIELO24) + + def test_non_existant_pref_fetch(self): + """ + Verify that preferences aren't fetched against a non-existant course id. + """ + expected_response = {"detail": "Not found."} + url = reverse(self.URL_NAME, kwargs={'course_id': self.COURSE_ID+'abc'}) + response = self.client.get(url) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + response = json.loads(response.content.decode('utf-8')) + self.assertDictEqual(response, expected_response) diff --git a/edxval/urls.py b/edxval/urls.py index de201d78..d5a272a9 100644 --- a/edxval/urls.py +++ b/edxval/urls.py @@ -4,6 +4,7 @@ from __future__ import absolute_import +from django.conf import settings from django.conf.urls import url from edxval import views @@ -39,5 +40,10 @@ r'^videos/transcript-credentials/(?P[\w]*)/(?P[\w]*)$', views.TranscriptCredentialsView.as_view(), name='transcript-credentials' + ), + url( + r'^videos/transcript-preferences/{}$'.format(settings.COURSE_ID_PATTERN), + views.TranscriptPreferenceView.as_view(), + name='transcript-preferences' ) ] diff --git a/edxval/views.py b/edxval/views.py index bfde9693..bf9a42a1 100644 --- a/edxval/views.py +++ b/edxval/views.py @@ -22,12 +22,13 @@ EncodedVideo, Profile, TranscriptCredentials, + TranscriptPreference, TranscriptProviderType, Video, VideoImage, VideoTranscript, ) -from edxval.serializers import VideoSerializer +from edxval.serializers import TranscriptPreferenceSerializer, VideoSerializer from edxval.utils import TranscriptFormat, validate_generated_images, validate_request_params LOGGER = logging.getLogger(__name__) @@ -439,3 +440,40 @@ def get(self, request, provider, org): )} return Response(status=status_code, data=data) + + +class TranscriptPreferenceView(generics.RetrieveAPIView): + """ + Retrieves the transcript preferences for a given course. + + **Example requests** + + GET api/val/v0/videos/transcript-preferences/{course_id} + + **Parameters** + + * course_id(str): course whose preferences are to be fetched + + **Response Values** + + * course_id(str): course id whose preferences are fetched + + * provider(str): transcript provider name + + * cielo24_fidelity(str/None): Cielo24 fidelity choice + + * cielo24_turnaround(str/None): Cielo24 turnaround time choice + + * three_play_turnaround(str/None): 3playMedia turnaround + + * preferred_languages(list): list of languages(str values) + + * video_source_language(str): video language + + * modified(datetime): last modified date + """ + authentication_classes = (JwtAuthentication, SessionAuthentication) + permission_classes = (ReadRestrictedDjangoModelPermissions,) + lookup_field = "course_id" + queryset = TranscriptPreference.objects.all() + serializer_class = TranscriptPreferenceSerializer diff --git a/setup.py b/setup.py index 931bd03f..d52c60e4 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ def load_requirements(*requirements_paths): return list(requirements) -VERSION = '1.2.7' +VERSION = '1.2.8' if sys.argv[-1] == 'tag': print("Tagging the version on github:")