def test_add_linking_unknown(mocker: MockerFixture): api = mocker.Mock(spec=TransmissionApi) api.add_torrent_with_files.return_value = CommandResult(error="unknown", success=False) api.add_torrent.return_value = CommandResult(error="unknown", success=False) add_service = AddService(api) fs = MockFilesystem({"test_path"}) path = Path("/", "test_path") file = MetainfoFile( { "name": "meaningless", "info_hash": "meaningless and necessary", "info": { "length": 5 }, }, path, ) command = LinkingAddCommand(add_service, fs, {TorrentData(file, Path("/some/place"))}) output: LinkingAddOutput = command.run() assert fs.exists(path) assert output.failed_torrents == {file: "unknown"}
def test_add_linking_success(mocker: MockerFixture): api = mocker.Mock(spec=TransmissionApi) api.add_torrent_with_files.return_value = CommandResult(success=True) api.add_torrent.return_value = CommandResult(success=True) add_service = AddService(api) fs = MockFilesystem({"test_path"}) locator: TorrentDataLocator = DefaultTorrentDataLocator(fs) find_service = FindService(locator) path = Path("/", "test_path") file = MetainfoFile( { "name": "meaningless", "info_hash": "meaningless and necessary", "info": { "length": 5 }, }, path, ) command = LinkingAddCommand(add_service, fs, {TorrentData(file, Path("/some/place"))}) output: LinkingAddOutput = command.run() assert not fs.exists(path) assert output.linked_torrents == {file: Path("/some/place")}
def test_mock_fs_nested_complex(): fs = MockFilesystem( { "upper": {"testing": {"file1", "file2.torrent", "file3", "file4.torrent"}}, "multi": ["file7", {"another": ["file5", {"level3": {"file8"}}]}], } ) assert fs.exists(Path("/multi/another/level3"))
def test_prune_folder_dry_run(mocker: MockerFixture): fs = MockFilesystem({"some_path"}) files = { MetainfoFile({ "info_hash": "aaa", "name": "some_name" }, Path("/some_path")) } service: PruneService = mocker.Mock(spec=PruneService) service.get_torrent_hashes.return_value = {"aaa", "bbb"} command = PruneFolderCommand(service, fs, files) command.dry_run() assert fs.exists(Path("/some_path"))
def test_mock_fs_top_level(): fs = MockFilesystem({"test"}) assert fs.exists(Path("/test"))
def test_mock_fs_nested_complex_2(): fs = MockFilesystem( {"data": {"torrent_name": ["torrent_file1", {"folder": "torrent_file2"}]}} ) assert fs.exists(Path("/data/torrent_name/folder/torrent_file2"))