Ejemplo n.º 1
0
def test_is_organization_setter_invalid(capsys):
    """ GithubReports Class 'is_organization' Property Setter Invalid Val Test

    This test will test the 'is_organization' getter and setter property
    methods. Default value tested during init test, test setting value to
    invalid value using the property setter method.

    Expected Result:
      'is_organization' property should be set to False,
      ignoring the invalid value.
    """

    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports()
    assert (isinstance(GitHubReportObj, object))

    # Test is_organization setting was defaulted to False
    assert (not GitHubReportObj._is_organization)
    assert (not GitHubReportObj.is_organization)

    # Set is_organization to an invalid value using property settter and
    # test the value ensuring that the invalid value was ignored, and is
    # set False.
    GitHubReportObj.is_organization = 42
    assert (not GitHubReportObj._is_organization)
    assert (not GitHubReportObj.is_organization)

    # Capture stdout, stderr to test log messages
    out, err = capsys.readouterr()
    # sys.stdout.write(out)
    # sys.stderr.write(err)
    assert "ERROR   CLS->GitHubReports.is_organization: \
-> is_organization property argument expected type bool but received " in err
Ejemplo n.º 2
0
def test_is_organization_setter_enabled():
    """ GithubReports Class 'is_organization' Property Setter Test

    This test will test the 'is_organization' getter and setter property
    methods. Default value tested during init test, test setting value to
    true using the class 'is_organization' setter method.

    Expected Result:
      'is_organization' property should be set to True.
    """

    # Instantiate a GithubReports object, and test for expected test values.
    GitHubReportObj = GithubReports()
    assert (isinstance(GitHubReportObj, object))

    # Test is_organization is set to default False
    assert (not GitHubReportObj._is_organization)
    assert (not GitHubReportObj.is_organization)

    # Call the Setter to enable is_organization and test the property value is
    # set to True value.
    GitHubReportObj.is_organization = True
    assert (GitHubReportObj._is_organization)
    assert (GitHubReportObj.is_organization)
Ejemplo n.º 3
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)