From 845bb7b88426c315c07b20c69a8e904e9c2bb336 Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Mon, 11 Sep 2017 15:06:11 +0500 Subject: [PATCH] transcript import export EDUCATOR-1216 --- .../test_cross_modulestore_import_export.py | 1 + .../xmodule/modulestore/tests/test_mongo.py | 3 + .../lib/xmodule/xmodule/tests/test_export.py | 1 + .../lib/xmodule/xmodule/tests/test_video.py | 31 +++-- .../xmodule/video_module/video_module.py | 64 ++++++---- .../courseware/tests/test_video_mongo.py | 111 +++++++++++++++++- 6 files changed, 173 insertions(+), 38 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py index 042198113f..3fce2798e3 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_cross_modulestore_import_export.py @@ -55,6 +55,7 @@ class CrossStoreXMLRoundtrip(CourseComparisonTest, PartitionTestCase): self.export_dir = mkdtemp() self.addCleanup(rmtree, self.export_dir, ignore_errors=True) + @patch('xmodule.video_module.video_module.edxval_api', None) @patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json) @ddt.data(*itertools.product( MODULESTORE_SETUPS, diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index ca1239c402..e1801de0ec 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -557,6 +557,7 @@ class TestMongoModuleStore(TestMongoModuleStoreBase): check_xblock_fields() check_mongo_fields() + @patch('xmodule.video_module.video_module.edxval_api', None) @patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json) def test_export_course_image(self, _from_json): """ @@ -575,6 +576,7 @@ class TestMongoModuleStore(TestMongoModuleStoreBase): self.assertTrue(path(root_dir / 'test_export/static/images/course_image.jpg').isfile()) self.assertTrue(path(root_dir / 'test_export/static/images_course_image.jpg').isfile()) + @patch('xmodule.video_module.video_module.edxval_api', None) @patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json) def test_export_course_image_nondefault(self, _from_json): """ @@ -590,6 +592,7 @@ class TestMongoModuleStore(TestMongoModuleStoreBase): self.assertTrue(path(root_dir / 'test_export/static/just_a_test.jpg').isfile()) self.assertFalse(path(root_dir / 'test_export/static/images/course_image.jpg').isfile()) + @patch('xmodule.video_module.video_module.edxval_api', None) def test_course_without_image(self): """ Make sure we elegantly passover our code when there isn't a static diff --git a/common/lib/xmodule/xmodule/tests/test_export.py b/common/lib/xmodule/xmodule/tests/test_export.py index 4e5c330419..c43e3e4cb1 100644 --- a/common/lib/xmodule/xmodule/tests/test_export.py +++ b/common/lib/xmodule/xmodule/tests/test_export.py @@ -68,6 +68,7 @@ class RoundTripTestCase(unittest.TestCase): self.temp_dir = mkdtemp() self.addCleanup(shutil.rmtree, self.temp_dir) + @mock.patch('xmodule.video_module.video_module.edxval_api', None) @mock.patch('xmodule.course_module.requests.get') @ddt.data( "toy", diff --git a/common/lib/xmodule/xmodule/tests/test_video.py b/common/lib/xmodule/xmodule/tests/test_video.py index 6df6a9f0a0..63b98eda64 100644 --- a/common/lib/xmodule/xmodule/tests/test_video.py +++ b/common/lib/xmodule/xmodule/tests/test_video.py @@ -646,7 +646,11 @@ class VideoDescriptorImportTestCase(unittest.TestCase): 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') + mock_val_api.import_from_xml.assert_called_once_with( + ANY, + 'test_edx_video_id', + course_id='test_course_id' + ) @patch('xmodule.video_module.video_module.edxval_api') def test_import_val_data_invalid(self, mock_val_api): @@ -673,14 +677,7 @@ class VideoExportTestCase(VideoDescriptorTestBase): """ Test that we write the correct XML on export. """ - def mock_val_export(edx_video_id, course_id): - """Mock edxval.api.export_to_xml""" - return etree.Element( - 'video_asset', - attrib={'export_edx_video_id': edx_video_id} - ) - - mock_val_api.export_to_xml = mock_val_export + mock_val_api.export_to_xml = Mock(return_value=etree.Element('video_asset')) self.descriptor.youtube_id_0_75 = 'izygArpw-Qo' self.descriptor.youtube_id_1_0 = 'p2Q6BrNhdh8' self.descriptor.youtube_id_1_25 = '1EeWXzPdhSA' @@ -691,7 +688,7 @@ class VideoExportTestCase(VideoDescriptorTestBase): self.descriptor.track = 'http://www.example.com/track' self.descriptor.handout = 'http://www.example.com/handout' self.descriptor.download_track = True - self.descriptor.html5_sources = ['http://www.example.com/source.mp4', 'http://www.example.com/source.ogg'] + self.descriptor.html5_sources = ['http://www.example.com/source.mp4', 'http://www.example.com/source1.ogg'] self.descriptor.download_video = True self.descriptor.transcripts = {'ua': 'ukrainian_translation.srt', 'ge': 'german_translation.srt'} self.descriptor.edx_video_id = 'test_edx_video_id' @@ -702,16 +699,21 @@ class VideoExportTestCase(VideoDescriptorTestBase): xml_string = '''\ ''' expected = etree.XML(xml_string, parser=parser) self.assertXmlEqual(expected, xml) + mock_val_api.export_to_xml.assert_called_once_with( + [u'test_edx_video_id', u'p2Q6BrNhdh8', 'source', 'source1'], + ANY, + external=False + ) @patch('xmodule.video_module.video_module.edxval_api') def test_export_to_xml_val_error(self, mock_val_api): @@ -727,6 +729,7 @@ class VideoExportTestCase(VideoDescriptorTestBase): expected = etree.XML(xml_string, parser=parser) self.assertXmlEqual(expected, xml) + @patch('xmodule.video_module.video_module.edxval_api', None) def test_export_to_xml_empty_end_time(self): """ Test that we write the correct XML on export. @@ -755,6 +758,7 @@ class VideoExportTestCase(VideoDescriptorTestBase): expected = etree.XML(xml_string, parser=parser) self.assertXmlEqual(expected, xml) + @patch('xmodule.video_module.video_module.edxval_api', None) def test_export_to_xml_empty_parameters(self): """ Test XML export with defaults. @@ -764,6 +768,7 @@ class VideoExportTestCase(VideoDescriptorTestBase): expected = '