Esempio n. 1
0
"""Test examples from the README."""
import pytest_localstack

s3_service_1 = pytest_localstack.session_fixture(services=["s3"])
s3_service_2 = pytest_localstack.session_fixture(services=["s3"])


def test_sync_buckets(s3_service_1, s3_service_2):
    """Test using multple sessions in one test."""
    s3_1 = s3_service_1.boto3.resource("s3")
    s3_2 = s3_service_2.boto3.resource("s3")

    src_bucket = s3_1.Bucket("src-bucket")
    src_bucket.create()
    src_object = src_bucket.Object("foobar")
    src_object.put(Body=b"Hello world!")

    dest_bucket = s3_2.Bucket("dest-bucket")
    dest_bucket.create()

    _sync_buckets(src_bucket, dest_bucket)

    response = dest_bucket.Object("foobar").get()
    assert response["Body"].read() == b"Hello world!"


def _sync_buckets(src_bucket, dest_bucket):
    for src_obj in src_bucket.objects.all():
        dest_obj = dest_bucket.Object(src_obj.key)
        response = src_obj.get()
        kwargs = {"Body": response["Body"].read()}
Esempio n. 2
0
"""Test sync_buckets.py"""
import boto3
from sync_buckets import sync_buckets

import pytest_localstack

patch = pytest_localstack.patch_fixture(services=["s3"])
localstack_1 = pytest_localstack.session_fixture()
localstack_2 = pytest_localstack.session_fixture()


def test_sync_buckets_patch(patch):
    """Test using patch_fixture."""
    s3 = boto3.resource("s3")
    src_bucket = s3.Bucket("src-bucket")
    src_bucket.create()
    dest_bucket = s3.Bucket("dest-bucket")
    dest_bucket.create()

    src_bucket.put_object(Key="test", Body=b"foobar")

    result = sync_buckets(src_bucket, dest_bucket)
    assert result == 1

    assert len(list(dest_bucket.objects.all())) == 1

    response = dest_bucket.Object("test").get()
    data = response["Body"].read()
    assert data == b"foobar"

Esempio n. 3
0
"""Test examples from the README."""
import pytest_localstack

s3_service_1 = pytest_localstack.session_fixture(services=["s3"])
s3_service_2 = pytest_localstack.session_fixture(services=["s3"])


def test_sync_buckets(s3_service_1, s3_service_2):
    """Test using multple sessions in one test."""
    s3_1 = s3_service_1.boto3.resource("s3")
    s3_2 = s3_service_2.boto3.resource("s3")

    src_bucket = s3_1.Bucket("src-bucket")
    src_bucket.create()
    src_object = src_bucket.Object("foobar")
    src_object.put(Body=b"Hello world!")

    dest_bucket = s3_2.Bucket("dest-bucket")
    dest_bucket.create()

    _sync_buckets(src_bucket, dest_bucket)

    response = dest_bucket.Object("foobar").get()
    assert response["Body"].read() == b"Hello world!"


def _sync_buckets(src_bucket, dest_bucket):
    for src_obj in src_bucket.objects.all():
        dest_obj = dest_bucket.Object(src_obj.key)
        response = src_obj.get()
        kwargs = {"Body": response["Body"].read()}
Esempio n. 4
0
"""Test all services accessible for pytest_localstack.session_fixture."""
import pytest_localstack

localstack = pytest_localstack.session_fixture(scope="module", autouse=True)


def _assert_key_isinstance(result, key, type):
    assert key in result
    assert isinstance(result[key], type)


class TestBotocore(object):
    """Test service accessibility via botocore."""
    def test_apigateway_available(self, localstack):
        client = localstack.botocore.client("apigateway")
        result = client.get_rest_apis()
        assert result["items"] == []

    def test_cloudformation_available(self, localstack):
        client = localstack.botocore.client("cloudformation")
        result = client.list_stacks(StackStatusFilter=[
            "CREATE_IN_PROGRESS",
            "CREATE_FAILED",
            "CREATE_COMPLETE",
            "ROLLBACK_IN_PROGRESS",
            "ROLLBACK_FAILED",
            "ROLLBACK_COMPLETE",
            "DELETE_IN_PROGRESS",
            "DELETE_FAILED",
            "DELETE_COMPLETE",
            "UPDATE_IN_PROGRESS",
"""Test all services accessible for pytest_localstack.session_fixture."""
import pytest_localstack

localstack = pytest_localstack.session_fixture(scope="module", autouse=True)


def _assert_key_isinstance(result, key, type):
    assert key in result
    assert isinstance(result[key], type)


class TestBotocore(object):
    """Test service accessibility via botocore."""

    def test_apigateway_available(self, localstack):
        client = localstack.botocore.client("apigateway")
        result = client.get_rest_apis()
        assert result["items"] == []

    def test_cloudformation_available(self, localstack):
        client = localstack.botocore.client("cloudformation")
        result = client.list_stacks(
            StackStatusFilter=[
                "CREATE_IN_PROGRESS",
                "CREATE_FAILED",
                "CREATE_COMPLETE",
                "ROLLBACK_IN_PROGRESS",
                "ROLLBACK_FAILED",
                "ROLLBACK_COMPLETE",
                "DELETE_IN_PROGRESS",
                "DELETE_FAILED",