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)
def test_constructor(self): sample_xml = ''' <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> ''' location = Location( ["i4x", "edX", "video", "default", "SampleProblem1"]) model_data = {'data': sample_xml, 'location': location} system = DummySystem(load_error_modules=True) descriptor = VideoDescriptor(system, model_data) self.assertEquals(descriptor.youtube_id_0_75, 'izygArpw-Qo') self.assertEquals(descriptor.youtube_id_1_0, 'p2Q6BrNhdh8') self.assertEquals(descriptor.youtube_id_1_25, '1EeWXzPdhSA') self.assertEquals(descriptor.youtube_id_1_5, 'rABDYkeK0x8') self.assertEquals(descriptor.show_captions, False) self.assertEquals(descriptor.start_time, 1.0) self.assertEquals(descriptor.end_time, 60) self.assertEquals(descriptor.track, 'http://www.example.com/track') self.assertEquals(descriptor.source, 'http://www.example.com/source.mp4')
def test_constructor(self): sample_xml = ''' <video display_name="Test Video" youtube="1.0:p2Q6BrNhdh8,0.75:izygArpw-Qo,1.25:1EeWXzPdhSA,1.5:rABDYkeK0x8" show_captions="false" download_track="true" download_video="true" start_time="00:00:01" end_time="00: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"/> <handout src="http://www.example.com/handout"/> <transcript language="ua" src="ukrainian_translation.srt" /> <transcript language="ge" src="german_translation.srt" /> </video> ''' location = Location( ["i4x", "edX", "video", "default", "SampleProblem1"]) field_data = DictFieldData({'data': sample_xml, 'location': location}) system = DummySystem(load_error_modules=True) descriptor = VideoDescriptor(system, field_data, Mock()) self.assert_attributes_equal( descriptor, { 'youtube_id_0_75': 'izygArpw-Qo', 'youtube_id_1_0': 'p2Q6BrNhdh8', 'youtube_id_1_25': '1EeWXzPdhSA', 'youtube_id_1_5': 'rABDYkeK0x8', 'download_video': True, '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': True, 'html5_sources': [ 'http://www.example.com/source.mp4', 'http://www.example.com/source.ogg' ], 'data': '', 'transcripts': { 'ua': 'ukrainian_translation.srt', 'ge': 'german_translation.srt' } })
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, DictFieldData({}), ScopeIds(None, None, location, location)) xml = desc.definition_to_xml(None) expected = '<video url_name="SampleProblem1"/>\n' self.assertEquals(expected, etree.tostring(xml, pretty_print=True))
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
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"]) 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)
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
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"]) 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)
def test_constructor(self): sample_xml = ''' <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"/> <source src="http://www.example.com/source.ogg"/> <track src="http://www.example.com/track"/> </video> ''' location = Location( ["i4x", "edX", "video", "default", "SampleProblem1"]) field_data = DictFieldData({'data': sample_xml, 'location': location}) system = DummySystem(load_error_modules=True) descriptor = VideoDescriptor(system, field_data, Mock()) self.assert_attributes_equal( descriptor, { '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', 'http://www.example.com/source.ogg' ], 'data': '' })
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)
def setUp(self): system = get_test_system() self.descriptor = VideoDescriptor(runtime=system, model_data={})