예제 #1
0
    def test_parse_youtube_invalid(self):
        """Ensure that ids that are invalid return an empty dict"""

        # invalid id
        youtube_str = 'thisisaninvalidid'
        output = VideoDescriptor._parse_youtube(youtube_str)
        self.assertEqual(output, {'0.75': '',
                                  '1.00': '',
                                  '1.25': '',
                                  '1.50': ''})
        # another invalid id
        youtube_str = ',::,:,,'
        output = VideoDescriptor._parse_youtube(youtube_str)
        self.assertEqual(output, {'0.75': '',
                                  '1.00': '',
                                  '1.25': '',
                                  '1.50': ''})

        # and another one, partially invalid
        youtube_str = '0.75_BAD!!!,1.0:AXdE34_U,1.25:KLHF9K_Y,1.5:VO3SxfeD,'
        output = VideoDescriptor._parse_youtube(youtube_str)
        self.assertEqual(output, {'0.75': '',
                                  '1.00': 'AXdE34_U',
                                  '1.25': 'KLHF9K_Y',
                                  '1.50': 'VO3SxfeD'})
예제 #2
0
    def test_export_to_xml_empty_parameters(self):
        """Test XML export with defaults."""
        module_system = DummySystem(load_error_modules=True)
        desc = VideoDescriptor(module_system, DictFieldData({}), ScopeIds(None, None, self.location, self.location))

        xml = desc.definition_to_xml(None)
        expected = '<video url_name="SampleProblem1"/>\n'

        self.assertEquals(expected, etree.tostring(xml, pretty_print=True))
예제 #3
0
 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(
         VideoDescriptor._parse_youtube(youtube_str),
         VideoDescriptor._parse_youtube(youtube_str_hack)
     )
예제 #4
0
    def test_export_to_xml_empty_parameters(self):
        """Test XML export with defaults."""
        module_system = DummySystem(load_error_modules=True)
        location = Location(["i4x", "edX", "video", "default", "SampleProblem1"])
        desc = VideoDescriptor(module_system, {'location': location})

        xml = desc.export_to_xml(None)
        expected = '<video url_name="SampleProblem1"/>\n'

        self.assertEquals(expected, xml)
예제 #5
0
    def create():
        """Method return Video Xmodule instance."""
        location = Location(["i4x", "edX", "video", "default",
                             "SampleProblem1"])
        field_data = {'data': VideoFactory.sample_problem_xml_youtube,
                      'location': location}

        system = get_test_descriptor_system()

        descriptor = VideoDescriptor(system, DictFieldData(field_data), ScopeIds(None, None, None, None))
        descriptor.xmodule_runtime = get_test_system()
        return descriptor
예제 #6
0
    def test_import_val_data_invalid(self, mock_val_api):
        mock_val_api.ValCannotCreateError = _MockValCannotCreateError
        mock_val_api.import_from_xml = Mock(side_effect=mock_val_api.ValCannotCreateError)
        module_system = DummySystem(load_error_modules=True)

        # Negative duration is invalid
        xml_data = """
            <video edx_video_id="test_edx_video_id">
                <video_asset client_video_id="test_client_video_id" duration="-1"/>
            </video>
        """
        with self.assertRaises(mock_val_api.ValCannotCreateError):
            VideoDescriptor.from_xml(xml_data, module_system, id_generator=Mock())
예제 #7
0
 def test_create_youtube_string_missing(self):
     """
     Test that Youtube IDs which aren't explicitly set aren't included
     in the output string.
     """
     system = DummySystem(load_error_modules=True)
     location = Location(["i4x", "edX", "video", "default", "SampleProblem1"])
     model_data = {'location': location}
     descriptor = VideoDescriptor(system, model_data)
     descriptor.youtube_id_0_75 = 'izygArpw-Qo'
     descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
     descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
     expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA"
     self.assertEqual(_create_youtube_string(descriptor), expected)
예제 #8
0
 def test_create_youtube_string_missing(self):
     """
     Test that Youtube IDs which aren't explicitly set aren't included
     in the output string.
     """
     system = DummySystem(load_error_modules=True)
     location = Location("edX", 'course', 'run', "video", "SampleProblem1", None)
     field_data = DictFieldData({'location': location})
     descriptor = VideoDescriptor(system, field_data, Mock())
     descriptor.youtube_id_0_75 = 'izygArpw-Qo'
     descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
     descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
     expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA"
     self.assertEqual(create_youtube_string(descriptor), expected)
예제 #9
0
 def test_create_youtube_string(self):
     """
     Test that Youtube ID strings are correctly created when writing
     back out to XML.
     """
     system = DummySystem(load_error_modules=True)
     location = Location("edX", 'course', 'run', "video", 'SampleProblem1', None)
     field_data = DictFieldData({'location': location})
     descriptor = VideoDescriptor(system, field_data, Mock())
     descriptor.youtube_id_0_75 = 'izygArpw-Qo'
     descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
     descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
     descriptor.youtube_id_1_5 = 'rABDYkeK0x8'
     expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"
     self.assertEqual(create_youtube_string(descriptor), expected)
예제 #10
0
 def test_create_youtube_string(self):
     """
     Test that Youtube ID strings are correctly created when writing
     back out to XML.
     """
     system = DummySystem(load_error_modules=True)
     location = Location(["i4x", "edX", "video", "default", "SampleProblem1"])
     model_data = {'location': location}
     descriptor = VideoDescriptor(system, model_data)
     descriptor.youtube_id_0_75 = 'izygArpw-Qo'
     descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
     descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
     descriptor.youtube_id_1_5 = 'rABDYkeK0x8'
     expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"
     self.assertEqual(_create_youtube_string(descriptor), expected)
예제 #11
0
    def create():
        """Method return Video Xmodule instance."""
        location = Location(["i4x", "edX", "video", "default",
                             "SampleProblem1"])
        model_data = {'data': VideoFactory.sample_problem_xml_youtube,
                      'location': location}

        system = get_test_system()
        system.render_template = lambda template, context: context

        descriptor = VideoDescriptor(system, model_data)

        module = descriptor.xmodule(system)

        return module
예제 #12
0
 def test_old_video_format(self):
     """
     Test backwards compatibility with VideoModule's XML format.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = """
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                show_captions="false"
                source="http://www.example.com/source.mp4"
                from="00:00:01"
                to="00:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
         </video>
     """
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': 'izygArpw-Qo',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': 'rABDYkeK0x8',
         'show_captions': False,
         'start_time': datetime.timedelta(seconds=1),
         'end_time': datetime.timedelta(seconds=60),
         'track': 'http://www.example.com/track',
         # 'download_track': True,
         'html5_sources': ['http://www.example.com/source.mp4'],
         'data': '',
     })
예제 #13
0
 def test_from_xml(self):
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                show_captions="false"
                download_track="false"
                start_time="00:00:01"
                download_video="false"
                end_time="00:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
           <handout src="http://www.example.com/handout"/>
           <transcript language="uk" src="ukrainian_translation.srt" />
           <transcript language="de" src="german_translation.srt" />
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': 'izygArpw-Qo',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': 'rABDYkeK0x8',
         'show_captions': False,
         'start_time': datetime.timedelta(seconds=1),
         'end_time': datetime.timedelta(seconds=60),
         'track': 'http://www.example.com/track',
         'handout': 'http://www.example.com/handout',
         'download_track': False,
         'download_video': False,
         'html5_sources': ['http://www.example.com/source.mp4'],
         'data': '',
         'transcripts': {'uk': 'ukrainian_translation.srt', 'de': 'german_translation.srt'},
     })
예제 #14
0
 def test_old_video_data(self):
     """
     Ensure that Video is able to read VideoModule's model data.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = """
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                show_captions="false"
                from="00:00:01"
                to="00:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
         </video>
     """
     video = VideoDescriptor.from_xml(xml_data, module_system)
     self.assert_attributes_equal(video, {
         'youtube_id_0_75': 'izygArpw-Qo',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': 'rABDYkeK0x8',
         'show_captions': False,
         'start_time': 1.0,
         'end_time': 60,
         'track': 'http://www.example.com/track',
         'html5_sources': ['http://www.example.com/source.mp4'],
         'data': ''
     })
예제 #15
0
 def test_from_xml_missing_attributes(self):
     """
     Ensure that attributes have the right values if they aren't
     explicitly set in XML.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,1.25:1EeWXzPdhSA"
                show_captions="true">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': '',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': '',
         'show_captions': True,
         'start_time': 0.0,
         'end_time': 0.0,
         'track': 'http://www.example.com/track',
         'source': 'http://www.example.com/source.mp4',
         'html5_sources': ['http://www.example.com/source.mp4'],
         'data': ''
     })
예제 #16
0
 def test_from_xml(self):
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                show_captions="false"
                start_time="00:00:01"
                end_time="00:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': 'izygArpw-Qo',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': 'rABDYkeK0x8',
         'show_captions': False,
         'start_time': 1.0,
         'end_time': 60,
         'track': 'http://www.example.com/track',
         'source': 'http://www.example.com/source.mp4',
         'html5_sources': ['http://www.example.com/source.mp4'],
         'data': ''
     })
예제 #17
0
    def test_import_val_data_invalid(self):
        create_profile('mobile')
        module_system = DummySystem(load_error_modules=True)

        # Negative file_size is invalid
        xml_data = """
            <video edx_video_id="test_edx_video_id">
                <video_asset client_video_id="test_client_video_id" duration="111.0">
                    <encoded_video profile="mobile" url="http://example.com/video" file_size="-222" bitrate="333"/>
                </video_asset>
            </video>
        """
        with self.assertRaises(ValCannotCreateError):
            VideoDescriptor.from_xml(xml_data, module_system, id_generator=Mock())
        with self.assertRaises(ValVideoNotFoundError):
            get_video_info("test_edx_video_id")
예제 #18
0
 def test_from_xml_double_quotes(self):
     """
     Make sure we can handle the double-quoted string format (which was used for exporting for
     a few weeks).
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="&quot;display_name&quot;"
             html5_sources="[&quot;source_1&quot;, &quot;source_2&quot;]"
             show_captions="false"
             download_video="true"
             sub="&quot;html5_subtitles&quot;"
             track="&quot;http://download_track&quot;"
             download_track="true"
             youtube_id_0_75="&quot;OEoXaMPEzf65&quot;"
             youtube_id_1_25="&quot;OEoXaMPEzf125&quot;"
             youtube_id_1_5="&quot;OEoXaMPEzf15&quot;"
             youtube_id_1_0="&quot;OEoXaMPEzf10&quot;"
             />
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': 'OEoXaMPEzf65',
         'youtube_id_1_0': 'OEoXaMPEzf10',
         'youtube_id_1_25': 'OEoXaMPEzf125',
         'youtube_id_1_5': 'OEoXaMPEzf15',
         'show_captions': False,
         'start_time': datetime.timedelta(seconds=0.0),
         'end_time': datetime.timedelta(seconds=0.0),
         'track': 'http://download_track',
         'download_track': True,
         'download_video': True,
         'html5_sources': ["source_1", "source_2"],
         'data': ''
     })
예제 #19
0
    def test_import_val_data(self, mock_val_api):
        def mock_val_import(xml, edx_video_id, course_id):
            """Mock edxval.api.import_from_xml"""
            self.assertEqual(xml.tag, 'video_asset')
            self.assertEqual(dict(xml.items()), {'mock_attr': ''})
            self.assertEqual(edx_video_id, 'test_edx_video_id')
            self.assertEqual(course_id, 'test_course_id')

        mock_val_api.import_from_xml = Mock(wraps=mock_val_import)
        module_system = DummySystem(load_error_modules=True)

        # import new edx_video_id
        xml_data = """
            <video edx_video_id="test_edx_video_id">
                <video_asset mock_attr=""/>
            </video>
        """
        id_generator = Mock()
        id_generator.target_course_id = 'test_course_id'
        video = VideoDescriptor.from_xml(xml_data, module_system, id_generator)

        self.assert_attributes_equal(video, {'edx_video_id': 'test_edx_video_id'})
        mock_val_api.import_from_xml.assert_called_once_with(
            ANY,
            'test_edx_video_id',
            course_id='test_course_id'
        )
예제 #20
0
 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'
     output = VideoDescriptor._parse_youtube(youtube_str)
     self.assertEqual(output, {'0.75': 'jNCf2gIqpeE',
                               '1.00': 'ZwkTiUPN0mg',
                               '1.25': 'rsq9auxASqI',
                               '1.50': 'kMyNdzVHHgg'})
예제 #21
0
 def test_parse_youtube_empty(self):
     """
     Some courses have empty youtube attributes, so we should handle
     that well.
     """
     self.assertEqual(VideoDescriptor._parse_youtube(''),
                      {'0.75': '',
                       '1.00': '',
                       '1.25': '',
                       '1.50': ''})
예제 #22
0
 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'
     output = VideoDescriptor._parse_youtube(youtube_str)
     self.assertEqual(output, {'0.75': 'jNCf2gIqpeE',
                               '1.00': '',
                               '1.25': '',
                               '1.50': ''})
예제 #23
0
class VideoDescriptorTest(unittest.TestCase):
    """Test for VideoDescriptor"""

    def setUp(self):
        system = get_test_system()
        self.descriptor = VideoDescriptor(
            runtime=system,
            model_data={})

    def test_get_context(self):
        """"test get_context"""
        correct_tabs = [
            {
                'name': "Settings",
                'template': "tabs/metadata-edit-tab.html",
                'current': True
            }
        ]
        rendered_context = self.descriptor.get_context()
        self.assertListEqual(rendered_context['tabs'], correct_tabs)

    def test_create_youtube_string(self):
        """
        Test that Youtube ID strings are correctly created when writing
        back out to XML.
        """
        system = DummySystem(load_error_modules=True)
        location = Location(["i4x", "edX", "video", "default", "SampleProblem1"])
        model_data = {'location': location}
        descriptor = VideoDescriptor(system, model_data)
        descriptor.youtube_id_0_75 = 'izygArpw-Qo'
        descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
        descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
        descriptor.youtube_id_1_5 = 'rABDYkeK0x8'
        expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"
        self.assertEqual(_create_youtube_string(descriptor), expected)

    def test_create_youtube_string_missing(self):
        """
        Test that Youtube IDs which aren't explicitly set aren't included
        in the output string.
        """
        system = DummySystem(load_error_modules=True)
        location = Location(["i4x", "edX", "video", "default", "SampleProblem1"])
        model_data = {'location': location}
        descriptor = VideoDescriptor(system, model_data)
        descriptor.youtube_id_0_75 = 'izygArpw-Qo'
        descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8'
        descriptor.youtube_id_1_25 = '1EeWXzPdhSA'
        expected = "0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA"
        self.assertEqual(_create_youtube_string(descriptor), expected)
예제 #24
0
 def test_from_xml_no_attributes(self):
     """
     Make sure settings are correct if none are explicitly set in XML.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '<video></video>'
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assertEquals(output.youtube_id_0_75, '')
     self.assertEquals(output.youtube_id_1_0, 'OEoXaMPEzfM')
     self.assertEquals(output.youtube_id_1_25, '')
     self.assertEquals(output.youtube_id_1_5, '')
     self.assertEquals(output.show_captions, True)
     self.assertEquals(output.start_time, 0.0)
     self.assertEquals(output.end_time, 0.0)
     self.assertEquals(output.track, '')
     self.assertEquals(output.source, '')
예제 #25
0
 def test_from_xml_no_attributes(self):
     """
     Make sure settings are correct if none are explicitly set in XML.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '<video></video>'
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': '',
         'youtube_id_1_0': 'OEoXaMPEzfM',
         'youtube_id_1_25': '',
         'youtube_id_1_5': '',
         'show_captions': True,
         'start_time': 0.0,
         'end_time': 0.0,
         'track': '',
         'source': '',
         'html5_sources': [],
         'data': ''
     })
예제 #26
0
    def test_from_xml_when_handout_is_course_asset(self, course_id_string, expected_handout_link):
        """
        Test that if handout link is course_asset then it will contain targeted course_id in handout link.
        """
        module_system = DummySystem(load_error_modules=True)
        course_id = CourseKey.from_string(course_id_string)
        xml_data = '''
            <video display_name="Test Video"
                   youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                   show_captions="false"
                   download_track="false"
                   start_time="00:00:01"
                   download_video="false"
                   end_time="00:01:00">
              <source src="http://www.example.com/source.mp4"/>
              <track src="http://www.example.com/track"/>
              <handout src="/asset-v1:test_org_1+test_course_1+test_run_1+type@[email protected]"/>
              <transcript language="uk" src="ukrainian_translation.srt" />
              <transcript language="de" src="german_translation.srt" />
            </video>
        '''
        id_generator = Mock()
        id_generator.target_course_id = course_id

        output = VideoDescriptor.from_xml(xml_data, module_system, id_generator)
        self.assert_attributes_equal(output, {
            'youtube_id_0_75': 'izygArpw-Qo',
            'youtube_id_1_0': 'p2Q6BrNhdh8',
            'youtube_id_1_25': '1EeWXzPdhSA',
            'youtube_id_1_5': 'rABDYkeK0x8',
            'show_captions': False,
            'start_time': datetime.timedelta(seconds=1),
            'end_time': datetime.timedelta(seconds=60),
            'track': 'http://www.example.com/track',
            'handout': expected_handout_link,
            'download_track': False,
            'download_video': False,
            'html5_sources': ['http://www.example.com/source.mp4'],
            'data': '',
            'transcripts': {'uk': 'ukrainian_translation.srt', 'de': 'german_translation.srt'},
        })
예제 #27
0
 def test_from_xml_double_quote_concatenated_youtube(self):
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:&quot;p2Q6BrNhdh8&quot;,1.25:&quot;1EeWXzPdhSA&quot;">
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': '',
         'youtube_id_1_0': 'p2Q6BrNhdh8',
         'youtube_id_1_25': '1EeWXzPdhSA',
         'youtube_id_1_5': '',
         'show_captions': True,
         'start_time': 0.0,
         'end_time': 0.0,
         'track': '',
         'source': '',
         'html5_sources': [],
         'data': ''
     })
예제 #28
0
 def test_from_xml(self):
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8"
                show_captions="false"
                from="00:00:01"
                to="00:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <track src="http://www.example.com/track"/>
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system)
     self.assertEquals(output.youtube_id_0_75, 'izygArpw-Qo')
     self.assertEquals(output.youtube_id_1_0, 'p2Q6BrNhdh8')
     self.assertEquals(output.youtube_id_1_25, '1EeWXzPdhSA')
     self.assertEquals(output.youtube_id_1_5, 'rABDYkeK0x8')
     self.assertEquals(output.show_captions, False)
     self.assertEquals(output.start_time, 1.0)
     self.assertEquals(output.end_time, 60)
     self.assertEquals(output.track, 'http://www.example.com/track')
     self.assertEquals(output.source, 'http://www.example.com/source.mp4')
예제 #29
0
    def test_import_val_data(self):
        create_profile('mobile')
        module_system = DummySystem(load_error_modules=True)

        xml_data = """
            <video edx_video_id="test_edx_video_id">
                <video_asset client_video_id="test_client_video_id" duration="111.0">
                    <encoded_video profile="mobile" url="http://example.com/video" file_size="222" bitrate="333"/>
                </video_asset>
            </video>
        """
        video = VideoDescriptor.from_xml(xml_data, module_system, id_generator=Mock())
        self.assertEqual(video.edx_video_id, 'test_edx_video_id')
        video_data = get_video_info(video.edx_video_id)
        self.assertEqual(video_data['client_video_id'], 'test_client_video_id')
        self.assertEqual(video_data['duration'], 111)
        self.assertEqual(video_data['status'], 'imported')
        self.assertEqual(video_data['courses'], [])
        self.assertEqual(video_data['encoded_videos'][0]['profile'], 'mobile')
        self.assertEqual(video_data['encoded_videos'][0]['url'], 'http://example.com/video')
        self.assertEqual(video_data['encoded_videos'][0]['file_size'], 222)
        self.assertEqual(video_data['encoded_videos'][0]['bitrate'], 333)
예제 #30
0
 def test_from_xml_no_attributes(self):
     """
     Make sure settings are correct if none are explicitly set in XML.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '<video></video>'
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(output, {
         'youtube_id_0_75': '',
         'youtube_id_1_0': 'OEoXaMPEzfM',
         'youtube_id_1_25': '',
         'youtube_id_1_5': '',
         'show_captions': True,
         'start_time': datetime.timedelta(seconds=0.0),
         'end_time': datetime.timedelta(seconds=0.0),
         'track': '',
         'handout': None,
         'download_track': False,
         'download_video': False,
         'html5_sources': [],
         'data': '',
         'transcripts': {},
     })
예제 #31
0
 def test_from_xml_double_quote_concatenated_youtube(self):
     module_system = DummySystem(load_error_modules=True)
     xml_data = '''
         <video display_name="Test Video"
                youtube="1.0:&quot;p2Q6BrNhdh8&quot;,1.25:&quot;1EeWXzPdhSA&quot;">
         </video>
     '''
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(
         output, {
             'youtube_id_0_75': '',
             'youtube_id_1_0': 'p2Q6BrNhdh8',
             'youtube_id_1_25': '1EeWXzPdhSA',
             'youtube_id_1_5': '',
             'show_captions': True,
             'start_time': datetime.timedelta(seconds=0.0),
             'end_time': datetime.timedelta(seconds=0.0),
             'track': '',
             'handout': None,
             'download_track': False,
             'download_video': False,
             'html5_sources': [],
             'data': ''
         })
예제 #32
0
 def test_from_xml_no_attributes(self):
     """
     Make sure settings are correct if none are explicitly set in XML.
     """
     module_system = DummySystem(load_error_modules=True)
     xml_data = '<video></video>'
     output = VideoDescriptor.from_xml(xml_data, module_system, Mock())
     self.assert_attributes_equal(
         output, {
             'youtube_id_0_75': '',
             'youtube_id_1_0': 'OEoXaMPEzfM',
             'youtube_id_1_25': '',
             'youtube_id_1_5': '',
             'show_captions': True,
             'start_time': datetime.timedelta(seconds=0.0),
             'end_time': datetime.timedelta(seconds=0.0),
             'track': '',
             'handout': None,
             'download_track': False,
             'download_video': False,
             'html5_sources': [],
             'data': '',
             'transcripts': {},
         })
예제 #33
0
 def setUp(self):
     system = get_test_system()
     self.descriptor = VideoDescriptor(runtime=system, model_data={})
예제 #34
0
    def test_export_to_xml(self):
        """Test that we write the correct XML on export."""
        module_system = DummySystem(load_error_modules=True)
        desc = VideoDescriptor(
            module_system, DictFieldData({}),
            ScopeIds(None, None, self.location, self.location))

        desc.youtube_id_0_75 = 'izygArpw-Qo'
        desc.youtube_id_1_0 = 'p2Q6BrNhdh8'
        desc.youtube_id_1_25 = '1EeWXzPdhSA'
        desc.youtube_id_1_5 = 'rABDYkeK0x8'
        desc.show_captions = False
        desc.start_time = datetime.timedelta(seconds=1.0)
        desc.end_time = datetime.timedelta(seconds=60)
        desc.track = 'http://www.example.com/track'
        desc.handout = 'http://www.example.com/handout'
        desc.download_track = True
        desc.html5_sources = [
            'http://www.example.com/source.mp4',
            'http://www.example.com/source.ogg'
        ]
        desc.download_video = True
        desc.transcripts = {
            'ua': 'ukrainian_translation.srt',
            'ge': 'german_translation.srt'
        }

        xml = desc.definition_to_xml(
            None)  # We don't use the `resource_fs` parameter
        expected = etree.fromstring('''\
         <video url_name="SampleProblem1" start_time="0:00:01" youtube="0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8" show_captions="false" end_time="0:01:00" download_video="true" download_track="true">
           <source src="http://www.example.com/source.mp4"/>
           <source src="http://www.example.com/source.ogg"/>
           <track src="http://www.example.com/track"/>
           <handout src="http://www.example.com/handout"/>
           <transcript language="ge" src="german_translation.srt" />
           <transcript language="ua" src="ukrainian_translation.srt" />
         </video>
        ''')
        self.assertXmlEqual(expected, xml)
예제 #35
0
 def test_parse_time_with_float(self):
     """Ensure that times are parsed correctly into seconds."""
     expected = 247
     output = VideoDescriptor._parse_time('247.0')
     self.assertEqual(output, expected)
예제 #36
0
 def test_parse_time_empty(self):
     """Ensure parse_time returns correctly with None or empty string."""
     expected = ''
     self.assertEqual(VideoDescriptor._parse_time(None), expected)
     self.assertEqual(VideoDescriptor._parse_time(''), expected)
예제 #37
0
    def test_export_to_xml(self):
        """Test that we write the correct XML on export."""
        module_system = DummySystem(load_error_modules=True)
        location = Location(
            ["i4x", "edX", "video", "default", "SampleProblem1"])
        desc = VideoDescriptor(module_system, DictFieldData({}),
                               ScopeIds(None, None, location, location))

        desc.youtube_id_0_75 = 'izygArpw-Qo'
        desc.youtube_id_1_0 = 'p2Q6BrNhdh8'
        desc.youtube_id_1_25 = '1EeWXzPdhSA'
        desc.youtube_id_1_5 = 'rABDYkeK0x8'
        desc.show_captions = False
        desc.start_time = 1.0
        desc.end_time = 60
        desc.track = 'http://www.example.com/track'
        desc.html5_sources = [
            'http://www.example.com/source.mp4',
            'http://www.example.com/source.ogg'
        ]

        xml = desc.definition_to_xml(
            None)  # We don't use the `resource_fs` parameter
        expected = etree.fromstring('''\
         <video url_name="SampleProblem1" start_time="0:00:01" youtube="0.75:izygArpw-Qo,1.00:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8" show_captions="false" end_time="0:01:00">
           <source src="http://www.example.com/source.mp4"/>
           <source src="http://www.example.com/source.ogg"/>
           <track src="http://www.example.com/track"/>
         </video>
        ''')

        self.assertXmlEqual(expected, xml)
예제 #38
0
 def test_parse_time(self):
     """Ensure that times are parsed correctly into seconds."""
     output = VideoDescriptor._parse_time('00:04:07')
     self.assertEqual(output, 247)
예제 #39
0
 def test_parse_time_none(self):
     """Check parsing of None."""
     output = VideoDescriptor._parse_time(None)
     self.assertEqual(output, '')
예제 #40
0
 def test_parse_time_empty(self):
     """Check parsing of the empty string."""
     output = VideoDescriptor._parse_time('')
     self.assertEqual(output, '')