How to use set_subscription_attributes method in localstack

Best Python code snippet using localstack_python

test_set_filter_policy.py

Source:test_set_filter_policy.py Github

copy

Full Screen

1import pytest2import set_filter_policy3SUBSCRIPTION_ARN = 'theSubscription'4FILTER_POLICY = '{"pet": ["dog", "cat"]}'5def test_create(mocker):6 mocker.patch.object(set_filter_policy, 'SNS')7 response = set_filter_policy.create(_mock_event(), None)8 assert response == {9 'Status': 'SUCCESS',10 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'11 }12 set_filter_policy.SNS.set_subscription_attributes.assert_called_with(13 SubscriptionArn=SUBSCRIPTION_ARN,14 AttributeName='FilterPolicy',15 AttributeValue=FILTER_POLICY16 )17def test_create_sns_exception(mocker):18 mocker.patch.object(set_filter_policy, 'SNS')19 set_filter_policy.SNS.set_subscription_attributes.side_effect = Exception('boom!')20 response = set_filter_policy.create(_mock_event(), None)21 assert response == {22 'Status': 'FAILED',23 'Reason': 'Error setting subscription filter policy: boom!',24 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'25 }26def test_update(mocker):27 mocker.patch.object(set_filter_policy, 'SNS')28 response = set_filter_policy.update(_mock_event(), None)29 assert response == {30 'Status': 'SUCCESS',31 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'32 }33 set_filter_policy.SNS.set_subscription_attributes.assert_called_with(34 SubscriptionArn=SUBSCRIPTION_ARN,35 AttributeName='FilterPolicy',36 AttributeValue=FILTER_POLICY37 )38def test_update_sns_exception(mocker):39 mocker.patch.object(set_filter_policy, 'SNS')40 set_filter_policy.SNS.set_subscription_attributes.side_effect = Exception('boom!')41 response = set_filter_policy.update(_mock_event(), None)42 assert response == {43 'Status': 'FAILED',44 'Reason': 'Error setting subscription filter policy: boom!',45 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'46 }47def test_delete(mocker):48 mocker.patch.object(set_filter_policy, 'SNS')49 response = set_filter_policy.delete(_mock_event(), None)50 assert response == {51 'Status': 'SUCCESS',52 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'53 }54 set_filter_policy.SNS.set_subscription_attributes.assert_called_with(55 SubscriptionArn=SUBSCRIPTION_ARN,56 AttributeName='FilterPolicy',57 AttributeValue='{}'58 )59def test_delete_sns_exception(mocker):60 mocker.patch.object(set_filter_policy, 'SNS')61 set_filter_policy.SNS.set_subscription_attributes.side_effect = Exception('boom!')62 response = set_filter_policy.delete(_mock_event(), None)63 assert response == {64 'Status': 'FAILED',65 'Reason': 'Error setting subscription filter policy: boom!',66 'PhysicalResourceId': SUBSCRIPTION_ARN + '-filterpolicy'67 }68def _mock_event():69 return {70 'ResourceProperties': {71 'SubscriptionArn': SUBSCRIPTION_ARN,72 'FilterPolicy': FILTER_POLICY73 }...

Full Screen

Full Screen

fanout.py

Source:fanout.py Github

copy

Full Screen

...26 Protocol="sqs",27 Endpoint=queue_arn,28 )["SubscriptionArn"]29 return cls(topic_arn, queue_url, queue_arn, subscription_arn)30 def set_subscription_attributes(self, model_name):31 attribute_value = {"model": [model_name]}32 self.sns.set_subscription_attributes(33 SubscriptionArn=self.subscription_arn,34 AttributeName='FilterPolicy',35 AttributeValue=json.dumps(attribute_value)36 )37 def set_queue_attributes(self):38 policy_json = {39 "Version": "2012-10-17",40 "Statement": [41 {42 "Sid": "MyPolicy",43 "Effect": "Allow",44 "Principal": {"AWS": "*"},45 "Action": "SQS:SendMessage",46 "Resource": self.queue_arn,47 "Condition": {48 "ArnEquals": {49 "aws:SourceArn": self.topic_arn50 }51 }52 }53 ]54 }55 self.sqs.set_queue_attributes(56 QueueUrl=self.queue_url,57 Attributes={58 'Policy': json.dumps(policy_json)59 }60 )61if __name__ == '__main__':62 topic_name = "topic_x"63 queue_names = ["queue_a", "queue_b", "queue_c"]64 for queue_name in queue_names:65 fan_out = Fanout.create(queue_name, topic_name)66 fan_out.set_subscription_attributes(queue_name)...

Full Screen

Full Screen

sns_publisher.py

Source:sns_publisher.py Github

copy

Full Screen

...11 TopicArn=topic_arn,12 Protocol='sqs',13 Endpoint='arn:aws:sqs:us-east-1:000000000000:shadow-ui-local'14)['SubscriptionArn']15sns.set_subscription_attributes(16 SubscriptionArn=bts_subscription_arn,17 AttributeName='FilterPolicy',18 AttributeValue='{"channel": "bts"}'19)20sns.set_subscription_attributes(21 SubscriptionArn=ui_subscription_arn,22 AttributeName='FilterPolicy',23 AttributeValue='{"channel": "ui"}'24)25def publish_message(sqs_message: str, channel: str):26 return sns.publish(27 TopicArn=topic_arn,28 Message=sqs_message,29 MessageAttributes={30 "channel": {31 'DataType': 'String',32 'StringValue': channel33 }34 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful