Skip to content
Snippets Groups Projects
testing.py 778 B
Newer Older
Laurent Peuch's avatar
Laurent Peuch committed
from unittest.mock import patch
from moto import mock_aws
Laurent Peuch's avatar
Laurent Peuch committed
class S3StorageTestMixin:
Laurent Peuch's avatar
Laurent Peuch committed
    s3_bucket = "test-bucket"
        s3_mock = mock_aws()
        s3_mock.start()
Laurent Peuch's avatar
Laurent Peuch committed
        resource = boto3.resource("s3", region_name="us-east-1")
        self.s3_bucket = resource.create_bucket(Bucket=self.s3_bucket)
        patched_storage_s3_client = patch(
Laurent Peuch's avatar
Laurent Peuch committed
            "cubicweb_s3storage.storages.S3Storage._s3_client",
            return_value=boto3.client("s3"),
        )
        patched_storage_s3_client.start()
        self._mocks = [
            s3_mock,
            patched_storage_s3_client,
        ]
Laurent Peuch's avatar
Laurent Peuch committed
        super().setUp()
Laurent Peuch's avatar
Laurent Peuch committed
        super().tearDown()
        while self._mocks:
            self._mocks.pop().stop()