Пример #1
0
def test_repo_namespace_setter_invalid(capsys):
    """ GithubReports Class 'repo_namespace' Property Setter Invalid Val Test

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

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

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

    # Test repo_namespace setting was defaulted to None
    assert (GitHubReportObj._repo_namespace is None)
    assert (GitHubReportObj.repo_namespace is None)

    # Set repo_namespace to an invalid value using property settter and
    # test the value ensuring that the invalid value was ignored,
    # and is set None.
    GitHubReportObj.repo_namespace = 42
    assert (GitHubReportObj._repo_namespace is None)
    assert (GitHubReportObj.repo_namespace 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.repo_namespace: \
-> repo_namespace property argument expected type str but received " in err
Пример #2
0
def test_search_open_pulls_invalid_token(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 using the repo_namespace
    property setter. 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)

    # Set the namespace
    GitHubReportObj.repo_namespace = "TheCloudMage"
    assert (GitHubReportObj.repo_namespace == "TheCloudMage")

    # 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()
    #     assert(search_results is None)
    search_results = GitHubReportObj.search_open_pulls()
    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_repo_namespace_setter_enabled():
    """ GithubReports Class 'repo_namespace' Property Setter Test

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

    Expected Result:
      'repo_namespace' property should be set to provided string value.
    """

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

    # Test repo_namespace is set to default False
    assert (GitHubReportObj._repo_namespace is None)
    assert (GitHubReportObj.repo_namespace is None)

    # Call the Setter to enable repo_namespace and test the property value is
    # set to the provided string value.
    GitHubReportObj.repo_namespace = "TheCloudMage"
    assert (GitHubReportObj._repo_namespace == "TheCloudMage")
    assert (GitHubReportObj.repo_namespace == "TheCloudMage")