Ejemplo n.º 1
0
def test_get_service_calls(lob: lobotomy.Lobotomy):
    """Should correctly retrieve service calls made."""
    lob.data = {
        "clients": {
            "sts": {
                "get_caller_identity": {
                    "Account": "123"
                }
            }
        }
    }
    session = lob()
    client = session.client("sts")

    assert client.get_caller_identity()["Account"] == "123"
    assert client.get_caller_identity(
    )["Account"] == "123", "Expected to work twice."

    assert len(lob.service_calls) == 2
    assert len(lob.get_service_calls("sts", "get_caller_identity")) == 2
    assert lob.get_service_call("sts", "get_caller_identity", 0)
    assert lob.get_service_call("sts", "get_caller_identity", 1)

    with pytest.raises(IndexError):
        lob.get_service_call("sts", "get_caller_identity", 2)
Ejemplo n.º 2
0
def test_dynamodb_get_item(lobotomized: lobotomy.Lobotomy):
    """Should handle dynamodb.get_item without recursion errors."""
    lobotomized.data = {"clients": {"dynamodb": {"get_item": {}}}}
    session = lobotomized()
    client = session.client("dynamodb")
    client.get_item(TableName="foo", Key={"pk": {"S": "spam"}, "sk": {"S": "ham"}})

    call = lobotomized.get_service_calls("dynamodb", "get_item")[0]
    assert call.request["TableName"] == "foo"
def test_s3_download_file(lobotomized: lobotomy.Lobotomy):
    """Should handle s3.download_file correctly despite it being an augmentation."""
    lobotomized.data = {"clients": {"s3": {"download_file": {}}}}
    session = lobotomized()
    client = session.client("s3")
    client.download_file(Filename="foo", Bucket="bar", Key="baz")

    call = lobotomized.get_service_calls("s3", "download_file")[0]
    assert call.request["Filename"] == "foo"
    assert call.request["Bucket"] == "bar"
    assert call.request["Key"] == "baz"
Ejemplo n.º 4
0
def test_session_properties(lob: lobotomy.Lobotomy):
    """Should return the expected values for session properties."""
    session_data = {
        "profile_name": "foo-bar",
        "region_name": "us-north-1",
        "available_profiles": ["foo-bar", "baz"],
    }
    lob.data = {"session": session_data}
    session = lob()
    assert session.profile_name == "foo-bar"
    assert session.region_name == "us-north-1"
    assert session.available_profiles == ["foo-bar", "baz"]
Ejemplo n.º 5
0
def test_creation_empty_patched(lob: lobotomy.Lobotomy):
    """Should patch an empty lobotomy and then work after setting data manually."""
    lob.data = {
        "clients": {
            "sts": {
                "get_caller_identity": {
                    "Account": "123"
                }
            }
        }
    }
    session = lob()
    client = session.client("sts")
    assert client.get_caller_identity()["Account"] == "123"
    assert len(lob.service_calls) == 1
    assert len(lob.get_service_calls("sts", "get_caller_identity")) == 1
Ejemplo n.º 6
0
def test_credentials(lob: lobotomy.Lobotomy):
    """Should return the expected values for session credentials."""
    credentials = {
        "method": "foo",
        "access_key": "A123",
        "secret_key": "123abc",
        "token": "foobar",
    }
    lob.data = {"session": {"credentials": credentials}}
    session = lob()
    observed = session.get_credentials()
    assert observed.method == "foo"
    assert observed.access_key == "A123"
    assert observed.secret_key == "123abc"
    assert observed.token == "foobar"

    frozen = observed.get_frozen_credentials()
    assert frozen.access_key == "A123"
    assert frozen.secret_key == "123abc"
    assert frozen.token == "foobar"