Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 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'], mix_stderr=True)
    assert result.exit_code == 1
    assert 'pull request #1 (My test) is no longer open' in result.output
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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