diff --git a/edxval/__init__.py b/edxval/__init__.py index 3b310695..ef90434f 100644 --- a/edxval/__init__.py +++ b/edxval/__init__.py @@ -2,4 +2,4 @@ init """ -__version__ = '2.4.3' +__version__ = '2.4.4' diff --git a/edxval/api.py b/edxval/api.py index ad25090a..978c5f47 100644 --- a/edxval/api.py +++ b/edxval/api.py @@ -778,6 +778,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): """ Soft deletes video for particular course. diff --git a/edxval/tests/test_api.py b/edxval/tests/test_api.py index 12c88a11..5165098d 100644 --- a/edxval/tests/test_api.py +++ b/edxval/tests/test_api.py @@ -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): diff --git a/edxval/tests/test_views.py b/edxval/tests/test_views.py index 2e89402f..1c2bda2d 100644 --- a/edxval/tests/test_views.py +++ b/edxval/tests/test_views.py @@ -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) diff --git a/edxval/urls.py b/edxval/urls.py index e020ebd0..97a05d18 100644 --- a/edxval/urls.py +++ b/edxval/urls.py @@ -28,6 +28,9 @@ path('videos/video-images/update/', views.VideoImagesView.as_view(), name='update-video-images' ), + path('videos/courses//video-ids', views.CourseVideoIDsView.as_view(), + name='course-video-ids' + ), ] if getattr(settings, 'PROVIDER_STATES_SETUP_VIEW_URL', None): diff --git a/edxval/views.py b/edxval/views.py index 1d5584d1..167e224d 100644 --- a/edxval/views.py +++ b/edxval/views.py @@ -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, @@ -192,6 +192,20 @@ 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. + """ + 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.