Esempio n. 1
0
def test_rsync_respects_all_options(mock_run, rsync_ssh):
    mock_run.return_value = MagicMock(returncode=0)
    rsync("src/",
          "dst",
          rsync_ssh,
          info=True,
          verbose=True,
          mirror=True,
          dry_run=True,
          extra_args=["--some-extra"])

    mock_run.assert_called_once_with(
        [
            "rsync",
            "-arlpmchz",
            "--copy-unsafe-links",
            "-e",
            "ssh -Kq -o BatchMode=yes",
            "--force",
            "-i",
            "-v",
            "-n",
            "--delete",
            "--delete-after",
            "--delete-excluded",
            "--some-extra",
            "src/",
            "dst",
        ],
        stdout=ANY,
        stderr=ANY,
    )
Esempio n. 2
0
def test_rsync_copies_files(tmp_path, rsync_ssh):
    src = tmp_path / "src"
    src.mkdir()
    (src / "first").write_text("TEST first")
    (src / "second").write_text("TEST second")
    (src / "third.txt").write_text("TEST third")
    (src / "fourth.txt").write_text("TEST fourth")

    dst = tmp_path / "dst"
    rsync(f"{src}/", str(dst), rsync_ssh, excludes=["f*"], includes=["*.txt"])

    assert dst.exists()
    assert not (dst / "first").exists()
    assert (dst / "second").exists()
    assert (dst / "second").read_text() == "TEST second"
    assert (dst / "third.txt").exists()
    assert (dst / "third.txt").read_text() == "TEST third"
    assert (dst / "fourth.txt").exists()
    assert (dst / "fourth.txt").read_text() == "TEST fourth"
Esempio n. 3
0
def test_rsync_copies_files_with_mirror(tmp_path, rsync_ssh):
    src = tmp_path / "src"
    src.mkdir()
    (src / "first").write_text("TEST first")
    (src / "second").write_text("TEST second")
    (src / "third.txt").write_text("TEST third")
    (src / "fourth.txt").write_text("TEST fourth")

    dst = tmp_path / "dst"
    dst.mkdir()
    (dst / "first").write_text("TEST first")

    # since we use mirror=True "first" should be deleted in dst
    rsync(f"{src}/", str(dst), rsync_ssh, excludes=["f*"], mirror=True)

    assert dst.exists()
    assert not (dst / "first").exists()
    assert (dst / "second").exists()
    assert (dst / "second").read_text() == "TEST second"
    assert (dst / "third.txt").exists()
    assert (dst / "third.txt").read_text() == "TEST third"
    assert not (dst / "fourth.txt").exists()
Esempio n. 4
0
def test_rsync_always_removes_temporary_files(mock_temp_file, mock_run,
                                              returncode, tmp_path, rsync_ssh):
    mock_run.return_value = MagicMock(returncode=returncode)

    files = []

    def ignore_file(_):
        new_path = tmp_path / f"file{len(files)}"
        new_path.write_text("TEST")
        files.append(new_path)
        return new_path

    mock_temp_file.side_effect = ignore_file

    try:
        rsync("src/", "dst", rsync_ssh, excludes=["f*"], includes=["*.txt"])
    except Exception:
        pass

    assert len(files) == 2
    for file in files:
        assert not file.exists()
Esempio n. 5
0
def test_rsync_throws_exception_on_bad_return_code(mock_run, rsync_ssh):
    mock_run.return_value = MagicMock()
    mock_run.return_value.returncode = 1

    with pytest.raises(RemoteConnectionError):
        rsync("src/", "dst", rsync_ssh)