Example #1
0
def test_archive_second_query_failure(mocker: MockerFixture):
    archive_path = Path("/", "test_path")
    fs = mocker.Mock(spec=Filesystem)
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult({1: Path("/", "file_1")})
    client.get_torrent_name_by_id.return_value = QueryResult(
        error="some_error", success=False
    )
    command = ArchiveCommand(archive_path, fs, client)

    result: ArchiveOutput = command.run()

    assert result.query_failure == "query failed: get_torrent_name_by_id"
Example #2
0
def test_archive_success(mocker: MockerFixture):
    archive_path = Path("/", "test_path")
    fs = mocker.Mock(spec=Filesystem)
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult({1: Path("/", "file_1")})
    client.get_torrent_name_by_id.return_value = QueryResult({1: "test_name"})
    command = ArchiveCommand(archive_path, fs, client)

    result: ArchiveOutput = command.run()

    assert result.copied == {ArchiveAction(1, "test_name", Path("/", "file_1"))}
    fs.create_dir.assert_called_once_with(Path("/", "test_path"))
    fs.copy.assert_called_once_with(Path("/", "file_1"), Path("/", "test_path"))
Example #3
0
def test_query_failure_output(mocker: MockerFixture, capsys):
    archive_path = Path("/", "test_path")
    fs = MockFilesystem({})
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult(
        error="some_error", success=False
    )
    client.get_torrent_name_by_id.return_value = QueryResult({1: "test_name"})
    command = ArchiveCommand(archive_path, fs, client)

    output: ArchiveOutput = command.run()
    output.display()

    result = capsys.readouterr().out
    assert result == "Query failed: get_torrent_files_by_id\n"
Example #4
0
def test_run_display_copy_failure(mocker: MockerFixture, capsys):
    archive_path = Path("/", "test_path")
    fs = MockFilesystem({"file_1", "test_path"})
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult({1: Path("/", "file_1")})
    client.get_torrent_name_by_id.return_value = QueryResult({1: "test_name"})
    command = ArchiveCommand(archive_path, fs, client)

    output: ArchiveOutput = command.run()
    output.display()

    result = capsys.readouterr().out
    assert (
        result
        == "\n".join(
            [
                "Failed to move 1 metainfo files:",
                "\x1b[31m✗ failed to move /file_1 because:destination is a file",
            ]
        )
        + "\n"
    )
Example #5
0
def test_display(mocker: MockerFixture, capsys):
    archive_path = Path("/", "test_path")
    fs = mocker.Mock(spec=Filesystem)
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult({1: Path("/", "file_1")})
    client.get_torrent_name_by_id.return_value = QueryResult({1: "test_name"})
    command = ArchiveCommand(archive_path, fs, client)

    output: ArchiveOutput = command.run()
    output.display()

    result = capsys.readouterr().out
    assert (
        result
        == "\n".join(
            [
                "Moved 1 metainfo files to /test_path:",
                "\x1b[32m✓ test_name",
            ]
        )
        + "\n"
    )
Example #6
0
def test_run_display_already_exists(mocker: MockerFixture, capsys):
    archive_path = Path("/", "test_path")
    fs = MockFilesystem(["file_1", {"test_path": ["file_1"]}])
    client = mocker.Mock(spec=TransmissionApi)
    client.get_torrent_files_by_id.return_value = QueryResult({1: Path("/", "file_1")})
    client.get_torrent_name_by_id.return_value = QueryResult({1: "test_name"})
    command = ArchiveCommand(archive_path, fs, client)

    output: ArchiveOutput = command.run()
    output.display()

    result = capsys.readouterr().out
    assert (
        result
        == "\n".join(
            [
                "Found 1 duplicate metainfo files:",
                "test_name",
                "No metainfo files moved",
            ]
        )
        + "\n"
    )