Skip to content

Commit

Permalink
feat: add endpoint to fetch course video ids
Browse files Browse the repository at this point in the history
  • Loading branch information
hajorg committed Oct 4, 2023
1 parent 0a85bb8 commit 182b1fc
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion edxval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
init
"""

__version__ = '2.4.3'
__version__ = '2.4.4'
15 changes: 15 additions & 0 deletions edxval/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,21 @@ def get_transcript_details_for_course(course_id):

return course_transcripts_data

def get_video_ids_for_course(course_id):
"""
Gets video_ids for a course.
Args:
course_id (String)
Returns:
(list): Returns all the edx_video_id's for a course
"""

course_videos = CourseVideo.objects.filter(course_id=course_id).select_related('video')
video_ids = [cv.video.edx_video_id for cv in course_videos]
return video_ids


def remove_video_for_course(course_id, edx_video_id):
"""
Expand Down
12 changes: 12 additions & 0 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,18 @@ def api_func(_expected_ids, sort_field, sort_direction):
return videos
self.check_sort_params_of_api(api_func)

def test_get_video_ids_for_course(self):

course_transcript = api.get_video_ids_for_course(self.course_id)

self.assertEqual(len(course_transcript), 1)

def test_get_video_ids_for_course_no_course_videos(self):

course_transcript = api.get_video_ids_for_course('this-is-not-a-course-id')

self.assertEqual(len(course_transcript), 0)


@ddt
class GetYouTubeProfileVideosTest(TestCase):
Expand Down
25 changes: 25 additions & 0 deletions edxval/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,3 +1127,28 @@ def test_successful_response(self):
mock_transcript_details.assert_called_once_with(course_id)

self.assertEqual(response.status_code, status.HTTP_200_OK)


class CourseVideoIDsViewTest(APIAuthTestCase):
"""
CourseVideoIDsViewTest Tests.
"""
base_url = 'course-transcripts'

def test_successful_response(self):
"""
Test succesful response from view
"""
with patch(
'edxval.views.get_video_ids_for_course'
) as mock_video_ids:
# Simulate a return value when the function is called.
mock_video_ids.return_value = []
course_id = 'course-v1:edx+1+2023_05'
url = reverse('course-video-ids', args=[course_id])
response = self.client.get(url)

# Verify the function was called once with course_id
mock_video_ids.assert_called_once_with(course_id)

self.assertEqual(response.status_code, status.HTTP_200_OK)
3 changes: 3 additions & 0 deletions edxval/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
path('videos/video-images/update/', views.VideoImagesView.as_view(),
name='update-video-images'
),
path('videos/<str:course_id>/video_ids/', views.CourseVideoIDsView.as_view(),
name='course-video-ids'
),
]

if getattr(settings, 'PROVIDER_STATES_SETUP_VIEW_URL', None):
Expand Down
19 changes: 18 additions & 1 deletion edxval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from edxval.api import create_or_update_video_transcript, get_transcript_details_for_course
from edxval.api import create_or_update_video_transcript, get_transcript_details_for_course, get_video_ids_for_course
from edxval.models import (
LIST_MAX_ITEMS,
CourseVideo,
Expand Down Expand Up @@ -192,6 +192,23 @@ def get(self, _request, course_id):
return Response(status=status.HTTP_200_OK, data=course_data)


class CourseVideoIDsView(APIView):
"""
A view to get video ids related to a course_id.
"""
authentication_classes = (JwtAuthentication, SessionAuthentication)

def get(self, _, course_id):
"""
Returns all video_ids for a course when given a course_id.
"""
if not course_id:
return Response(status=status.HTTP_400_BAD_REQUEST, data={'message': 'course_id param required'})

video_ids = get_video_ids_for_course(course_id)
return Response(status=status.HTTP_200_OK, data=video_ids)


class VideoStatusView(APIView):
"""
A Video View to update the status of a video.
Expand Down

0 comments on commit 182b1fc

Please sign in to comment.