def test_scan_returns_file_names_that_could_not_be_imported(mocker): from cozy.media.importer import Importer files = {"1", "2"} mocker.patch("multiprocessing.pool.ThreadPool.map", return_value=files) mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(files) assert not_imported == files
def test_scan_returns_none_for_non_audio_files(mocker): from cozy.media.importer import Importer def iterator(): for item in [None, None]: yield item mocker.patch("multiprocessing.pool.ThreadPool.map", return_value=iterator()) mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(["a"]) assert not_imported == set()
def test_scan_returns_file_names_that_could_not_be_imported(mocker): from cozy.media.importer import Importer files = {"1", "2"} class Mock: def get(self): return {"1", "2"} mocker.patch("multiprocessing.pool.Pool.map_async", return_value=Mock()) mocker.patch("cozy.media.importer.Importer._wait_for_job_to_complete") mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(files) assert not_imported == files
def test_scan_processes_all_files_even_if_many_are_not_audio_files(mocker): from cozy.media.importer import Importer def iterator(): items = [None] * 200 items.append("test") for item in items: yield item mocker.patch("multiprocessing.pool.ThreadPool.map", return_value=iterator()) mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(["a"]) assert len(not_imported) == 1 assert "test" in not_imported
def test_scan_returns_none_for_non_audio_files(mocker): from cozy.media.importer import Importer class Mock: def get(self): return self.iterator() def iterator(self): for item in [None, None]: yield item mocker.patch("multiprocessing.pool.Pool.map_async", return_value=Mock()) mocker.patch("cozy.media.importer.Importer._wait_for_job_to_complete") mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(["a"]) assert not_imported == set()
def test_execute_import_returns_list_of_imported_files(mocker): from cozy.media.importer import Importer media_file1 = MediaFile(book_name="a", author="a", reader="a", disk=1, track_number=1, length=1, cover=b"", path="path", modified=1, chapters=[]) media_file2 = MediaFile(book_name="a", author="a", reader="a", disk=1, track_number=1, length=1, cover=b"", path="path2", modified=1, chapters=[]) class Mock: def get(self): return self.iterator() def iterator(self): for item in [media_file1, media_file2, None]: yield item mocker.patch("multiprocessing.pool.Pool.map_async", return_value=Mock()) mocker.patch("cozy.media.importer.Importer._wait_for_job_to_complete") mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() imported, _ = importer._execute_import(["a", "b"]) assert all([a == b for a, b in zip(imported, ["path", "path2"])])
def test_scan_processes_all_files_even_if_many_are_not_audio_files(mocker): from cozy.media.importer import Importer class Mock: def get(self): return self.iterator() def iterator(self): items = [None] * 200 items.append("test") for item in items: yield item mocker.patch("multiprocessing.pool.Pool.map_async", return_value=Mock()) mocker.patch("cozy.media.importer.Importer._wait_for_job_to_complete") mocker.patch("cozy.model.library.Library.insert_many") importer = Importer() _, not_imported = importer._execute_import(["a"]) assert len(not_imported) == 1 assert "test" in not_imported