Exemplo n.º 1
0
def test_cli_tool_create_pr(cd_to_pr_tool_repo_clone, pr_tool_type):
    git('checkout', 'master')
    git('branch', '-D', 'pr_branch', ignore_error=True)
    git('checkout', '-b', 'pr_branch')
    with open('pr-file', 'w') as f:
        f.write('test pr file')
    git('add', 'pr-file')
    git('commit', '-m', 'pr file')

    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    # PR creation fails when the branch is not pushed.
    result = CliRunner().invoke(
        pr, ['create', '-m', 'test pr', '-b', 'master', '-h', 'pr_branch'],
        mix_stderr=True)
    assert result.exit_code == 1
    assert 'head branch "pr_branch" is not a valid remote tracking branch' in result.output

    # PR should be create when the branch is there.
    git('push', 'origin', '-u', '-f', 'pr_branch')
    result = CliRunner().invoke(
        pr,
        ['create', '-m', 'test pr', '--base', 'master', '--head', 'pr_branch'],
        mix_stderr=True)
    assert result.exit_code == 0
    assert 'Creating pull request:' in result.output
    assert '  pr_branch -> master on' in result.output
    assert 'Created a pull request #1 (test/pr/1)'

    created_pr = git_apple_llvm.pr.main.pr_tool.get_pr_from_number(1)
    assert created_pr.info.author_username == 'pr_branch'
Exemplo n.º 2
0
def test_cli_tool_test_invalid_pr(cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, 'mock')

    result = CliRunner().invoke(pr, ['test', '#1'], mix_stderr=True)
    assert result.exit_code == 1
    assert 'pull request #1 does not exist' in result.output
Exemplo n.º 3
0
def test_cli_tool_test_jenkins_swift_plans(
        cd_to_pr_tool_repo_clone_adjust_jenkins_ci):
    write_config('jenkins-test.foo-bar',
                 '{"username": "******", "token": "123"}')
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool,
                                                    PRToolType.GitHub)

    def request_callback(request, uri, response_headers):
        return [201, response_headers, '']

    url1 = f'{JENKINS_TEST_API_URL}/view/monorepo/job/pr-build-test/buildWithParameters?token=GIT_APPLE_LLVM'
    url1 += '&cause=started%20by%20user%20using%20git%20apple-llvm&pullRequestID=1'
    url1 += '&test_targets=check-llvm'
    httpretty.register_uri(httpretty.POST, url1, body=request_callback)
    result = CliRunner().invoke(pr, ['test', '#1', '--test', 'pr'])
    if result.exit_code != 0:
        raise AssertionError
    if 'Triggering pull request testing for pr #1 by <author>:' not in result.output:
        raise AssertionError
    if 'My test' not in result.output:
        raise AssertionError
    if '✅ requested pr [a-RA] ci job for PR #1' not in result.output:
        raise AssertionError
Exemplo n.º 4
0
def test_list_target(pr_tool_type, cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    mock_tool.create_pull_request('Another 2', 'Stable only!', 'stable')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['list', '--target', 'master'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == '''- [#1] My test
  test/pr/1

  This tests important things

'''
    result = CliRunner().invoke(pr, ['list', '--target', 'stable'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == '''- [#2] Another 2
  test/pr/2

  Stable only!

'''
    result = CliRunner().invoke(pr, ['list', '--target', 'does-not-exist'],
                                mix_stderr=True)
    assert result.exit_code == 0
    assert result.output == ''
Exemplo n.º 5
0
def test_cli_tool_test_closed_pr(pr_tool_type):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things', 'master')
    mock_tool.pull_requests[0].state = PullRequestState.Closed
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['test', '#1'])
    assert result.exit_code == 1
Exemplo n.º 6
0
def test_cli_list(pr_tool_type, cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things', 'master')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['list'])

    assert result.exit_code == 0
    assert result.output == '''- [#1] My test
Exemplo n.º 7
0
def test_cli_tool_test_invalid_pr(cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, 'mock')

    result = CliRunner().invoke(pr, ['test', '#1'])
    if result.exit_code != 1:
        raise AssertionError
    if 'pull request #1 does not exist' not in result.output:
        raise AssertionError
Exemplo n.º 8
0
def test_cli_tool_test_closed_pr(pr_tool_type):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    mock_tool.pull_requests[0].state = PullRequestState.Closed
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['test', '#1'], mix_stderr=True)
    assert result.exit_code == 1
    assert 'pull request #1 (My test) is no longer open' in result.output
Exemplo n.º 9
0
def test_cli_tool_test_swift_ci(pr_tool_type, cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things', 'master')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['test', '#1'])
    assert result.exit_code == 0
    assert 'Triggering pull request testing for pr #1 by <author>:' in result.output
    assert 'My test' in result.output
    assert 'you commented "@swift-ci please test" on the pull request' in result.output
Exemplo n.º 10
0
def test_cli_tool_create_pr_invalid_base(cd_to_pr_tool_repo_clone, pr_tool_type):
    git('checkout', 'master')
    git('branch', '-D', 'pr_branch2', ignore_error=True)
    git('checkout', '-b', 'pr_branch2')
    git('push', 'origin', '-u', '-f', 'pr_branch2')

    mock_tool = MockPRTool()
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)
    # PR creation fails when the branch is not pushed.
    result = CliRunner().invoke(pr, ['create', '-m', 'test pr', '-b', 'mastar', '-h', 'pr_branch2'])
    assert result.exit_code == 1
    assert 'base branch "mastar" is not a valid remote tracking branch' in result.output
Exemplo n.º 11
0
def test_pr_tool_list(pr_tool_type):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things', 'master')
    tool = create_pr_tool(mock_tool, pr_tool_type)
    prs = tool.list()

    assert len(prs) == 1
    assert prs[0].number == 1
    assert prs[0].state == PullRequestState.Open
    assert prs[0].title == 'My test'
    assert prs[0].body_text == 'This tests important things'
    assert prs[0].author_username == '<author>'
    assert prs[0].base_branch == 'master'
Exemplo n.º 12
0
def test_cli_list(pr_tool_type, cd_to_pr_tool_repo):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    git_apple_llvm.pr.main.pr_tool = create_pr_tool(mock_tool, pr_tool_type)

    result = CliRunner().invoke(pr, ['list'])

    if result.exit_code != 0:
        raise AssertionError
    if result.output != '''- [#1] My test
  test/pr/1

  This tests important things

''':
        raise AssertionError
Exemplo n.º 13
0
def test_pr_tool_list(pr_tool_type):
    mock_tool = MockPRTool()
    mock_tool.create_pull_request('My test', 'This tests important things',
                                  'master')
    tool = create_pr_tool(mock_tool, pr_tool_type)
    prs = tool.list()

    if len(prs) != 1:
        raise AssertionError
    if prs[0].number != 1:
        raise AssertionError
    if prs[0].state != PullRequestState.Open:
        raise AssertionError
    if prs[0].title != 'My test':
        raise AssertionError
    if prs[0].body_text != 'This tests important things':
        raise AssertionError
    if prs[0].author_username != '<author>':
        raise AssertionError
    if prs[0].base_branch != 'master':
        raise AssertionError
Exemplo n.º 14
0
 def create_pull(self, title: str, base: str, head: str):
     mock = MockPRTool()
     mock.create_pr(title=title, base_branch=base, head_repo_url=None, head_branch=head)
     self.prs.append(_GitHubPullRequest(mock.pull_requests[0]))
     return self.prs[-1]