Skip to content

Test s3

aws_credentials()

Mocked AWS Credentials for moto.

Source code in backend/archiver/utils/tests/test_s3.py
10
11
12
13
14
15
16
17
@pytest.fixture(scope="function")
def aws_credentials():
    """Mocked AWS Credentials for moto."""
    os.environ["AWS_ACCESS_KEY_ID"] = "testing"
    os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
    os.environ["AWS_SECURITY_TOKEN"] = "testing"
    os.environ["AWS_SESSION_TOKEN"] = "testing"
    os.environ["AWS_DEFAULT_REGION"] = "eu-west-1"

s3(aws_credentials)

Return a mocked S3 client

Source code in backend/archiver/utils/tests/test_s3.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@pytest.fixture(scope="function")
def s3(aws_credentials):
    """
    Return a mocked S3 client
    """
    with mock_aws():
        user = "user"
        password = "pass"
        region = "eu-west-1"
        client = boto3.client(
            's3',
        )

        location = {'LocationConstraint': region}
        client.create_bucket(Bucket="landingzone",
                                    CreateBucketConfiguration=location)
        client.put_object(Bucket="landingzone", Key="test-file", Body="asdf")

        yield S3Storage(url=None, user=user, password=SecretStr(password), region=region)  # type: ignore