Skip to content

Commit

Permalink
add transcript credentials fetch endpoint (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
DawoudSheraz authored Apr 2, 2020
1 parent dfe5c54 commit 36b6bec
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
60 changes: 60 additions & 0 deletions edxval/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
EncodedVideo,
Profile,
TranscriptCredentials,
TranscriptPreference,
TranscriptProviderType,
Video,
VideoTranscript,
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions edxval/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import absolute_import

from django.conf import settings
from django.conf.urls import url

from edxval import views
Expand Down Expand Up @@ -39,5 +40,10 @@
r'^videos/transcript-credentials/(?P<provider>[\w]*)/(?P<org>[\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'
)
]
40 changes: 39 additions & 1 deletion edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down

0 comments on commit 36b6bec

Please sign in to comment.