Beispiel #1
0
def test_get_credentials_empty_configuration():
    test_obj = JenkinsConfigParser()
    sample_config = StringIO("")
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials("http://localhost:8080") is None
Beispiel #2
0
def test_empty_section():
    test_url = "http://localhost:8080"
    sample_config = StringIO("[http://localhost:8080]")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials(test_url) is None
Beispiel #3
0
def test_get_credentials_anonymous():
    test_url = "http://localhost:8080"
    sample_config = StringIO("""[http://localhost:8080]
username=
password=
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    assert test_obj.get_credentials(test_url) is None
Beispiel #4
0
    def __init__(self, url, credentials=None, ssl_cert=True):
        super(Jenkins, self).__init__()
        self._log = logging.getLogger(__name__)

        # If no explicit credentials provided,
        # load credentials from any config files
        if credentials is None:
            config = JenkinsConfigParser()
            config.read(JenkinsConfigParser.get_default_configfiles())
            creds = config.get_credentials(url)
        else:
            creds = credentials

        self._api = JenkinsAPI(url, creds, ssl_cert)
Beispiel #5
0
def test_get_credentials_no_username():
    test_url = "http://localhost:8080"

    sample_config = StringIO("""[http://localhost:8080]
password=Password123
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    with pytest.raises(InvalidUserParamsError):
        test_obj.get_credentials(test_url)
Beispiel #6
0
def test_get_credentials():
    test_url = "http://localhost:8080"
    expected_username = "******"
    expected_password = "******"

    sample_config = StringIO("""[http://localhost:8080]
username=jdoe
password=Password123
""")
    test_obj = JenkinsConfigParser()
    if six.PY3:
        test_obj.read_file(sample_config)
    else:
        test_obj.readfp(sample_config)

    actual_credentials = test_obj.get_credentials(test_url)
    assert actual_credentials[0] == expected_username
    assert actual_credentials[1] == expected_password