Beispiel #1
0
def test_execute_git_not_installed(
    mock_github_service: MockerFixture,
    mock_check_command_installed: MockerFixture,
    mock_popen: MockerFixture,
) -> None:
    """It returns failure with git not installed message."""
    mock_check_command_installed.return_value = "some error msg"
    github_service = mock_github_service.return_value
    mock_popen.side_effect = FileNotFoundError
    response = gcuc.GitCloneUseCase(github_service).execute(["staticdev/omg"])

    mock_check_command_installed.assert_called_with("git")
    assert bool(response) is False
    assert "some error msg" == response.value["message"]
def test_execute_connection_error(
    mock_config_manager: MockerFixture,
    mock_github_service: MockerFixture,
    mock_prompt_inquirer_prompter: MockerFixture,
    domain_gh_conn_settings: cs.GhConnectionSettings,
    mock_config_repos_use_case: MockerFixture,
) -> None:
    """It returns success."""
    config_manager = mock_config_manager.return_value
    mock_github_service.side_effect = ConnectionError
    response = ci.ConfigInitUseCase(config_manager).execute(
        domain_gh_conn_settings)

    assert bool(response) is False
    assert response.type == res.ResponseFailure.SYSTEM_ERROR
def test_execute_attribute_error(
    mock_config_manager: MockerFixture,
    mock_github_service: MockerFixture,
    mock_prompt_inquirer_prompter: MockerFixture,
    domain_gh_conn_settings: cs.GhConnectionSettings,
    mock_config_repos_use_case: MockerFixture,
) -> None:
    """It returns success."""
    config_manager = mock_config_manager.return_value
    mock_github_service.side_effect = AttributeError("msg")
    response = ci.ConfigInitUseCase(config_manager).execute(domain_gh_conn_settings)

    assert bool(response) is False
    assert response.type == res.ResponseTypes.PARAMETERS_ERROR
    assert response.value["message"] == "msg"
Beispiel #4
0
def test_config_repos_wrong_token(
    mock_prompt_inquirer_prompter: MockerFixture,
    mock_github_service: MockerFixture,
    mock_config_manager: MockerFixture,
    runner: CliRunner,
) -> None:
    """It executes _get_github_service with token error."""
    mock_config_manager.config_is_empty.return_value = False
    mock_prompt_inquirer_prompter.new_repos.return_value = True
    mock_github_service.side_effect = AttributeError
    result = runner.invoke(git_portfolio.__main__.configure, ["repos"],
                           prog_name="gitp")

    assert result.output.startswith(
        "Error: Wrong GitHub permissions. Please check your token.\n")
    assert type(result.exception) == SystemExit
Beispiel #5
0
def test_config_repos_connection_error(
    mock_prompt_inquirer_prompter: MockerFixture,
    mock_github_service: MockerFixture,
    mock_config_manager: MockerFixture,
    runner: CliRunner,
) -> None:
    """It executes _get_github_service with token error."""
    mock_config_manager.config_is_empty.return_value = False
    mock_prompt_inquirer_prompter.new_repos.return_value = True
    mock_github_service.side_effect = ConnectionError
    result = runner.invoke(git_portfolio.__main__.configure, ["repos"],
                           prog_name="gitp")

    assert result.output.startswith((
        "Error: Unable to reach server. Please check you network and credentials "
        "and try again.\n"))
    assert type(result.exception) == SystemExit
def test_execute_connection_error(
    mock_config_manager: MockerFixture,
    mock_github_service: MockerFixture,
    mock_prompt_inquirer_prompter: MockerFixture,
    domain_gh_conn_settings: cs.GhConnectionSettings,
    mock_config_repos_use_case: MockerFixture,
) -> None:
    """It returns success."""
    config_manager = mock_config_manager.return_value
    mock_github_service.side_effect = ConnectionError
    response = ci.ConfigInitUseCase(config_manager).execute(domain_gh_conn_settings)

    assert bool(response) is False
    assert response.type == res.ResponseTypes.SYSTEM_ERROR
    assert (
        response.value["message"]
        == "impossible to connect, please check your hostname address and token."
    )
Beispiel #7
0
def test_save_config_success(
    tmp_path: Path,
    mock_yaml_dump: MockerFixture,
    mock_os_join_path: MockerFixture,
) -> None:
    """It dumps yaml config file."""
    filename = "config.yaml"
    content = ("github_access_token: aaaaabbbbbccccc12345\n"
               "github_hostname: ''\n"
               "github_selected_repos:\n"
               " - staticdev/test\n")
    d = tmp_path
    p = d / filename
    p.write_text(content)
    mock_os_join_path.side_effect = [str(d), str(p)]
    manager = cm.ConfigManager()
    manager.save_config()
    mock_yaml_dump.assert_called_once()