Esempio n. 1
0
def test_vcs_fail_config(tmpdir):

    fake_key = tmpdir.join("fake-key")
    fake_key.ensure()
    fake_key = str(fake_key)

    with pytest.raises(ValidationError) as excinfo:
        config_model.GitSpec(repo="*****@*****.**",
                             password="******",
                             deploy_passphrase="foobaz")

    errs = excinfo.value.errors()
    assert errs[0]["msg"] == "deploy_key required when using deploy_passphrase"

    with pytest.raises(ValidationError) as excinfo:
        config_model.GitSpec(repo="*****@*****.**")

    errs = excinfo.value.errors()
    assert errs[0]["msg"].startswith(
        "Missing one of required auth method fields")

    with pytest.raises(ValidationError) as excinfo:
        config_model.GitSpec(repo="*****@*****.**",
                             token="token",
                             deploy_key=fake_key)

    errs = excinfo.value.errors()
    assert errs[0]["msg"].startswith("Only one of")
Esempio n. 2
0
def test_vcs_pass_prepare_deploykey_passphrase(mock_pexpect, tmpdir,
                                               monkeypatch):
    monkeypatch.setenv("USER", "dummy-user")

    key_file = tmpdir.join("dummy-keyfile")
    key_file.ensure()
    key_file = str(key_file)

    git_cfg = config_model.GitSpec(
        repo="*****@*****.**",
        deploy_key=key_file,
        deploy_passphrase="dummy-key-passphrase",
    )

    repo_dir = tmpdir.join("repo")

    git.vcs_prepare(spec=git_cfg, repo_dir=Path(repo_dir))

    mock_run = mock_pexpect.run
    assert mock_run.called
    calls = mock_run.mock_calls

    expected_commands = [
        "git init",
        "git remote add origin [email protected]",
        "git config --local user.email dummy-user",
        "git config --local user.name dummy-user",
        "git config --local push.default matching",
        f"git config --local core.sshCommand 'ssh -i {key_file} -o StrictHostKeyChecking=no'",
        "git pull origin master",
    ]

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].kwargs["command"] == cmd
Esempio n. 3
0
def test_vcs_pass_git_config(monkeypatch, tmpdir, mock_pexpect):
    monkeypatch.setenv("USER", "dummy-user")
    git_cfg = config_model.GitSpec(repo="https://[email protected]",
                                   token="dummy-token")
    repo_dir = Path(tmpdir.join("repo"))
    repo_dir.mkdir()

    git_rnr = git.git_runner(git_cfg, repo_dir)

    assert git_rnr.repo_url == "https://dummy-user@[email protected]"
    assert git_rnr.is_dir_empty is True

    git_rnr.git_config()

    expected_commands = [
        "git config --local user.email dummy-user",
        "git config --local user.name dummy-user",
        "git config --local push.default matching",
    ]

    calls = mock_pexpect.run.mock_calls

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].kwargs["command"] == cmd
Esempio n. 4
0
def test_vcs_pass_save(mock_pexpect, tmpdir, monkeypatch):
    monkeypatch.setenv("USER", "dummy-user")

    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")

    repo_dir = tmpdir.join("repo")

    mock_timestamp = Mock()
    mock_timestamp.return_value = "dummy-timestamp"
    monkeypatch.setattr(git, "tag_name_timestamp", mock_timestamp)

    git.vcs_save(gh_cfg=git_cfg, repo_dir=Path(repo_dir))

    mock_run = mock_pexpect.run
    assert mock_run.called
    calls = mock_run.mock_calls

    expected_commands = [
        "git status",
        "git add -A",
        "git commit -m dummy-timestamp",
        "git push",
        "git tag -a dummy-timestamp -m dummy-timestamp",
        "git push --tags",
    ]

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].kwargs["command"] == cmd
Esempio n. 5
0
def test_vcs_pass_status(monkeypatch, tmpdir, mock_pexpect):
    monkeypatch.setenv("USER", "dummy-user")
    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")
    repo_dir = tmpdir.join("repo")

    mock_pexpect.run.return_value = ("nothing to commit", 0)
    result = git.vcs_status(spec=git_cfg, repo_dir=Path(repo_dir))
    assert result == "nothing to commit"
Esempio n. 6
0
def test_vcs_fail_run_auth(monkeypatch, tmpdir, mock_pexpect):
    monkeypatch.setenv("USER", "dummy-user")
    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")
    repo_dir = Path(tmpdir.join("repo"))

    git_rnr = git.git_runner(git_cfg, repo_dir)

    mock_pexpect.run.return_value = ("fake-failure", 1)
    with pytest.raises(RuntimeError) as exc:
        git_rnr.git_clone()

    errmsg = exc.value.args[0]
    assert errmsg == "fake-failure"
Esempio n. 7
0
def test_vcs_pass_save_nochange(monkeypatch, tmpdir, mock_pexpect):
    monkeypatch.setenv("USER", "dummy-user")

    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")

    repo_dir = tmpdir.join("repo")

    mock_pexpect.run.return_value = ("nothing to commit", 0)
    git.vcs_save(gh_cfg=git_cfg, repo_dir=Path(repo_dir))

    mock_run = mock_pexpect.run
    assert mock_run.called
    calls = mock_run.mock_calls

    expected_commands = ["git status"]

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].kwargs["command"] == cmd
Esempio n. 8
0
def test_vcs_pass_prepare_token(mock_pexpect, tmpdir, monkeypatch):
    monkeypatch.setenv("USER", "dummy-user")
    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")
    repo_dir = tmpdir.join("repo")

    git.vcs_prepare(spec=git_cfg, repo_dir=Path(repo_dir))

    mock_run = mock_pexpect.run
    assert mock_run.called
    calls = mock_run.mock_calls

    expected_commands = [
        "git init",
        "git remote add origin [email protected]",
        "git config --local user.email dummy-user",
        "git config --local user.name dummy-user",
        "git config --local push.default matching",
        "git pull origin master",
    ]

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].kwargs["command"] == cmd
Esempio n. 9
0
def test_vcs_pass_run_auth(monkeypatch, tmpdir, mock_pexpect):
    monkeypatch.setenv("USER", "dummy-user")
    git_cfg = config_model.GitSpec(repo="*****@*****.**", token="dummy-token")
    repo_dir = Path(tmpdir.join("repo"))

    git_rnr = git.git_runner(git_cfg, repo_dir)
    mock_run = Mock()
    git_rnr.run = mock_run

    mock_pexpect.run.return_value = ("yipiee!", 0)
    git_rnr.git_clone()

    calls = mock_run.mock_calls
    expected_commands = [
        f"clone [email protected] {repo_dir}",
        "config --local user.email dummy-user",
        "config --local user.name dummy-user",
        "config --local push.default matching",
    ]

    assert len(calls) == len(expected_commands)
    for cmd_i, cmd in enumerate(expected_commands):
        assert calls[cmd_i].args[0] == cmd