Exemplo n.º 1
0
def test_save_config_no_file(tmp_path: Path,
                             mock_os_join_path: MockerFixture) -> None:
    """It raises AttributeError."""
    d = tmp_path
    mock_os_join_path.side_effect = [str(d), str(d / "config.yaml")]
    manager = cm.ConfigManager()
    with pytest.raises(AttributeError):
        manager.save_config()
Exemplo n.º 2
0
def test_init_invalid_config(tmp_path: Path,
                             mock_os_join_path: MockerFixture) -> None:
    """It trucantes the file."""
    filename = "config1.yaml"
    d = tmp_path
    p = d / filename
    p.write_text("in:valid")
    mock_os_join_path.side_effect = [str(d), str(p)]
    cm.ConfigManager()
Exemplo n.º 3
0
def test_save_config_empty_file(tmp_path: Path,
                                mock_os_join_path: MockerFixture) -> None:
    """It raises AttributeError."""
    filename = "config2.yaml"
    d = tmp_path
    p = d / filename
    p.write_text("")
    mock_os_join_path.side_effect = [str(d), str(p)]
    manager = cm.ConfigManager(filename)
    with pytest.raises(AttributeError):
        manager.save_config()
Exemplo n.º 4
0
def test_save_invalid_yaml(tmp_path: Path,
                           mock_os_join_path: MockerFixture) -> None:
    """It trucantes the file."""
    filename = "config.yaml"
    content = ("github_access_token: aaaaabbbbbccccc12345"
               "github_hostname: ''"
               "github_selected_repos:"
               " - staticdev/test")
    d = tmp_path
    p = d / filename
    p.write_text(content)
    mock_os_join_path.side_effect = [str(d), str(p)]
    cm.ConfigManager()
Exemplo n.º 5
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()
Exemplo n.º 6
0
import git_portfolio.config_manager as cm
import git_portfolio.domain.config as c
import git_portfolio.domain.gh_connection_settings as cs
import git_portfolio.github_service as ghs
import git_portfolio.prompt as p
import git_portfolio.response_objects as res
import git_portfolio.use_cases.config_init_use_case as ci
import git_portfolio.use_cases.config_repos_use_case as cr
import git_portfolio.use_cases.gh_create_issue_use_case as ghci
import git_portfolio.use_cases.gh_create_pr_use_case as ghcp
import git_portfolio.use_cases.gh_delete_branch_use_case as ghdb
import git_portfolio.use_cases.gh_merge_pr_use_case as ghmp
import git_portfolio.use_cases.git_use_case as guc

F = TypeVar("F", bound=Callable[..., Any])
CONFIG_MANAGER = cm.ConfigManager()


def gitp_config_check(func: F) -> F:
    """Validate if there are selected repos and outputs success."""
    @functools.wraps(func)
    def wrapper(*args: Any, **kwargs: Any) -> Any:
        if CONFIG_MANAGER.config_is_empty():
            click.secho(
                "Error: no config found, please run `gitp config init`.",
                fg="red",
            )
        else:
            value = func(*args, **kwargs)
            _echo_outputs(value)
            return value