import json import os from os import path import boto3 import pytest from moto import mock_s3, mock_sts from dae_s3_consumer_events_distribution_lambda.const import S3BucketRoleVariable, S3BucketVariable from . import FIXTURES_PATH @pytest.fixture(scope='function') def rti_event(): with open(path.join(FIXTURES_PATH, 'rti.json'), 'r') as fin: yield json.load(fin) @pytest.fixture def lambda_env_config(): os.environ['ENVIRONMENT'] = 'dev' os.environ[S3BucketVariable.RTI] = 'dev-artistapp-notifications-fake' os.environ[S3BucketVariable.APOLLO] = 'dev-apollo-notifications-fake' os.environ[ S3BucketRoleVariable.RTI ] = ('arn:aws:iam::666:role/' 'dev-artistapp-' 'cross_account_notifications_role-fake') os.environ[ S3BucketRoleVariable.APOLLO ] = ('arn:aws:iam::666:role/' 'dev-artistapp-' 'cross_account_notifications_role-fake') @pytest.fixture(scope='function', autouse=True) def aws_credentials(): 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'] = 'us-east-1' boto3.setup_default_session( aws_access_key_id='testing', aws_secret_access_key='testing', aws_session_token='testing', region_name='testing', ) @pytest.fixture def s3(aws_credentials): with mock_s3(): del os.environ['AWS_DEFAULT_REGION'] s3_client = boto3.client('s3') s3_client.create_bucket(Bucket='dev-delphi-notifications-fake') s3_client.create_bucket(Bucket='dev-artistapp-notifications-fake') yield s3_client @pytest.fixture def sts(aws_credentials): with mock_sts(): sts_client = boto3.client('sts') yield sts_client