diff --git a/edxval/api.py b/edxval/api.py index 363a8ad5..67399b48 100644 --- a/edxval/api.py +++ b/edxval/api.py @@ -733,6 +733,18 @@ def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc ) +def get_course_videos_qset(course_id): + """ + Get a QuerySet of CourseVideos for a given course. + + This assumes that the caller can further filter as necessary. + """ + return CourseVideo.objects.select_related('video').filter( + course_id=str(course_id), + is_hidden=False, + ) + + def get_transcript_details_for_course(course_id): """ Get all the transcripts for a course and return details. diff --git a/edxval/tests/test_api.py b/edxval/tests/test_api.py index 75e2eb2e..f440d692 100644 --- a/edxval/tests/test_api.py +++ b/edxval/tests/test_api.py @@ -761,6 +761,13 @@ def test_get_video_ids_for_course_no_course_videos(self): self.assertEqual(len(course_transcript), 0) + def test_get_course_videos_qset(self): + """Test getting a minimal queryset.""" + with self.assertNumQueries(1): + course_videos_qset = api.get_course_videos_qset(self.course_id) + course_video = course_videos_qset.get(video__edx_video_id="super-soaker") + self.assertEqual(course_video.video.client_video_id, "Shallow Swordfish") + @ddt class GetYouTubeProfileVideosTest(TestCase):