test_video_xml.py 3.04 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
# pylint: disable=protected-access
3

4
"""Test for Video Xmodule functional logic.
5
These test data read from xml, not from mongo.
6 7 8 9 10 11 12 13 14 15 16

We have a ModuleStoreTestCase class defined in
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py.
You can search for usages of this in the cms and lms tests for examples.
You use this so that it will do things like point the modulestore
setting to mongo, flush the contentstore before and after, load the
templates, etc.
You can then use the CourseFactory and XModuleItemFactory as defined in
common/lib/xmodule/xmodule/modulestore/tests/factories.py to create the
course, section, subsection, unit, etc.
"""
17
from nose.plugins.attrib import attr
18

19
from xmodule.video_module import VideoDescriptor
Ned Batchelder committed
20
from xmodule.tests import LogicTest
21 22 23


SOURCE_XML = """
24
    <video show_captions="true"
25
    display_name="A Name"
26
    youtube="0.75:jNCf2gIqpeE,1.0:ZwkTiUPN0mg,1.25:rsq9auxASqI,1.50:kMyNdzVHHgg"
27
    sub="a_sub_file.srt.sjson"
28
    download_video="true"
29 30
    start_time="01:00:03" end_time="01:00:10"
    >
31 32
        <source src="example.mp4"/>
        <source src="example.webm"/>
33
        <transcript language="uk" src="ukrainian_translation.srt" />
34
    </video>
35 36 37
"""


38
@attr('shard_1')
39 40
class VideoModuleLogicTest(LogicTest):
    """Tests for logic of Video Xmodule."""
41

42
    descriptor_class = VideoDescriptor
43

Calen Pennington committed
44
    raw_field_data = {
45 46 47 48 49 50
        'data': '<video />'
    }

    def test_parse_youtube(self):
        """Test parsing old-style Youtube ID strings into a dict."""
        youtube_str = '0.75:jNCf2gIqpeE,1.00:ZwkTiUPN0mg,1.25:rsq9auxASqI,1.50:kMyNdzVHHgg'
51
        output = VideoDescriptor._parse_youtube(youtube_str)
52 53 54 55 56 57 58 59 60 61 62
        self.assertEqual(output, {'0.75': 'jNCf2gIqpeE',
                                  '1.00': 'ZwkTiUPN0mg',
                                  '1.25': 'rsq9auxASqI',
                                  '1.50': 'kMyNdzVHHgg'})

    def test_parse_youtube_one_video(self):
        """
        Ensure that all keys are present and missing speeds map to the
        empty string.
        """
        youtube_str = '0.75:jNCf2gIqpeE'
63
        output = VideoDescriptor._parse_youtube(youtube_str)
64 65 66 67 68 69 70 71 72 73 74 75
        self.assertEqual(output, {'0.75': 'jNCf2gIqpeE',
                                  '1.00': '',
                                  '1.25': '',
                                  '1.50': ''})

    def test_parse_youtube_key_format(self):
        """
        Make sure that inconsistent speed keys are parsed correctly.
        """
        youtube_str = '1.00:p2Q6BrNhdh8'
        youtube_str_hack = '1.0:p2Q6BrNhdh8'
        self.assertEqual(
76 77
            VideoDescriptor._parse_youtube(youtube_str),
            VideoDescriptor._parse_youtube(youtube_str_hack)
78 79 80 81 82 83 84
        )

    def test_parse_youtube_empty(self):
        """
        Some courses have empty youtube attributes, so we should handle
        that well.
        """
85
        self.assertEqual(VideoDescriptor._parse_youtube(''),
86 87 88 89
                         {'0.75': '',
                          '1.00': '',
                          '1.25': '',
                          '1.50': ''})