def test_create_branch_good(): thing = Gitator() thing.create_github_connection = MagicMock() github_connection = create_autospec(Github) thing.g = github_connection repo = create_autospec(Repository.Repository, instance=True) github_connection.get_repo = MagicMock(return_value=repo) # thing.run_checks = MagicMock(return_value=True) assert thing.create_branch("repo_name", "branch_name", "commit_sha") == True repo.create_git_ref.assert_called_once_with("refs/heads/branch_name", "commit_sha")
def test_create_branch_bad(): thing = Gitator() thing.create_github_connection = MagicMock() github_connection = create_autospec(Github) thing.g = github_connection repo = create_autospec(Repository.Repository, instance=True) github_connection.get_repo = MagicMock(return_value=repo) repo.create_git_ref = MagicMock( side_effect=Exception("Problem branching.")) with pytest.raises(Exception) as ex: assert thing.create_branch("repo_name", "branch_name", "commit_sha") == False assert str(ex.value) == "Problem branching." repo.create_git_ref.assert_called_once_with("refs/heads/branch_name", "commit_sha")