コード例 #1
0
def test_set_iam_properties_provider_assigned(mocker, provider):
    test_input, expectedProvider = provider
    mocker.patch(
        "redshift_connector.plugin.{}.get_credentials".format(test_input))
    rp: RedshiftProperty = make_redshift_property()
    rp.credentials_provider = test_input

    spy = mocker.spy(expectedProvider, "add_parameter")

    IamHelper.set_iam_credentials(rp)
    assert spy.called
    assert spy.call_count == 1
    # ensure call to add_Parameter was made on the expected Provider class
    assert isinstance(spy.call_args[0][0], expectedProvider) is True
コード例 #2
0
def test_dynamically_loading_credential_holder(mocker):
    external_class_name: str = "test.unit.MockCredentialsProvider"
    mocker.patch("{}.get_credentials".format(external_class_name))
    mocker.patch(
        "redshift_connector.iam_helper.IamHelper.set_cluster_credentials",
        return_value=None)
    rp: RedshiftProperty = make_redshift_property()
    rp.credentials_provider = external_class_name

    spy = mocker.spy(MockCredentialsProvider, "add_parameter")

    IamHelper.set_iam_credentials(rp)
    assert spy.called
    assert spy.call_count == 1
    # ensure call to add_Parameter was made on the expected Provider class
    assert isinstance(spy.call_args[0][0], MockCredentialsProvider) is True
コード例 #3
0
def test_set_iam_credentials_via_aws_credentials(mocker):
    redshift_property: RedshiftProperty = RedshiftProperty()
    redshift_property.profile = "profile_val"
    redshift_property.access_key_id = "access_val"
    redshift_property.secret_access_key = "secret_val"
    redshift_property.session_token = "session_val"

    mocker.patch(
        "redshift_connector.iam_helper.IamHelper.set_cluster_credentials",
        return_value=None)
    spy = mocker.spy(AWSCredentialsProvider, "add_parameter")

    IamHelper.set_iam_credentials(redshift_property)
    assert spy.called is True
    assert spy.call_count == 1
    assert spy.call_args[0][1] == redshift_property