Commit ea9c5408 by christopher lee

Implemented new api for rerunning a course

Takes the videos of an old course id and then adds the new course
id to those videos.
parent f4b3441f
......@@ -6,4 +6,5 @@ include = edxval/*
omit =
**/__init__.py
**/tests/*
**/settings.py
\ No newline at end of file
**/settings.py
**/migrations*
......@@ -6,7 +6,7 @@ The internal API for VAL. This is not yet stable
from enum import Enum
import logging
from edxval.models import Video, EncodedVideo
from edxval.models import Video, EncodedVideo, CourseVideo
from edxval.serializers import VideoSerializer, ProfileSerializer
logger = logging.getLogger(__name__) # pylint: disable=C0103
......@@ -93,6 +93,7 @@ def create_video(video_data):
extension: 3 letter extension of video
width: horizontal pixel resolution
height: vertical pixel resolution
courses: Courses associated with this video
}
"""
serializer = VideoSerializer(data=video_data)
......@@ -119,7 +120,7 @@ def create_profile(profile_data):
}
Returns:
new_object.id (int): id of the newly created object
(int): id of the newly created object
Raises:
ValCannotCreateError: Raised if the serializer throws an error
......@@ -141,7 +142,7 @@ def get_video_info(edx_video_id, location=None): # pylint: disable=W0613
edx_video_id (str): id for video content.
Returns:
result (dict): Deserialized Video Object with related field EncodedVideo
(dict): Deserialized Video Object with related field EncodedVideo
Returns all the Video object fields, and it's related EncodedVideo
objects in a list.
{
......@@ -180,7 +181,7 @@ def get_video_info(edx_video_id, location=None): # pylint: disable=W0613
'client_video_id': u'The example video',
'encoded_videos': [
{
'url': u'http://www.meowmix.com',
'url': u'http://www.example.com',
'file_size': 25556,
'bitrate': 9600,
'profile': u'mobile'
......@@ -212,7 +213,7 @@ def get_urls_for_profiles(edx_video_id, profiles):
profiles (list): list of profiles we want to search for
Returns:
profiles_to_urls (dict): A dict containing the profile to url pair
(dict): A dict containing the profile to url pair
"""
profiles_to_urls = {profile: None for profile in profiles}
try:
......@@ -236,7 +237,7 @@ def get_url_for_profile(edx_video_id, profile):
profile (str): a string of the profile we are searching
Returns:
A string with the url
(str): A string with the url
"""
return get_urls_for_profiles(edx_video_id, [profile])[profile]
......@@ -279,10 +280,55 @@ def get_videos_for_ids(
def get_video_info_for_course_and_profile(course_id, profile_name):
"""
Returns a dict mapping profiles to URLs.
Returns a dict of edx_video_ids with a dict of requested profiles.
If the profiles or video is not found, urls will be blank.
Args:
course_id (str): id of the course
profiles (list): list of profile_names
Returns:
(dict): Returns all the profiles attached to a specific
edx_video_id
{
edx_video_id: {
profile_name: {
'url': url of the encoding
'duration': length of the video in seconds
'file_size': size of the file in bytes
},
},
}
Example:
Given two videos with two profiles each in course_id 'test_course':
{
u'edx_video_id_1': {
u'mobile': {
'url': u'http: //www.example.com/meow',
'duration': 1111,
'file_size': 2222
},
u'desktop': {
'url': u'http: //www.example.com/woof',
'duration': 3333,
'file_size': 4444
}
},
u'edx_video_id_2': {
u'mobile': {
'url': u'http: //www.example.com/roar',
'duration': 5555,
'file_size': 6666
},
u'desktop': {
'url': u'http: //www.example.com/bzzz',
'duration': 7777,
'file_size': 8888
}
}
}
"""
#TODO This function needs unit tests. Write them when addressing MA-169
# In case someone passes in a key (VAL doesn't really understand opaque keys)
course_id = unicode(course_id)
try:
......@@ -304,3 +350,28 @@ def get_video_info_for_course_and_profile(course_id, profile_name):
}
for enc_vid in encoded_videos
}
def copy_course_videos(old_course_id, new_course_id):
"""
Adds the new_course_id to the videos taken from the old_course_id
Args:
old_course_id: The original course_id
new_course_id: The new course_id of the rerun
"""
if old_course_id == new_course_id:
raise ValueError(
"Both course_id's are the same: {}".format(new_course_id)
)
if Video.objects.filter(courses__course_id=unicode(new_course_id)):
raise ValCannotCreateError(
"New course id already exists: {}".format(new_course_id)
)
videos = Video.objects.filter(courses__course_id=unicode(old_course_id))
for video in videos:
CourseVideo.objects.create(
video=video,
course_id=new_course_id
)
......@@ -30,13 +30,33 @@ Encoded_videos for test_api, does not have profile.
"""
ENCODED_VIDEO_DICT_MOBILE = dict(
url="http://www.meowmix.com",
file_size=4545,
bitrate=6767,
file_size=11,
bitrate=22,
)
ENCODED_VIDEO_DICT_DESKTOP = dict(
url="http://www.meowmagic.com",
file_size=1212,
bitrate=2323,
file_size=33,
bitrate=44,
)
ENCODED_VIDEO_DICT_MOBILE2 = dict(
url="http://www.woof.com",
file_size=55,
bitrate=66,
)
ENCODED_VIDEO_DICT_DESKTOP2 = dict(
url="http://www.bark.com",
file_size=77,
bitrate=88,
)
ENCODED_VIDEO_DICT_MOBILE3 = dict(
url="http://www.ssss.com",
file_size=1111,
bitrate=2222,
)
ENCODED_VIDEO_DICT_DESKTOP3 = dict(
url="http://www.hiss.com",
file_size=3333,
bitrate=4444,
)
"""
Validators
......@@ -322,6 +342,18 @@ COMPLETE_SET_EXTRA_VIDEO_FIELD = dict(
"""
Other
"""
VIDEO_DICT_TREE = dict(
client_video_id="Trees4lyfe",
duration=532.00,
edx_video_id="tree-hugger",
status="test",
)
VIDEO_DICT_PLANT = dict(
client_video_id="PlantzRule",
duration=876.00,
edx_video_id="fernmaster",
status="test",
)
VIDEO_DICT_ZEBRA = dict(
client_video_id="Zesty Zebra",
duration=111.00,
......
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