def setUp(self): self.course_data_path = path('/path') self.mocked_content_store = mock.Mock() self.static_content_importer = StaticContentImporter( static_content_store=self.mocked_content_store, course_data_path=self.course_data_path, target_id=CourseKey.from_string('course-v1:edX+DemoX+Demo_Course'))
def setUp(self): # lint-amnesty, pylint: disable=super-method-not-called self.course_data_path = path('/path') self.mocked_content_store = mock.Mock() self.static_content_importer = StaticContentImporter( static_content_store=self.mocked_content_store, course_data_path=self.course_data_path, target_id=CourseKey.from_string('course-v1:edX+DemoX+Demo_Course'))
def test_ignore_tilde_static_files(self): course_dir = DATA_DIR / "tilde" course_id = CourseLocator("edX", "tilde", "Fall_2012") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=course_dir, target_id=course_id ) static_content_importer.import_static_content_directory() saved_static_content = [call[0][0] for call in content_store.save.call_args_list] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertNotIn("example.txt~", name_val) self.assertIn("GREEN", name_val["example.txt"])
class StaticContentImporterTest(unittest.TestCase): shard = 2 def setUp(self): self.course_data_path = path('/path') self.mocked_content_store = mock.Mock() self.static_content_importer = StaticContentImporter( static_content_store=self.mocked_content_store, course_data_path=self.course_data_path, target_id=CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') ) def test_import_static_content_directory(self): static_content_dir = 'static' expected_base_dir = path(self.course_data_path / static_content_dir) mocked_os_walk_yield = [ ('static', None, ['file1.txt', 'file2.txt']), ('static/inner', None, ['file1.txt']), ] with mock.patch( 'xmodule.modulestore.xml_importer.os.walk', return_value=mocked_os_walk_yield ), mock.patch.object( self.static_content_importer, 'import_static_file' ) as patched_import_static_file: self.static_content_importer.import_static_content_directory('static') patched_import_static_file.assert_any_call( 'static/file1.txt', base_dir=expected_base_dir ) patched_import_static_file.assert_any_call( 'static/file2.txt', base_dir=expected_base_dir ) patched_import_static_file.assert_any_call( 'static/inner/file1.txt', base_dir=expected_base_dir ) def test_import_static_file(self): base_dir = path('/path/to/dir') full_file_path = os.path.join(base_dir, 'static/some_file.txt') self.mocked_content_store.generate_thumbnail.return_value = (None, None) with mock.patch("__builtin__.open", mock.mock_open(read_data="data")) as mock_file: self.static_content_importer.import_static_file( full_file_path=full_file_path, base_dir=base_dir ) mock_file.assert_called_with(full_file_path, 'rb') self.mocked_content_store.assert_called_once()
def setUp(self): self.course_data_path = path('/path') self.mocked_content_store = mock.Mock() self.static_content_importer = StaticContentImporter( static_content_store=self.mocked_content_store, course_data_path=self.course_data_path, target_id=CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') )
class StaticContentImporterTest(unittest.TestCase): def setUp(self): self.course_data_path = path('/path') self.mocked_content_store = mock.Mock() self.static_content_importer = StaticContentImporter( static_content_store=self.mocked_content_store, course_data_path=self.course_data_path, target_id=CourseKey.from_string('course-v1:edX+DemoX+Demo_Course') ) def test_import_static_content_directory(self): static_content_dir = 'static' expected_base_dir = path(self.course_data_path / static_content_dir) mocked_os_walk_yield = [ ('static', None, ['file1.txt', 'file2.txt']), ('static/inner', None, ['file1.txt']), ] with mock.patch( 'xmodule.modulestore.xml_importer.os.walk', return_value=mocked_os_walk_yield ), mock.patch.object( self.static_content_importer, 'import_static_file' ) as patched_import_static_file: self.static_content_importer.import_static_content_directory('static') patched_import_static_file.assert_any_call( 'static/file1.txt', base_dir=expected_base_dir ) patched_import_static_file.assert_any_call( 'static/file2.txt', base_dir=expected_base_dir ) patched_import_static_file.assert_any_call( 'static/inner/file1.txt', base_dir=expected_base_dir ) def test_import_static_file(self): base_dir = path('/path/to/dir') full_file_path = os.path.join(base_dir, 'static/some_file.txt') self.mocked_content_store.generate_thumbnail.return_value = (None, None) with mock.patch("__builtin__.open", mock.mock_open(read_data="data")) as mock_file: self.static_content_importer.import_static_file( full_file_path=full_file_path, base_dir=base_dir ) mock_file.assert_called_with(full_file_path, 'rb') self.mocked_content_store.assert_called_once()
def test_ignore_tilde_static_files(self): course_dir = DATA_DIR / "tilde" course_id = CourseLocator("edX", "tilde", "Fall_2012") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=course_dir, target_id=course_id) static_content_importer.import_static_content_directory() saved_static_content = [ call[0][0] for call in content_store.save.call_args_list ] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertNotIn("example.txt~", name_val) self.assertIn("GREEN", name_val["example.txt"])
def test_ignore_dot_underscore_static_files(self): """ Test for ignored Mac OS metadata files (filename starts with "._") """ course_dir = DATA_DIR / "dot-underscore" course_id = CourseLocator("edX", "dot-underscore", "2014_Fall") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=course_dir, target_id=course_id ) static_content_importer.import_static_content_directory() saved_static_content = [call[0][0] for call in content_store.save.call_args_list] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertIn(".example.txt", name_val) self.assertNotIn("._example.txt", name_val) self.assertNotIn(".DS_Store", name_val) self.assertIn("GREEN", name_val["example.txt"]) self.assertIn("BLUE", name_val[".example.txt"])
def test_sample_static_files(self): """ Test for to ensure Mac OS metadata files (filename starts with "._") as well as files ending with "~" get ignored, while files starting with "." are not. """ course_id = CourseLocator("edX", "course_ignore", "2014_Fall") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=self.course_dir, target_id=course_id ) static_content_importer.import_static_content_directory() saved_static_content = [call[0][0] for call in content_store.save.call_args_list] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertIn(".example.txt", name_val) self.assertIn("GREEN", name_val["example.txt"]) self.assertIn("BLUE", name_val[".example.txt"]) self.assertNotIn("._example.txt", name_val) self.assertNotIn(".DS_Store", name_val) self.assertNotIn("example.txt~", name_val)
def test_sample_static_files(self): """ Test for to ensure Mac OS metadata files (filename starts with "._") as well as files ending with "~" get ignored, while files starting with "." are not. """ course_id = CourseLocator("edX", "course_ignore", "2014_Fall") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=self.course_dir, target_id=course_id ) static_content_importer.import_static_content_directory() saved_static_content = [call[0][0] for call in content_store.save.call_args_list] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertIn(".example.txt", name_val) self.assertIn(b"GREEN", name_val["example.txt"]) self.assertIn(b"BLUE", name_val[".example.txt"]) self.assertNotIn("._example.txt", name_val) self.assertNotIn(".DS_Store", name_val) self.assertNotIn("example.txt~", name_val)
def test_ignore_dot_underscore_static_files(self): """ Test for ignored Mac OS metadata files (filename starts with "._") """ course_dir = DATA_DIR / "dot-underscore" course_id = CourseLocator("edX", "dot-underscore", "2014_Fall") content_store = Mock() content_store.generate_thumbnail.return_value = ("content", "location") static_content_importer = StaticContentImporter( static_content_store=content_store, course_data_path=course_dir, target_id=course_id) static_content_importer.import_static_content_directory() saved_static_content = [ call[0][0] for call in content_store.save.call_args_list ] name_val = {sc.name: sc.data for sc in saved_static_content} self.assertIn("example.txt", name_val) self.assertIn(".example.txt", name_val) self.assertNotIn("._example.txt", name_val) self.assertNotIn(".DS_Store", name_val) self.assertIn("GREEN", name_val["example.txt"]) self.assertIn("BLUE", name_val[".example.txt"])