Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Add test for S3 bucket configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berg <berg.christian@gmail.com>
  • Loading branch information
christianberg committed Feb 8, 2019
1 parent f3ff9b9 commit cbba324
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock
from sevenseconds.helper.aws import get_account_id, get_az_names
from sevenseconds.config.cloudtrail import configure_cloudtrail
from sevenseconds.config.s3 import configure_s3_buckets
from datetime import datetime
import botocore.exceptions

Expand Down Expand Up @@ -129,5 +130,37 @@ def get_trail_status(Name):
configure_cloudtrail(account)


def test_configure_s3_buckets():
config = {
's3_buckets': {
'bucket-1': {
'name': 'bucket-1',
'regions': ['eu-central-1'],
'lifecycle_configuration': {'Rules': [{'x': 'y'}]},
'encryption_config': {'Rules': [{'a': 'b'}]},
'tags': {'foo': 'bar', 'bee': 'baz'}
}
}
}
account = MagicMock(config=config)
s3 = account.session.resource('s3', 'eu-central-1')
bucket = s3.Bucket('bucket-1')
bucket.creation_date = None

configure_s3_buckets(account)

bucket.create.assert_called_once()
s3.BucketLifecycle('bucket-1').put.assert_called_once_with(
LifecycleConfiguration={'Rules': [{'x': 'y'}]})
s3.meta.client.put_bucket_encryption.assert_called_once_with(
Bucket='bucket-1',
ServerSideEncryptionConfiguration={'Rules': [{'a': 'b'}]})
bucket.Tagging().put.assert_called_once_with(
Tagging={'TagSet': [
{'Key': 'foo', 'Value': 'bar'},
{'Key': 'bee', 'Value': 'baz'}
]})


if __name__ == '__main__':
pytest.main()

0 comments on commit cbba324

Please sign in to comment.