def iris_infrastructure(): mock_sqs().start() mock_sns().start() sns_res = boto3.resource('sns', region_name=test_iris_settings.AWS_REGION) sqs_res = boto3.resource('sqs', region_name=test_iris_settings.AWS_REGION) topic = sns_res.create_topic(Name=test_iris_settings.IRIS_SNS_TOPIC) queue = sqs_res.create_queue( QueueName=test_iris_settings.IRIS_SQS_APP_QUEUE) queue_arn = queue.attributes['QueueArn'] topic_arn = topic.arn sns_res.meta.client.subscribe(TopicArn=topic_arn, Protocol='sqs', Endpoint=queue_arn) yield { 'sns_res': sns_res, 'sqs_res': sqs_res, 'topic': topic, 'queue': queue, 'topic_arn': topic_arn, 'queue_arn': queue_arn } mock_sns().stop() mock_sqs().stop()
def sns(): mock_sns().start() client = boto3.client("sns", region_name="us-west-2") yield client mock_sns().stop()
def moto_start(set_region): mock_autoscaling().start() mock_ec2().start() mock_ecs().start() mock_sns().start() mock_sqs().start() yield mock_autoscaling().stop() mock_ec2().stop() mock_ecs().stop() mock_sns().stop() mock_sqs().stop()
def _handle_sns_topic(resources): from moto import mock_sns sns = mock_sns() def before(): sns.start() for resource_definition in resources: if resource_definition["Properties"].get("TopicName"): boto3.resource("sns").create_topic( Name=resource_definition["Properties"]["TopicName"]) def after(): sns_client = boto3.client("sns") topic_arns = { arn["TopicArn"].split(":")[-1]: arn["TopicArn"] for arn in sns_client.list_topics()["Topics"] } for resource_definition in resources: if resource_definition["Properties"].get("TopicName"): sns_client.delete_topic(TopicArn=topic_arns[ resource_definition["Properties"]["TopicName"]]) sns.stop() return before, after
def sns_topic(): with mock_sns(): sns = resource('sns') topic = sns.create_topic(Name=environ.get('SNS_TOPIC_NAME')) environ['DATA_UPDATE_TOPIC'] = topic.arn environ['NEW_REPORT_TOPIC'] = topic.arn environ['DELETE_REPORT_TOPIC'] = topic.arn yield topic
def sns(aws_credentials): """Mocked S3 Fixture.""" from consoleme.config import config with mock_sns(): yield boto3.client( "sns", region_name="us-east-1", **config.get("boto3.client_kwargs", {}) )
def mock_aws_environment(monkeypatch, aws_credentials): with mock_sns(): boto3.setup_default_session() sns = boto3.client('sns') mock_topic = sns.create_topic(Name="some-topic") monkeypatch.setenv("TOPIC_ARN", mock_topic.get('TopicArn')) from sns_lambda import app return app
def setUp(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) self.mock = mock_sns() self.mock.start() current_account_id = "123456789012" region = "us-east-1" self.client = get_boto3_client(profile=None, service="sns", region=region) response = self.client.create_topic(Name=MY_RESOURCE) self.example = SnsTopic(name=MY_RESOURCE, region=region, client=self.client, current_account_id=current_account_id) self.topics = SnsTopics(client=self.client, current_account_id=current_account_id, region=region)
def moto_topic_arn(): """Creates an SNS topic in moto, and yields the new topic ARN.""" with mock_sns(): sns_client = boto3.client('sns') topic_name = 'test-lambda-topic' resp = sns_client.create_topic(Name=topic_name) topic_arn = resp['TopicArn'] # Our Lambdas all read their topic ARN from the environment, so we # set it here. os.environ.update({'TOPIC_ARN': topic_arn}) yield topic_arn
def requireMocking(): """ method which should be called before all other methods in tests. It basically configures our mocking context for stasis """ bucket = moto.mock_s3() bucket.start() sns = moto.mock_sns() sns.start() sqs = moto.mock_sqs() sqs.start() dynamo = moto.mock_dynamodb2() dynamo.start() lamb = moto.mock_lambda() lamb.start() ecs = moto.mock_ecs() ecs.start() ec2 = moto.mock_ec2() ec2.start() ecr = moto.mock_ecr() ecr.start() session = boto3.session.Session() session.client('sns') session.client('s3') dynamodb = boto3.resource('dynamodb') yield sqs.stop() sns.stop() dynamo.stop() lamb.stop() bucket.stop() ecs.stop() ec2.stop() ecr.stop() pass
def moto_start(set_region): mock_sns().start() mock_sqs().start() yield mock_sns().stop() mock_sqs().stop()
def sns(aws_credentials): """Mocked S3 Fixture.""" with mock_sns(): yield boto3.client("sns", region_name="us-east-1")
def decorate(cls, func): return moto.mock_sqs(moto.mock_sns(responses.activate(func)))
def sns_client(aws_credentials): with mock_sns(): snsc = boto3.client('sns', region_name="us-east-1") yield snsc
def mocked_sns(boto_session, settings): with mock_sns(): settings.SNS_CLIENT = boto_session.client('sns') settings.SNS_CLIENT.create_topic(Name=settings.SNS_ARN.rsplit(':', 1)[1]) yield settings.SNS_CLIENT
def sns(aws_credentials): with mock_sns(): conn = boto3.client("sns") yield conn
def decorate(cls, func): return moto.mock_sqs(moto.mock_sns(responses.activate(func)))
def sns_client(aws_credentials): with mock_sns(): yield boto3.client("sns")
def mocked_sns(): with mock_sns() as mocked_sns: cli = boto3.client("sns", region_name="us-east-1") cli.create_topic(Name="some-forecast-notification-topic") yield cli
import re import time import zlib import boto3 from moto import mock_s3, mock_sns from stream_alert.rule_processor.handler import StreamAlert from stream_alert_cli.logger import LOGGER_CLI, LOGGER_SA # import all rules loaded from the main handler # pylint: disable=unused-import import stream_alert.rule_processor.main # pylint: enable=unused-import BOTO_MOCKER_S3 = mock_s3() BOTO_MOCKER_SNS = mock_sns() DIR_RULES = 'test/integration/rules' DIR_TEMPLATES = 'test/integration/templates' COLOR_RED = '\033[0;31;1m' COLOR_YELLOW = '\033[0;33;1m' COLOR_GREEN = '\033[0;32;1m' COLOR_RESET = '\033[0m' def report_output(cols, failed): """Helper function to pretty print columns Args: cols: A list of columns to print (service, test description) failed: Boolean indicating if this rule failed """
def sns(region_name): with moto.mock_sns(): yield boto3.client('sns', region_name=region_name)
def sns(): with mock_sns(): yield boto3.resource('sns')
def setUp(self): self.sns_mock = moto.mock_sns() self.sns_mock.start() self.sqs_mock = moto.mock_sqs() self.sqs_mock.start()