Skip to content

Commit

Permalink
Merge pull request #69 from edx/ammar/tnl-6541-add-hls-profile
Browse files Browse the repository at this point in the history
add hls profile
  • Loading branch information
muhammad-ammar committed Mar 16, 2017
2 parents d260fb6 + 084e246 commit 82d5a13
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 48 deletions.
30 changes: 30 additions & 0 deletions edxval/migrations/0004_data__add_hls_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


HLS_PROFILE = 'hls'


def create_hls_profile(apps, schema_editor):
""" Create hls profile """
Profile = apps.get_model("edxval", "Profile")
Profile.objects.get_or_create(profile_name=HLS_PROFILE)


def delete_hls_profile(apps, schema_editor):
""" Delete hls profile """
Profile = apps.get_model("edxval", "Profile")
Profile.objects.filter(profile_name=HLS_PROFILE).delete()


class Migration(migrations.Migration):

dependencies = [
('edxval', '0003_coursevideo_is_hidden'),
]

operations = [
migrations.RunPython(create_hls_profile, delete_hls_profile),
]
30 changes: 29 additions & 1 deletion edxval/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PROFILE_MOBILE = "mobile"
PROFILE_DESKTOP = "desktop"
PROFILE_YOUTUBE = "youtube"
PROFILE_HLS = 'hls'
"""
Encoded_videos for test_api, does not have profile.
"""
Expand Down Expand Up @@ -43,6 +44,11 @@
file_size=3333,
bitrate=4444,
)
ENCODED_VIDEO_DICT_HLS = dict(
url='https://www.tmnt.com/tmnt101.m3u8',
file_size=100,
bitrate=0
)
"""
Validators
"""
Expand Down Expand Up @@ -150,6 +156,12 @@
bitrate=4222,
profile="desktop",
)
ENCODED_VIDEO_DICT_FISH_HLS = dict(
url='https://www.tmnt.com/tmnt101.m3u8',
file_size=100,
bitrate=100,
profile='hls',
)
ENCODED_VIDEO_DICT_UPDATE_FISH_MOBILE = dict(
url="https://www.fishfellow.com",
file_size=1,
Expand All @@ -162,6 +174,12 @@
bitrate=2,
profile="desktop",
)
ENCODED_VIDEO_DICT_UPDATE_FISH_HLS = dict(
url="https://www.comics.com/flash/intro.m3u8",
file_size=200,
bitrate=200,
profile="hls",
)
ENCODED_VIDEO_DICT_FISH_INVALID_PROFILE = dict(
url="https://www.swordsplints.com",
file_size=1234,
Expand All @@ -176,6 +194,15 @@
subtitles=[SUBTITLE_DICT_SRT, SUBTITLE_DICT_SJSON],
**VIDEO_DICT_FISH
)
COMPLETE_SET_FISH_WITH_HLS = dict(
encoded_videos=[
ENCODED_VIDEO_DICT_FISH_MOBILE,
ENCODED_VIDEO_DICT_FISH_DESKTOP,
ENCODED_VIDEO_DICT_FISH_HLS,
],
subtitles=[SUBTITLE_DICT_SRT, SUBTITLE_DICT_SJSON],
**VIDEO_DICT_FISH
)
COMPLETE_SET_TWO_MOBILE_FISH = dict(
encoded_videos=[
ENCODED_VIDEO_DICT_FISH_MOBILE,
Expand All @@ -187,7 +214,8 @@
COMPLETE_SET_UPDATE_FISH = dict(
encoded_videos=[
ENCODED_VIDEO_DICT_UPDATE_FISH_MOBILE,
ENCODED_VIDEO_DICT_UPDATE_FISH_DESKTOP
ENCODED_VIDEO_DICT_UPDATE_FISH_DESKTOP,
ENCODED_VIDEO_DICT_UPDATE_FISH_HLS,
],
subtitles=[SUBTITLE_DICT_SRT],
**VIDEO_DICT_FISH
Expand Down
72 changes: 63 additions & 9 deletions edxval/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def test_create_video(self):

video_data = dict(
encoded_videos=[
constants.ENCODED_VIDEO_DICT_FISH_MOBILE
constants.ENCODED_VIDEO_DICT_FISH_MOBILE,
constants.ENCODED_VIDEO_DICT_FISH_HLS
],
**constants.VIDEO_DICT_FISH
)
Expand Down Expand Up @@ -198,12 +199,17 @@ def test_create_profile(self):
"""
api.create_profile(constants.PROFILE_DESKTOP)
profiles = list(Profile.objects.all())
self.assertEqual(len(profiles), 6)
profile_names = [unicode(profile) for profile in profiles]
self.assertEqual(len(profiles), 7)
self.assertIn(
constants.PROFILE_DESKTOP,
[unicode(profile) for profile in profiles],
profile_names
)
self.assertIn(
constants.PROFILE_HLS,
profile_names
)
self.assertEqual(len(profiles), 6)
self.assertEqual(len(profiles), 7)

def test_invalid_create_profile(self):
"""
Expand Down Expand Up @@ -240,6 +246,11 @@ def setUp(self):
profile=Profile.objects.get(profile_name="desktop"),
**constants.ENCODED_VIDEO_DICT_DESKTOP
)
EncodedVideo.objects.create(
video=video,
profile=Profile.objects.get(profile_name="hls"),
**constants.ENCODED_VIDEO_DICT_HLS
)
self.course_id = 'test-course'
CourseVideo.objects.create(video=video, course_id=self.course_id)

Expand Down Expand Up @@ -308,19 +319,27 @@ def setUp(self):
profile=Profile.objects.get(profile_name="desktop"),
**constants.ENCODED_VIDEO_DICT_DESKTOP
)
EncodedVideo.objects.create(
video=Video.objects.get(
edx_video_id=constants.VIDEO_DICT_FISH.get("edx_video_id")
),
profile=Profile.objects.get(profile_name="hls"),
**constants.ENCODED_VIDEO_DICT_HLS
)
self.course_id = 'test-course'
CourseVideo.objects.create(video=video, course_id=self.course_id)

def test_get_urls_for_profiles(self):
"""
Tests when the profiles to the video are found
"""
profiles = ["mobile", "desktop"]
profiles = ["mobile", "desktop", 'hls']
edx_video_id = constants.VIDEO_DICT_FISH['edx_video_id']
urls = api.get_urls_for_profiles(edx_video_id, profiles)
self.assertEqual(len(urls), 2)
self.assertEqual(len(urls), 3)
self.assertEqual(urls["mobile"], u'http://www.meowmix.com')
self.assertEqual(urls["desktop"], u'http://www.meowmagic.com')
self.assertEqual(urls["hls"], u'https://www.tmnt.com/tmnt101.m3u8')

def test_get_urls_for_profiles_no_video(self):
"""
Expand Down Expand Up @@ -357,11 +376,12 @@ def setUp(self):
"""
Creates two courses for testing
Creates two videos with 2 encoded videos for the first course, and then
2 videos with 1 encoded video for the second course.
Creates two videos for first course where first video has 3 encodings and second
video has 2 encoding and then 2 videos with 1 encoded video for the second course.
"""
mobile_profile = Profile.objects.create(profile_name=constants.PROFILE_MOBILE)
desktop_profile = Profile.objects.create(profile_name=constants.PROFILE_DESKTOP)
hls_profile = Profile.objects.get(profile_name=constants.PROFILE_HLS)

self.course_id = 'test-course'
# 1st video
Expand All @@ -376,6 +396,11 @@ def setUp(self):
profile=desktop_profile,
**constants.ENCODED_VIDEO_DICT_DESKTOP
)
EncodedVideo.objects.create(
video=video,
profile=hls_profile,
**constants.ENCODED_VIDEO_DICT_HLS
)
CourseVideo.objects.create(video=video, course_id=self.course_id)
# 2nd video
video = Video.objects.create(**constants.VIDEO_DICT_STAR)
Expand Down Expand Up @@ -553,6 +578,24 @@ def test_get_video_for_course_profiles_repeated_profile(self):
))
self.assertEqual(videos, expected_dict)

def test_get_video_for_course_profiles_hls(self):
"""
Tests get_video_info_for_course_and_profiles for hls profile
"""
videos = api.get_video_info_for_course_and_profiles(
self.course_id,
['hls']
)
self.assertEqual(
videos,
self._create_video_dict(
constants.VIDEO_DICT_FISH,
{
constants.PROFILE_HLS: constants.ENCODED_VIDEO_DICT_HLS
}
)
)


class GetVideosForCourseTest(TestCase, SortedVideoTestMixin):
"""
Expand Down Expand Up @@ -814,6 +857,7 @@ class ExportTest(TestCase):
def setUp(self):
mobile_profile = Profile.objects.create(profile_name=constants.PROFILE_MOBILE)
desktop_profile = Profile.objects.create(profile_name=constants.PROFILE_DESKTOP)
hls_profile = Profile.objects.get(profile_name=constants.PROFILE_HLS)
Video.objects.create(**constants.VIDEO_DICT_STAR)
video = Video.objects.create(**constants.VIDEO_DICT_FISH)
EncodedVideo.objects.create(
Expand All @@ -826,6 +870,11 @@ def setUp(self):
profile=desktop_profile,
**constants.ENCODED_VIDEO_DICT_DESKTOP
)
EncodedVideo.objects.create(
video=video,
profile=hls_profile,
**constants.ENCODED_VIDEO_DICT_HLS
)

def assert_xml_equal(self, left, right):
"""
Expand Down Expand Up @@ -861,6 +910,7 @@ def test_basic(self):
<video_asset client_video_id="Shallow Swordfish" duration="122.0">
<encoded_video url="http://www.meowmix.com" file_size="11" bitrate="22" profile="mobile"/>
<encoded_video url="http://www.meowmagic.com" file_size="33" bitrate="44" profile="desktop"/>
<encoded_video url="https://www.tmnt.com/tmnt101.m3u8" file_size="100" bitrate="0" profile="hls"/>
</video_asset>
""")
self.assert_xml_equal(
Expand Down Expand Up @@ -935,7 +985,7 @@ def test_new_video_full(self):

xml = self.make_import_xml(
video_dict=constants.VIDEO_DICT_STAR,
encoded_video_dicts=[constants.ENCODED_VIDEO_DICT_STAR]
encoded_video_dicts=[constants.ENCODED_VIDEO_DICT_STAR, constants.ENCODED_VIDEO_DICT_FISH_HLS]
)
api.import_from_xml(xml, constants.VIDEO_DICT_STAR["edx_video_id"], new_course_id)

Expand All @@ -945,6 +995,10 @@ def test_new_video_full(self):
video.encoded_videos.get(profile__profile_name=constants.PROFILE_MOBILE),
constants.ENCODED_VIDEO_DICT_STAR
)
self.assert_encoded_video_matches_dict(
video.encoded_videos.get(profile__profile_name=constants.PROFILE_HLS),
constants.ENCODED_VIDEO_DICT_FISH_HLS
)
video.courses.get(course_id=new_course_id)

def test_new_video_minimal(self):
Expand Down
9 changes: 7 additions & 2 deletions edxval/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ def test_encoded_video_set_output(self):
profile=Profile.objects.get(profile_name="mobile"),
**constants.ENCODED_VIDEO_DICT_MOBILE
)
EncodedVideo.objects.create(
video=video,
profile=Profile.objects.get(profile_name="hls"),
**constants.ENCODED_VIDEO_DICT_HLS
)
result = VideoSerializer(video).data # pylint: disable=E1101
# Check for 2 EncodedVideo entries
self.assertEqual(len(result.get("encoded_videos")), 2)
# Check for 3 EncodedVideo entries
self.assertEqual(len(result.get("encoded_videos")), 3)
# Check for original Video data
self.assertDictContainsSubset(constants.VIDEO_DICT_FISH, result)

Expand Down
Loading

0 comments on commit 82d5a13

Please sign in to comment.