def request_pull(self, github_token, repo_name, branch_name): print("Entering method requestpull(**********, " + repo_name + "," + branch_name + ")") gitator = Gitator() gitator.create_github_connection(github_token) gitator.check_repo_existence(repo_name) if branch_name == 'merge_back': branch_list = gitator.list_branches(repo_name) gitator.delete_prs(repo_name) branch_name_origin = 'master' for branch in branch_list: branch_name_destination = branch.name i = gitator.create_issue(repo_name, branch_name_origin, branch_name_destination) gitator.create_pr(repo_name, branch_name_origin, branch_name_destination, i) else: branch_name_origin = branch_name branch_name_destination = 'master' if not gitator.check_branch_existence(repo_name, branch_name_origin): raise Exception('Branch not found.') i = gitator.create_issue(repo_name, branch_name_origin, branch_name_destination) gitator.create_pr(repo_name, branch_name_origin, branch_name_destination, i)
def test_check_branch_existence_good(): thing = Gitator() thing.create_github_connection = MagicMock() thing.g = MagicMock() repo = create_autospec(Repository, instance=True) repo.get_branch = MagicMock() thing.g.get_repo = MagicMock(return_value=repo) assert thing.check_branch_existence('repo_name', 'branch_name') == True repo.get_branch.assert_called_once_with('branch_name')
def test_check_branch_existence_bad(): thing = Gitator() thing.create_github_connection = MagicMock() thing.g = MagicMock() repo = create_autospec(Repository, instance=True) ex = Exception() ex.status = 500 ex.message = "Problem talking to github" repo.get_branch = MagicMock(side_effect=ex) thing.g.get_repo = MagicMock(return_value=repo) with pytest.raises(Exception) as ex: assert thing.check_branch_existence('repo_name', 'branch_name') == False assert str(ex.value.message) == "Problem talking to github" repo.get_branch.assert_called_once_with('branch_name')