예제 #1
0
def test_search_open_pulls_no_namespace_3(capsys):
    """ GithubReports Class 'test_search_open_pulls' Method Test

    This test will test the 'test_search_open_pulls' method. The method
    is designed to run a search against Github for number of open PRs
    across a given organization or user account.

    This test will attempt to call the search_open_pulls() method
    without a or repo_namespace configured. auth_token will be tested
    by being passed as a method argument.

    Expected Result:
        return object should be None.
        Log Error no repo_namespace
    """
    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports(verbose=True)
    assert (isinstance(GitHubReportObj, object))

    assert (GitHubReportObj.auth_token is None)
    assert (GitHubReportObj.repo_namespace is None)

    # Call the method
    search_results = GitHubReportObj.search_open_pulls(
        auth_token="12345678910987654321")
    assert (GitHubReportObj.auth_token == "12345678910987654321")
    assert (GitHubReportObj.repo_namespace is None)
    assert (search_results is None)

    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    assert "ERROR   CLS->GitHubReports.search_open_pulls: \
-> Github repo_namespace required to call this method" in err
예제 #2
0
def test_search_open_pulls_invalid_token_2(capsys):
    """ GithubReports Class 'test_search_open_pulls' Method Test

    This test will test the 'test_search_open_pulls' method. The method
    is designed to run a search against Github for number of open PRs
    across a given organization or user account.

    This test will attempt to call the search_open_pulls() method
    with an invalid auth token. Auth Token will be set at
    init, and repo_namespace will be tested by passing the value
    as a method argument. As the auth_token will be invalid, a Github object
    instantiation exception should be triggered and Error logged.

    Expected Result:
        return object should be None.
        Log Error Bad Credentials Exception
    """
    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports(verbose=True,
                                    auth_token="12345678910987654321")
    assert (isinstance(GitHubReportObj, object))

    assert (GitHubReportObj.auth_token == "12345678910987654321")
    assert (GitHubReportObj.repo_namespace is None)

    # search_results = None
    # Call the Search method, and expect Bad Credentials exception
    # with pytest.raises(
    #     Exception,
    #     match=r'401 {"message": "Bad credentials"'
    # ):
    #     # Call Search, expect BadCredentials Exception
    #     search_results = GitHubReportObj.search_open_pulls(
    #         repo_namespace="TheCloudMage"
    #     )

    # Call the Search method, and expect Bad Credentials exception
    search_results = GitHubReportObj.search_open_pulls(
        repo_namespace="TheCloudMage")

    assert (GitHubReportObj.repo_namespace == "TheCloudMage")
    assert (search_results is None)

    # Call the method
    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    assert "EXCEPTION occurred in" in err
    assert "401 {\"message\": \"Bad credentials\"" in err
예제 #3
0
def test_search_open_pulls_github_except(capsys):
    """ GithubReports Class 'test_search_open_pulls' Method Test

    This test will test the 'test_search_open_pulls' method. The method
    is designed to run a search against Github for number of open PRs
    across a given organization or user account.

    This test will attempt to call the search_open_pulls() method
    with the AuthToken set to a forced bad value. Instantiation of
    the PyGithub Object should result in an Exception Condition.

    Expected Result:
        Github Object Instantiation should cause Exception.
    """
    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports(verbose=True,
                                    auth_token="12345678910987654321")

    # Force set a bad Auth Token Value
    GitHubReportObj._auth_token = 42
    GitHubReportObj._repo_namespace = "TheCloudMage"
    # Ensure auth_token is set to a bad value
    assert (GitHubReportObj.auth_token == 42)
    assert (GitHubReportObj.repo_namespace == "TheCloudMage")

    # Attempt to call the search method
    search_results = None
    search_results = GitHubReportObj.search_open_pulls()

    # Call the method
    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    # Call the Search method, and expect Bad Credentials exception
    assert "An un-expected error occurred when attempting" in err
    assert "EXCEPTION occurred in" in err
    assert (search_results is None)
예제 #4
0
def test_search_open_pulls(capsys):
    """ GithubReports Class 'test_search_open_pulls' Method Test

    This test will test the 'test_search_open_pulls' method. The method
    is designed to run a search against Github for number of open PRs
    across a given organization or user account.

    This test will grab a valid token from an env export
    (export GITHUB_TOKEN=<Token>) and use the token to make
    a valid open pull request query from Github.

    Expected Result:
        Github Object should be properly returned.
    """
    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports(verbose=True,
                                    auth_token=os.environ['GITHUB_TOKEN'])

    # Attempt to call the search method
    assert (not GitHubReportObj.is_organization)
    assert (GitHubReportObj._search_results is None)
    assert (GitHubReportObj._repo_namespace is None)
    assert (GitHubReportObj.auth_token == os.environ['GITHUB_TOKEN'])

    GitHubReportObj.notify = True
    search_results = GitHubReportObj.search_open_pulls(repo_namespace="rnason")
    assert (GitHubReportObj._notify)
    GitHubReportObj.notify = False
    assert (not GitHubReportObj._notify)

    GitHubReportObj.is_organization = True
    search_results = GitHubReportObj.search_open_pulls(repo_namespace="CFWiP")
    assert (GitHubReportObj._is_organization)
    assert (GitHubReportObj._repo_namespace == "CFWiP")
    assert (not bool(GitHubReportObj._search_results))
    assert (search_results is None)

    # Call the method
    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    # Call the Search method, and expect Bad Credentials exception
    assert "0 results returned, exiting search function..." in out

    # Now that 0 results have been tested, poll an organization with
    # an Open PR
    search_results = GitHubReportObj.search_open_pulls(
        repo_namespace="CloudMages")
    assert (GitHubReportObj._is_organization)
    assert (GitHubReportObj._repo_namespace == "CloudMages")
    assert (bool(GitHubReportObj._search_results))
    assert (search_results is not None)

    # Call the method
    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    # Call the Search method, and expect Bad Credentials exception
    assert ("of the returned search results were verified "
            "as open pull requests" in out)