Commit 65349b38 by Dave St.Germain

Move course video and youtube video lookups to query strings on /videos/

parent 14fb480a
...@@ -325,6 +325,10 @@ class VideoListTest(APIAuthTestCase): ...@@ -325,6 +325,10 @@ class VideoListTest(APIAuthTestCase):
Profile.objects.create(**constants.PROFILE_DICT_DESKTOP) Profile.objects.create(**constants.PROFILE_DICT_DESKTOP)
super(VideoListTest, self).setUp() super(VideoListTest, self).setUp()
def tearDown(self):
super(VideoListTest, self).tearDown()
Video.objects.all().delete()
# Tests for successful POST 201 requests. # Tests for successful POST 201 requests.
def test_complete_set_two_encoded_video_post(self): def test_complete_set_two_encoded_video_post(self):
""" """
...@@ -494,12 +498,12 @@ class VideoListTest(APIAuthTestCase): ...@@ -494,12 +498,12 @@ class VideoListTest(APIAuthTestCase):
self.assertEqual(len(videos), 1) self.assertEqual(len(videos), 1)
self.assertEqual(videos[0]['courses'], [course1, course2]) self.assertEqual(videos[0]['courses'], [course1, course2])
url = reverse('course-video-list', kwargs={'course_id': course1}) url = reverse('video-list') + '?course=%s' % course1
videos = self.client.get(url).data videos = self.client.get(url).data
self.assertEqual(len(videos), 1) self.assertEqual(len(videos), 1)
self.assertEqual(videos[0]['edx_video_id'], constants.VIDEO_DICT_ANIMAL['edx_video_id']) self.assertEqual(videos[0]['edx_video_id'], constants.VIDEO_DICT_ANIMAL['edx_video_id'])
url = reverse('course-video-list', kwargs={'course_id': 'animals/fish/salmon'}) url = reverse('video-list') + '?course=animals/fish/salmon'
response = self.client.get(url).data response = self.client.get(url).data
self.assertEqual(len(response), 0) self.assertEqual(len(response), 0)
...@@ -527,7 +531,7 @@ class VideoListTest(APIAuthTestCase): ...@@ -527,7 +531,7 @@ class VideoListTest(APIAuthTestCase):
self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# now look up the vid by youtube id # now look up the vid by youtube id
url = reverse('youtube-video-list', kwargs={'youtube_id': 'AbcDef'}) url = reverse('video-list') + '?youtube=AbcDef'
response = self.client.get(url).data response = self.client.get(url).data
self.assertEqual(len(response), 1) self.assertEqual(len(response), 1)
self.assertEqual(response[0]['edx_video_id'], video['edx_video_id']) self.assertEqual(response[0]['edx_video_id'], video['edx_video_id'])
......
...@@ -29,15 +29,4 @@ urlpatterns = patterns( ...@@ -29,15 +29,4 @@ urlpatterns = patterns(
views.get_subtitle, views.get_subtitle,
name="subtitle-content" name="subtitle-content"
), ),
url(
r'^courses/{}$'.format(settings.COURSE_ID_PATTERN),
views.CourseVideoList.as_view(),
name="course-video-list"
),
url(
r'^youtube/(?P<youtube_id>[-_\w]+)$',
views.YoutubeVideoList.as_view(),
name="youtube-video-list"
),
) )
...@@ -58,32 +58,19 @@ class VideoList(generics.ListCreateAPIView): ...@@ -58,32 +58,19 @@ class VideoList(generics.ListCreateAPIView):
lookup_field = "edx_video_id" lookup_field = "edx_video_id"
serializer_class = VideoSerializer serializer_class = VideoSerializer
class CourseVideoList(generics.ListAPIView):
"""
GET a list of videos for a course
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication)
permission_classes = (ReadRestrictedDjangoModelPermissions,)
queryset = Video.objects.all().prefetch_related("encoded_videos")
lookup_field = "course_id"
serializer_class = VideoSerializer
def get_queryset(self):
return self.queryset.filter(courses__course_id=self.kwargs['course_id'])
class YoutubeVideoList(generics.ListAPIView):
"""
Get a list of videos for the given youtube id
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication)
permission_classes = (ReadRestrictedDjangoModelPermissions,)
serializer_class = VideoSerializer
queryset = Video.objects.all()
def get_queryset(self): def get_queryset(self):
return Video.by_youtube_id(self.kwargs['youtube_id']) qset = Video.objects.all().prefetch_related("encoded_videos", "courses")
args = self.request.GET
course_id = args.get('course')
if course_id:
# view videos by course id
qset = qset.filter(courses__course_id=course_id)
youtube_id = args.get('youtube')
if youtube_id:
# view videos by youtube id
qset = qset & Video.by_youtube_id(youtube_id)
return qset
class ProfileList(generics.ListCreateAPIView): class ProfileList(generics.ListCreateAPIView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment