Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-val
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-val
Commits
01e9f689
Commit
01e9f689
authored
Sep 18, 2014
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26 from edx/dcs/youtube-lookup
Lookup youtube videos by id
parents
22bef6f9
65349b38
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
18 deletions
+62
-18
edxval/models.py
+14
-1
edxval/tests/test_views.py
+36
-2
edxval/urls.py
+0
-6
edxval/views.py
+12
-9
No files found.
edxval/models.py
View file @
01e9f689
...
@@ -32,7 +32,7 @@ from django.core.validators import MinValueValidator, RegexValidator
...
@@ -32,7 +32,7 @@ from django.core.validators import MinValueValidator, RegexValidator
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
url_regex
=
r'^[a-zA-Z0-9\-]*$'
url_regex
=
r'^[a-zA-Z0-9\-
_
]*$'
class
Profile
(
models
.
Model
):
class
Profile
(
models
.
Model
):
...
@@ -60,6 +60,7 @@ class Profile(models.Model):
...
@@ -60,6 +60,7 @@ class Profile(models.Model):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
profile_name
return
self
.
profile_name
class
Video
(
models
.
Model
):
class
Video
(
models
.
Model
):
"""
"""
Model for a Video group with the same content.
Model for a Video group with the same content.
...
@@ -87,6 +88,18 @@ class Video(models.Model):
...
@@ -87,6 +88,18 @@ class Video(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
edx_video_id
return
self
.
edx_video_id
@classmethod
def
by_youtube_id
(
cls
,
youtube_id
):
"""
Look up video by youtube id
"""
url
=
'://youtu.be/
%
s'
%
youtube_id
qset
=
cls
.
objects
.
filter
(
encoded_videos__profile__profile_name
=
'youtube'
,
encoded_videos__url__endswith
=
url
)
.
prefetch_related
(
'encoded_videos'
,
'courses'
,
'subtitles'
)
return
qset
class
CourseVideo
(
models
.
Model
):
class
CourseVideo
(
models
.
Model
):
"""
"""
...
...
edxval/tests/test_views.py
View file @
01e9f689
...
@@ -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,15 +498,45 @@ class VideoListTest(APIAuthTestCase):
...
@@ -494,15 +498,45 @@ 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
)
def
test_lookup_youtube
(
self
):
"""
Test looking up by youtube id
"""
video
=
{
'edx_video_id'
:
'testing-youtube'
,
'encoded_videos'
:
[
{
'profile'
:
'youtube'
,
'url'
:
'https://youtu.be/AbcDef'
,
'file_size'
:
4545
,
'bitrate'
:
6767
,
}
],
'subtitles'
:
[],
'courses'
:
[
'youtube'
],
'client_video_id'
:
"Funny Cats"
,
'duration'
:
122
}
response
=
self
.
client
.
post
(
reverse
(
'video-list'
),
video
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
# now look up the vid by youtube id
url
=
reverse
(
'video-list'
)
+
'?youtube=AbcDef'
response
=
self
.
client
.
get
(
url
)
.
data
self
.
assertEqual
(
len
(
response
),
1
)
self
.
assertEqual
(
response
[
0
][
'edx_video_id'
],
video
[
'edx_video_id'
])
# Tests for POST queries to database
# Tests for POST queries to database
def
test_queries_for_only_video
(
self
):
def
test_queries_for_only_video
(
self
):
...
...
edxval/urls.py
View file @
01e9f689
...
@@ -29,10 +29,4 @@ urlpatterns = patterns(
...
@@ -29,10 +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"
),
)
)
edxval/views.py
View file @
01e9f689
...
@@ -58,16 +58,19 @@ class VideoList(generics.ListCreateAPIView):
...
@@ -58,16 +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
):
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
):
def
get_queryset
(
self
):
return
self
.
queryset
.
filter
(
courses__course_id
=
self
.
kwargs
[
'course_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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment