Exemple #1
0
def test_notify_setter_invalid(capsys):
    """ GithubReports Class 'notify' Property Setter Invalid Val Test

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

    Expected Result:
      'notify' 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 notify setting was defaulted to False
    assert (not GitHubReportObj._notify)
    assert (not GitHubReportObj.notify)

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

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

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

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

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

    # Test notify is set to default False
    assert (not GitHubReportObj._notify)
    assert (not GitHubReportObj.notify)

    # Call the Setter to enable notify and test the property value is
    # set to True value.
    GitHubReportObj.notify = True
    assert (GitHubReportObj._notify)
    assert (GitHubReportObj.notify)
Exemple #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)