def mock_config_manager(mocker: MockerFixture) -> MockerFixture: """Fixture for mocking CONFIG_MANAGER.""" mock = mocker.patch("git_portfolio.config_manager.ConfigManager", autospec=True) mock.return_value.config = c.Config("", "mytoken", ["staticdev/omg", "staticdev/omg2"]) return mock
def test_execute(mock_config_manager: MockerFixture) -> None: """It returns success.""" config_manager = mock_config_manager.return_value config_manager.config = c.Config("", "abc", []) response = cr.ConfigReposUseCase(config_manager).execute(["staticdev/omg"]) assert bool(response) is True assert "gitp repositories successfully configured." == response.value
def __init__(self, config_filename: str = "config.yaml") -> None: """Load config if it exists.""" self.config_folder = os.path.join(os.path.expanduser("~"), ".gitp") self.config_path = os.path.join(self.config_folder, config_filename) if os.path.exists(self.config_path): print("Loading previous config...\n") with open(self.config_path, "r+") as config_file: try: data = yaml.safe_load(config_file) if data: try: self.config = c.Config(**data) return except TypeError: config_file.truncate(0) except yaml.scanner.ScannerError: config_file.truncate(0) self.config = c.Config("", "", [])
def test_config_model_init() -> None: """Verify model initialization.""" github_hostname = "localhost" github_access_token = "mytoken" github_selected_repos = ["staticdev/omg", "staticdev/omg2"] test_config = c.Config(github_hostname, github_access_token, github_selected_repos) assert test_config.github_hostname == github_hostname assert test_config.github_access_token == github_access_token assert test_config.github_selected_repos == github_selected_repos
def test_merge_prs( mock_gh_merge_pr_use_case: MockerFixture, mock_github_service: MockerFixture, mock_prompt_inquirer_prompter: MockerFixture, mock_config_manager: MockerFixture, runner: CliRunner, ) -> None: """It executes gh_merge_pr_use_case.""" config_manager = mock_config_manager.return_value github_service = mock_github_service.return_value github_service.github_username = "******" github_service.config = c.Config("", "abc", ["staticdev/omg"]) runner.invoke(git_portfolio.__main__.merge, ["prs"], prog_name="gitp") mock_gh_merge_pr_use_case(config_manager, github_service).execute.assert_called_once()