How to use ses method in localstack

Best Python code snippet using localstack_python

test_ses_receipt_handler.py

Source:test_ses_receipt_handler.py Github

copy

Full Screen

...23 filter_name, ip_address_or_range, allow, error_code=error_code)24 if error_code is None:25 ses_receipt.create_receipt_filter(filter_name, ip_address_or_range, allow)26 else:27 with pytest.raises(ClientError) as exc_info:28 ses_receipt.create_receipt_filter(filter_name, ip_address_or_range, allow)29 assert exc_info.value.response['Error']['Code'] == error_code30@pytest.mark.parametrize("error_code", [None, 'TestException'])31def test_list_receipt_filters(make_stubber, error_code):32 ses_client = boto3.client('ses')33 ses_stubber = make_stubber(ses_client)34 ses_receipt = SesReceiptHandler(ses_client, None)35 filters = [{36 'Name': f'test_filter-{index}',37 'IpFilter': {'Cidr': '0.0.0.0', 'Policy': 'Allow'}38 } for index in range(3)]39 ses_stubber.stub_list_receipt_filters(filters, error_code=error_code)40 if error_code is None:41 got_filters = ses_receipt.list_receipt_filters()42 assert got_filters == filters43 else:44 with pytest.raises(ClientError) as exc_info:45 ses_receipt.list_receipt_filters()46 assert exc_info.value.response['Error']['Code'] == error_code47@pytest.mark.parametrize("error_code", [None, 'TestException'])48def test_delete_receipt_filter(make_stubber, error_code):49 ses_client = boto3.client('ses')50 ses_stubber = make_stubber(ses_client)51 ses_receipt = SesReceiptHandler(ses_client, None)52 filter_name = 'test-filter'53 ses_stubber.stub_delete_receipt_filter(filter_name, error_code=error_code)54 if error_code is None:55 ses_receipt.delete_receipt_filter(filter_name)56 else:57 with pytest.raises(ClientError) as exc_info:58 ses_receipt.delete_receipt_filter(filter_name)59 assert exc_info.value.response['Error']['Code'] == error_code60@pytest.mark.parametrize("error_code", [None, 'TestException'])61def test_create_receipt_rule_set(make_stubber, error_code):62 ses_client = boto3.client('ses')63 ses_stubber = make_stubber(ses_client)64 ses_receipt = SesReceiptHandler(ses_client, None)65 rule_set_name = 'test-rule-set'66 ses_stubber.stub_create_receipt_rule_set(rule_set_name, error_code=error_code)67 if error_code is None:68 ses_receipt.create_receipt_rule_set(rule_set_name)69 else:70 with pytest.raises(ClientError) as exc_info:71 ses_receipt.create_receipt_rule_set(rule_set_name)72 assert exc_info.value.response['Error']['Code'] == error_code73@pytest.mark.parametrize("error_code,stop_on_method", [74 (None, None),75 ('TestException', 'stub_create_bucket'),76 ('TestException', 'stub_put_bucket_policy')])77def test_create_bucket_for_copy(78 make_stubber, stub_runner, error_code, stop_on_method):79 s3_resource = boto3.resource('s3')80 s3_stubber = make_stubber(s3_resource.meta.client)81 ses_receipt = SesReceiptHandler(None, s3_resource)82 bucket_name = 'doc-example-bucket'83 with stub_runner(error_code, stop_on_method) as runner:84 runner.add(85 s3_stubber.stub_create_bucket, bucket_name,86 region_name=s3_resource.meta.client.meta.region_name)87 runner.add(s3_stubber.stub_head_bucket, bucket_name)88 runner.add(s3_stubber.stub_put_bucket_policy, bucket_name, ANY)89 if stop_on_method == 'stub_put_bucket_policy':90 s3_stubber.stub_delete_bucket(bucket_name)91 if error_code is None:92 got_bucket = ses_receipt.create_bucket_for_copy(bucket_name)93 assert got_bucket.name == bucket_name94 else:95 with pytest.raises(ClientError) as exc_info:96 ses_receipt.create_bucket_for_copy(bucket_name)97 assert exc_info.value.response['Error']['Code'] == error_code98@pytest.mark.parametrize("error_code", [None, 'TestException'])99def test_create_s3_copy_rule(make_stubber, error_code):100 ses_client = boto3.client('ses')101 ses_stubber = make_stubber(ses_client)102 ses_receipt = SesReceiptHandler(ses_client, None)103 rule_set_name = 'test-rule-set'104 rule_name = 'test-rule'105 recipients = ['me', 'myself', 'I']106 bucket_name = 'doc-example-bucket'107 prefix = 'mymails/'108 actions = [{109 'S3Action': {'BucketName': bucket_name, 'ObjectKeyPrefix': prefix}110 }]111 ses_stubber.stub_create_receipt_rule(112 rule_set_name, rule_name, recipients, actions, error_code=error_code)113 if error_code is None:114 ses_receipt.create_s3_copy_rule(115 rule_set_name, rule_name, recipients, bucket_name, prefix)116 else:117 with pytest.raises(ClientError) as exc_info:118 ses_receipt.create_s3_copy_rule(119 rule_set_name, rule_name, recipients, bucket_name, prefix)120 assert exc_info.value.response['Error']['Code'] == error_code121@pytest.mark.parametrize("error_code", [None, 'TestException'])122def test_describe_receipt_rule_set(make_stubber, error_code):123 ses_client = boto3.client('ses')124 ses_stubber = make_stubber(ses_client)125 ses_receipt = SesReceiptHandler(ses_client, None)126 rule_set_name = 'test-rule-set'127 rule_name = 'test-rule'128 recipients = ['me', 'myself', 'I']129 bucket_name = 'doc-example-bucket'130 prefix = 'mymails/'131 actions = [{132 'S3Action': {'BucketName': bucket_name, 'ObjectKeyPrefix': prefix}133 }]134 ses_stubber.stub_describe_receipt_rule_set(135 rule_set_name, rule_name, recipients, actions, error_code=error_code)136 if error_code is None:137 response = ses_receipt.describe_receipt_rule_set(rule_set_name)138 assert response['Metadata']['Name'] == rule_set_name139 rule = response['Rules'][0]140 assert rule['Name'] == rule_name141 assert rule['Recipients'] == recipients142 assert rule['Actions'] == actions143 else:144 with pytest.raises(ClientError) as exc_info:145 ses_receipt.describe_receipt_rule_set(rule_set_name)146 assert exc_info.value.response['Error']['Code'] == error_code147@pytest.mark.parametrize("error_code", [None, 'TestException'])148def test_delete_receipt_rule(make_stubber, error_code):149 ses_client = boto3.client('ses')150 ses_stubber = make_stubber(ses_client)151 ses_receipt = SesReceiptHandler(ses_client, None)152 rule_set_name = 'test-rule-set'153 rule_name = 'test-rule'154 ses_stubber.stub_delete_receipt_rule(155 rule_set_name, rule_name, error_code=error_code)156 if error_code is None:157 ses_receipt.delete_receipt_rule(rule_set_name, rule_name)158 else:159 with pytest.raises(ClientError) as exc_info:160 ses_receipt.delete_receipt_rule(rule_set_name, rule_name)161 assert exc_info.value.response['Error']['Code'] == error_code162@pytest.mark.parametrize("error_code", [None, 'TestException'])163def test_delete_receipt_rule_set(make_stubber, error_code):164 ses_client = boto3.client('ses')165 ses_stubber = make_stubber(ses_client)166 ses_receipt = SesReceiptHandler(ses_client, None)167 rule_set_name = 'test-rule-set'168 ses_stubber.stub_delete_receipt_rule_set(rule_set_name, error_code=error_code)169 if error_code is None:170 ses_receipt.delete_receipt_rule_set(rule_set_name)171 else:172 with pytest.raises(ClientError) as exc_info:173 ses_receipt.delete_receipt_rule_set(rule_set_name)...

Full Screen

Full Screen

test_ses_identities.py

Source:test_ses_identities.py Github

copy

Full Screen

...19 if error_code is None:20 got_token = ses_identity.verify_domain_identity(domain_name)21 assert token == got_token22 else:23 with pytest.raises(ClientError) as exc_info:24 ses_identity.verify_domain_identity(domain_name)25 assert exc_info.value.response['Error']['Code'] == error_code26@pytest.mark.parametrize("error_code", [None, 'TestException'])27def test_verify_email_identity(make_stubber, error_code):28 ses_client = boto3.client('ses')29 ses_stubber = make_stubber(ses_client)30 ses_identity = SesIdentity(ses_client)31 email = 'test@example.com'32 ses_stubber.stub_verify_email_identity(email, error_code=error_code)33 if error_code is None:34 ses_identity.verify_email_identity(email)35 else:36 with pytest.raises(ClientError) as exc_info:37 ses_identity.verify_email_identity(email)38 assert exc_info.value.response['Error']['Code'] == error_code39@pytest.mark.parametrize("error_code", [None, 'TestException'])40def test_wait_until_identity_exists(make_stubber, error_code):41 ses_client = boto3.client('ses')42 ses_stubber = make_stubber(ses_client)43 ses_identity = SesIdentity(ses_client)44 email = 'test@example.com'45 ses_stubber.stub_get_identity_verification_attributes(46 [email], ['Success'], error_code=error_code)47 if error_code is None:48 ses_identity.wait_until_identity_exists(email)49 else:50 with pytest.raises(WaiterError):51 ses_identity.wait_until_identity_exists(email)52@pytest.mark.parametrize("error_code", [None, 'TestException'])53def test_get_identity_status(make_stubber, error_code):54 ses_client = boto3.client('ses')55 ses_stubber = make_stubber(ses_client)56 ses_identity = SesIdentity(ses_client)57 email = 'test@example.com'58 status = 'Pending'59 ses_stubber.stub_get_identity_verification_attributes(60 [email], [status], error_code=error_code)61 if error_code is None:62 got_status = ses_identity.get_identity_status(email)63 assert got_status == status64 else:65 with pytest.raises(ClientError) as exc_info:66 ses_identity.get_identity_status(email)67 assert exc_info.value.response['Error']['Code'] == error_code68@pytest.mark.parametrize("error_code", [None, 'TestException'])69def test_delete_identity(make_stubber, error_code):70 ses_client = boto3.client('ses')71 ses_stubber = make_stubber(ses_client)72 ses_identity = SesIdentity(ses_client)73 email = 'test@example.com'74 ses_stubber.stub_delete_identity(email, error_code=error_code)75 if error_code is None:76 ses_identity.delete_identity(email)77 else:78 with pytest.raises(ClientError) as exc_info:79 ses_identity.delete_identity(email)80 assert exc_info.value.response['Error']['Code'] == error_code81@pytest.mark.parametrize("error_code", [None, 'TestException'])82def test_list_identities(make_stubber, error_code):83 ses_client = boto3.client('ses')84 ses_stubber = make_stubber(ses_client)85 ses_identity = SesIdentity(ses_client)86 identity_type = 'EmailAddress'87 max_items = 588 identities = ['test@example.com', 'anotherone@example.org']89 ses_stubber.stub_list_identities(90 identity_type, max_items, identities, error_code=error_code)91 if error_code is None:92 got_identities = ses_identity.list_identities(identity_type, max_items)93 assert got_identities == identities94 else:95 with pytest.raises(ClientError) as exc_info:96 ses_identity.list_identities(identity_type, max_items)...

Full Screen

Full Screen

test_ses_templates.py

Source:test_ses_templates.py Github

copy

Full Screen

...27 assert template == ses_template.template28 assert {'subject', 'text', 'html'} == ses_template.template_tags29 assert ses_template.verify_tags({'text': 'hi', 'html': '<p>hi</p>'})30 else:31 with pytest.raises(ClientError) as exc_info:32 ses_template.create_template(*template.values())33 assert exc_info.value.response['Error']['Code'] == error_code34@pytest.mark.parametrize("error_code", [None, 'TestException'])35def test_delete_template(make_stubber, error_code):36 ses_client = boto3.client('ses')37 ses_stubber = make_stubber(ses_client)38 ses_template = SesTemplate(ses_client)39 template_name = 'test-template'40 ses_template.template = {'TemplateName': template_name}41 ses_stubber.stub_delete_template(template_name, error_code=error_code)42 if error_code is None:43 ses_template.delete_template()44 else:45 with pytest.raises(ClientError) as exc_info:46 ses_template.delete_template()47 assert exc_info.value.response['Error']['Code'] == error_code48@pytest.mark.parametrize("error_code", [None, 'TestException'])49def test_get_template(make_stubber, error_code):50 ses_client = boto3.client('ses')51 ses_stubber = make_stubber(ses_client)52 ses_template = SesTemplate(ses_client)53 template = make_template('test-template')54 ses_stubber.stub_get_template(*template.values(), error_code=error_code)55 if error_code is None:56 got_template = ses_template.get_template(template['TemplateName'])57 assert got_template == template58 else:59 with pytest.raises(ClientError) as exc_info:60 ses_template.get_template(template['TemplateName'])61 assert exc_info.value.response['Error']['Code'] == error_code62@pytest.mark.parametrize("error_code", [None, 'TestException'])63def test_list_templates(make_stubber, error_code):64 ses_client = boto3.client('ses')65 ses_stubber = make_stubber(ses_client)66 ses_template = SesTemplate(ses_client)67 template_names = [f'test-template-{index}' for index in range(4)]68 ses_stubber.stub_list_templates(template_names, error_code=error_code)69 if error_code is None:70 got_template_metas = ses_template.list_templates()71 assert got_template_metas == [72 {'Name': meta['Name']} for meta in got_template_metas]73 else:74 with pytest.raises(ClientError) as exc_info:75 ses_template.list_templates()76 assert exc_info.value.response['Error']['Code'] == error_code77@pytest.mark.parametrize("error_code", [None, 'TestException'])78def test_update_template(make_stubber, error_code):79 ses_client = boto3.client('ses')80 ses_stubber = make_stubber(ses_client)81 ses_template = SesTemplate(ses_client)82 template = make_template('test-template')83 ses_stubber.stub_update_template(*template.values(), error_code=error_code)84 if error_code is None:85 ses_template.update_template(*template.values())86 else:87 with pytest.raises(ClientError) as exc_info:88 ses_template.update_template(*template.values())...

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