| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | import email | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import boto | 
					
						
							|  |  |  | from boto.exception import BotoServerError | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | from moto import mock_ses | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ses | 
					
						
							|  |  |  | def test_verify_email_identity(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  |     conn.verify_email_identity("test@example.com") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     identities = conn.list_identities() | 
					
						
							|  |  |  |     address = identities['ListIdentitiesResponse']['ListIdentitiesResult']['Identities'][0] | 
					
						
							|  |  |  |     address.should.equal('test@example.com') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ses | 
					
						
							|  |  |  | def test_domain_verify(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.verify_domain_dkim("domain1.com") | 
					
						
							|  |  |  |     conn.verify_domain_identity("domain2.com") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     identities = conn.list_identities() | 
					
						
							|  |  |  |     domains = list(identities['ListIdentitiesResponse']['ListIdentitiesResult']['Identities']) | 
					
						
							|  |  |  |     domains.should.equal(['domain1.com', 'domain2.com']) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ses | 
					
						
							|  |  |  | def test_delete_identity(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  |     conn.verify_email_identity("test@example.com") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult']['Identities'].should.have.length_of(1) | 
					
						
							|  |  |  |     conn.delete_identity("test@example.com") | 
					
						
							|  |  |  |     conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult']['Identities'].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ses | 
					
						
							|  |  |  | def test_send_email(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  |     conn.send_email.when.called_with( | 
					
						
							|  |  |  |         "test@example.com", "test subject", | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  |         "test body", "test_to@example.com").should.throw(BotoServerError) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.verify_email_identity("test@example.com") | 
					
						
							|  |  |  |     conn.send_email("test@example.com", "test subject", "test body", "test_to@example.com") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     send_quota = conn.get_send_quota() | 
					
						
							|  |  |  |     sent_count = int(send_quota['GetSendQuotaResponse']['GetSendQuotaResult']['SentLast24Hours']) | 
					
						
							|  |  |  |     sent_count.should.equal(1) | 
					
						
							| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-26 09:17:38 -04:00
										 |  |  | @mock_ses | 
					
						
							|  |  |  | def test_send_html_email(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     conn.send_email.when.called_with( | 
					
						
							|  |  |  |         "test@example.com", "test subject", | 
					
						
							|  |  |  |         "<span>test body</span>", "test_to@example.com", format="html").should.throw(BotoServerError) | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-26 09:17:38 -04:00
										 |  |  |     conn.verify_email_identity("test@example.com") | 
					
						
							|  |  |  |     conn.send_email("test@example.com", "test subject", "<span>test body</span>", "test_to@example.com", format="html") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     send_quota = conn.get_send_quota() | 
					
						
							|  |  |  |     sent_count = int(send_quota['GetSendQuotaResponse']['GetSendQuotaResult']['SentLast24Hours']) | 
					
						
							|  |  |  |     sent_count.should.equal(1) | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_ses | 
					
						
							|  |  |  | def test_send_raw_email(): | 
					
						
							|  |  |  |     conn = boto.connect_ses('the_key', 'the_secret') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     message = email.mime.multipart.MIMEMultipart() | 
					
						
							|  |  |  |     message['Subject'] = 'Test' | 
					
						
							|  |  |  |     message['From'] = 'test@example.com' | 
					
						
							| 
									
										
										
										
											2016-03-08 23:05:17 -06:00
										 |  |  |     message['To'] = 'to@example.com' | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Message body | 
					
						
							|  |  |  |     part = email.mime.text.MIMEText('test file attached') | 
					
						
							|  |  |  |     message.attach(part) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Attachment | 
					
						
							|  |  |  |     part = email.mime.text.MIMEText('contents of test file here') | 
					
						
							|  |  |  |     part.add_header('Content-Disposition', 'attachment; filename=test.txt') | 
					
						
							|  |  |  |     message.attach(part) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  |     conn.send_raw_email.when.called_with( | 
					
						
							|  |  |  |         source=message['From'], | 
					
						
							|  |  |  |         raw_message=message.as_string(), | 
					
						
							|  |  |  |     ).should.throw(BotoServerError) | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     conn.verify_email_identity("test@example.com") | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  |     conn.send_raw_email( | 
					
						
							|  |  |  |         source=message['From'], | 
					
						
							|  |  |  |         raw_message=message.as_string(), | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2013-02-24 23:30:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     send_quota = conn.get_send_quota() | 
					
						
							|  |  |  |     sent_count = int(send_quota['GetSendQuotaResponse']['GetSendQuotaResult']['SentLast24Hours']) | 
					
						
							|  |  |  |     sent_count.should.equal(1) |