Best Python code snippet using localstack_python
aws_sns.py
Source:aws_sns.py
...76 sns_client().unsubscribe(77 SubscriptionArn=subscription_arn78 )79 print("Unsubscribed " + subscription['Endpoint'])80def opt_in_phone_number(phone_number):81 return sns_client().opt_in_phone_number(82 phoneNumber=phone_number83 )84def publish_message(topic_arn):85 return sns_client().publish(86 TopicArn=topic_arn,87 Message="Hello, you're receiving this because you've subscribed!"88 )89if __name__ == '__main__':90 print(create_topic())91 # print(get_topics())92 # print(get_topic_attributes(TOPIC_ARN))93 # update_topic_attributes(TOPIC_ARN)94 # delete_topic(TOPIC_ARN)95 # print(create_topic())96 # create_email_subscription(TOPIC_ARN, 'YOUR_EMAIL_ADDRESS')97 # create_sms_subscription(TOPIC_ARN, 'YOUR_PHONE_NUMBER')98 # create_sqs_queue_subscription(TOPIC_ARN, QUEUE_ARN)99 # print(get_topic_subscriptions(TOPIC_ARN))100 # print(list_all_subscriptions())101 # print(check_if_phone_number_opted_out('905321613889'))102 # print(list_opted_out_phone_numbers())103 # opt_out_of_email_subscription('YOUR_EMAIL_ADDRESS')104 # opt_out_of_sms_subscription('YOUR_PHONE_NUMBER')105 # opt_in_phone_number('YOUR_PHONE_NUMBER')...
sns.py
Source:sns.py
...58 print('Unsubscribing ' + subscription['Endpoint'])59 subscription_arn = subscription['SubscriptionArn']60 sns_client().unsubscribe(SubscriptionArn=subscription_arn)61 print('Unsubscribed from this topic')62def opt_in_phone_number(phone_number):63 return sns_client().opt_in_phone_number(phoneNumber=phone_number)64def publish_message_to_subscribers(topic_arn):65 return sns_client().publish(66 TopicArn=topic_arn,67 Message='Hello, you are receiving this because you are subscribed!'68 )69if __name__ == '__main__':70 # create_topic()71 # print(get_topics())72 # print(get_topic_attributes())73 # update_topic_attributes()74 # delete_topic()75 # create_email_subscription(TOPIC_ARN, '')76 # create_sms_subscription(TOPIC_ARN, '')77 # create_sqs_queue_subscription(TOPIC_ARN, 'arn:aws:sqs:us-east-2:585973949575:Main-Queue')78 # print(get_topic_subscriptions(TOPIC_ARN))79 # print(check_if_phone_number_opted_out(''))80 # print(list_opted_out_phone_numbers())81 # opt_out_of_email_subscription('')82 # opt_out_of_sms_subscription('')83 # print(opt_in_phone_number(''))...
test_sns.py
Source:test_sns.py
...29class TestOptInPhoneNumber:30 @mock.patch("massgov.pfml.util.aws.sns.create_sns_client")31 def test_success(self, mock_create_sns, mock_sns):32 mock_create_sns.return_value = mock_sns33 sns_util.opt_in_phone_number("+15109283075")34 mock_sns.opt_in_phone_number.assert_called_with(phoneNumber="+15109283075")35 @mock.patch("massgov.pfml.util.aws.sns.create_sns_client")36 def test_invalid_parameter_raises_exception(self, mock_create_sns, mock_sns, caplog):37 mock_create_sns.return_value = mock_sns38 invalid_param = boto3.client("sns", "us-east-1").exceptions.InvalidParameterException(39 error_response={"Error": {"Code": "InvalidParameter"}}, operation_name=""40 )41 mock_opt_in = mock_sns.opt_in_phone_number42 mock_opt_in.side_effect = invalid_param43 with pytest.raises(Exception):44 sns_util.opt_in_phone_number("")45 assert "Invalid parameter in request" in caplog.text46 @mock.patch("massgov.pfml.util.aws.sns.create_sns_client")47 def test_throttled_exception_raises_exception(self, mock_create_sns, mock_sns, caplog):48 mock_create_sns.return_value = mock_sns49 throttled = boto3.client("sns", "us-east-1").exceptions.ThrottledException(50 error_response={"Error": {"Code": "Throttled"}}, operation_name=""51 )52 mock_opt_in = mock_sns.opt_in_phone_number53 mock_opt_in.side_effect = throttled54 with pytest.raises(Exception):55 sns_util.opt_in_phone_number("")...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!