How to use validate_email_summary method in mailosaur-python

Best Python code snippet using mailosaur-python_python

emails_test.py

Source:emails_test.py Github

copy

Full Screen

...22 cls.emails = cls.client.messages.list(cls.server).items23 def test_list(self):24 self.assertEqual(5, len(self.emails))25 for email in self.emails:26 self.validate_email_summary(email)27 def test_list_received_after(self):28 past_date = datetime.today() - timedelta(minutes=10)29 past_emails = self.client.messages.list(30 self.server, received_after=past_date).items31 self.assertTrue(len(past_emails) > 0)32 future_emails = self.client.messages.list(33 self.server, received_after=datetime.today()).items34 self.assertEqual(0, len(future_emails))35 def test_get(self):36 host = os.getenv('MAILOSAUR_SMTP_HOST', 'mailosaur.net')37 test_email_address = "wait_for_test@%s.%s" % (self.server, host)38 Mailer.send_email(self.client, self.server, test_email_address)39 criteria = SearchCriteria()40 criteria.sent_to = test_email_address41 email = self.client.messages.get(self.server, criteria)42 self.validate_email(email)43 def test_get(self):44 email_to_retrieve = self.emails[0]45 email = self.client.messages.get_by_id(email_to_retrieve.id)46 self.validate_email(email)47 self.validate_headers(email)48 def test_get_not_found(self):49 with self.assertRaises(MailosaurException):50 self.client.messages.get_by_id(51 "efe907e9-74ed-4113-a3e0-a3d41d914765")52 def test_search_timeout_errors_suppressed(self):53 criteria = SearchCriteria()54 criteria.sent_from = "neverfound@example.com"55 results = self.client.messages.search(56 self.server, criteria, timeout=1, error_on_timeout=False).items57 self.assertEqual(0, len(results))58 def test_search_no_criteria_error(self):59 with self.assertRaises(MailosaurException):60 self.client.messages.search(self.server, SearchCriteria())61 def test_search_by_sent_from(self):62 target_email = self.emails[1]63 criteria = SearchCriteria()64 criteria.sent_from = target_email.sender[0].email65 results = self.client.messages.search(self.server, criteria).items66 self.assertEqual(1, len(results))67 self.assertEqual(68 target_email.sender[0].email, results[0].sender[0].email)69 self.assertEqual(target_email.subject, results[0].subject)70 def test_search_by_sent_to(self):71 target_email = self.emails[1]72 criteria = SearchCriteria()73 criteria.sent_to = target_email.to[0].email74 results = self.client.messages.search(self.server, criteria).items75 self.assertEqual(1, len(results))76 self.assertEqual(target_email.to[0].email, results[0].to[0].email)77 self.assertEqual(target_email.subject, results[0].subject)78 def test_search_by_body(self):79 target_email = self.emails[1]80 unique_string = target_email.subject[0:10]81 criteria = SearchCriteria()82 criteria.body = "%s html" % (unique_string)83 results = self.client.messages.search(self.server, criteria).items84 self.assertEqual(1, len(results))85 self.assertEqual(target_email.to[0].email, results[0].to[0].email)86 self.assertEqual(target_email.subject, results[0].subject)87 def test_search_by_subject(self):88 target_email = self.emails[1]89 unique_string = target_email.subject[0:10]90 criteria = SearchCriteria()91 criteria.subject = unique_string92 results = self.client.messages.search(self.server, criteria).items93 self.assertEqual(1, len(results))94 self.assertEqual(target_email.to[0].email, results[0].to[0].email)95 self.assertEqual(target_email.subject, results[0].subject)96 def test_search_with_match_all(self):97 target_email = self.emails[1]98 unique_string = target_email.subject[0:10]99 criteria = SearchCriteria()100 criteria.subject = unique_string101 criteria.body = "this is a link"102 criteria.match = "ALL"103 results = self.client.messages.search(self.server, criteria).items104 self.assertEqual(1, len(results))105 def test_search_with_match_any(self):106 target_email = self.emails[1]107 unique_string = target_email.subject[0:10]108 criteria = SearchCriteria()109 criteria.subject = unique_string110 criteria.body = "this is a link"111 criteria.match = "ANY"112 results = self.client.messages.search(self.server, criteria).items113 self.assertEqual(4, len(results))114 def test_search_with_special_characters(self):115 criteria = SearchCriteria()116 criteria.subject = "Search with ellipsis … and emoji 👨🏿‍🚒"117 results = self.client.messages.search(self.server, criteria).items118 self.assertEqual(0, len(results))119 def test_spam_analysis(self):120 target_id = self.emails[0].id121 result = self.client.analysis.spam(target_id)122 for rule in result.spam_filter_results.spam_assassin:123 self.assertIsNotNone(rule.rule)124 self.assertIsNotNone(rule.description)125 def test_delete(self):126 target_email_id = self.emails[4].id127 self.client.messages.delete(target_email_id)128 # Attempting to delete again should fail129 with self.assertRaises(MailosaurException):130 self.client.messages.delete(target_email_id)131 def test_create_and_send_with_text(self):132 if self.verified_domain is None:133 pytest.skip("Requires verified domain secret")134 subject = "New message"135 options = MessageCreateOptions(136 "anything@%s" % (self.verified_domain), True, subject, "This is a new email")137 message = self.client.messages.create(self.server, options)138 self.assertIsNotNone(message.id)139 self.assertEqual(subject, message.subject)140 def test_create_and_send_with_html(self):141 if self.verified_domain is None:142 pytest.skip("Requires verified domain secret")143 subject = "New HTML message"144 options = MessageCreateOptions(145 "anything@%s" % (self.verified_domain), True, subject, html="<p>This is a new email.</p>")146 message = self.client.messages.create(self.server, options)147 self.assertIsNotNone(message.id)148 self.assertEqual(subject, message.subject)149 def test_create_and_send_with_attachment(self):150 if self.verified_domain is None:151 pytest.skip("Requires verified domain secret")152 subject = "New message with attachment"153 file = open(os.path.join(os.path.dirname(154 __file__), 'resources', 'cat.png'), 'rb')155 attachment = Attachment()156 attachment.file_name = "cat.png"157 attachment.content = base64.b64encode(file.read()).decode('ascii')158 attachment.content_type = "image/png"159 attachments = [attachment]160 options = MessageCreateOptions("anything@%s" % (self.verified_domain), True,161 subject, html="<p>This is a new email.</p>", attachments=attachments)162 message = self.client.messages.create(self.server, options)163 self.assertEqual(1, len(message.attachments))164 file1 = message.attachments[0]165 self.assertIsNotNone(file1.id)166 self.assertIsNotNone(file1.url)167 self.assertEqual(82138, file1.length)168 self.assertEqual("cat.png", file1.file_name)169 self.assertEqual("image/png", file1.content_type)170 def test_forward_with_text(self):171 if self.verified_domain is None:172 pytest.skip("Requires verified domain secret")173 body = "Forwarded message"174 options = MessageForwardOptions(175 "anything@%s" % (self.verified_domain), body)176 message = self.client.messages.forward(self.emails[0].id, options)177 self.assertIsNotNone(message.id)178 self.assertTrue(body in message.text.body)179 def test_forward_with_html(self):180 if self.verified_domain is None:181 pytest.skip("Requires verified domain secret")182 body = "<p>Forwarded <strong>HTML</strong> message.</p>"183 options = MessageForwardOptions(184 "anything@%s" % (self.verified_domain), html=body)185 message = self.client.messages.forward(self.emails[0].id, options)186 self.assertIsNotNone(message.id)187 self.assertTrue(body in message.html.body)188 def test_reply_with_text(self):189 if self.verified_domain is None:190 pytest.skip("Requires verified domain secret")191 body = "Reply message body"192 options = MessageReplyOptions(body)193 message = self.client.messages.reply(self.emails[0].id, options)194 self.assertIsNotNone(message.id)195 self.assertTrue(body in message.text.body)196 def test_reply_with_html(self):197 if self.verified_domain is None:198 pytest.skip("Requires verified domain secret")199 body = "<p>Reply <strong>HTML</strong> message body.</p>"200 options = MessageReplyOptions(html=body)201 message = self.client.messages.reply(self.emails[0].id, options)202 self.assertIsNotNone(message.id)203 self.assertTrue(body in message.html.body)204 def test_reply_with_attachment(self):205 if self.verified_domain is None:206 pytest.skip("Requires verified domain secret")207 body = "<p>Reply with attachment.</p>"208 file = open(os.path.join(os.path.dirname(209 __file__), 'resources', 'cat.png'), 'rb')210 attachment = Attachment()211 attachment.file_name = "cat.png"212 attachment.content = base64.b64encode(file.read()).decode('ascii')213 attachment.content_type = "image/png"214 options = MessageReplyOptions(html=body, attachments=[attachment])215 message = self.client.messages.reply(self.emails[0].id, options)216 self.assertEqual(1, len(message.attachments))217 file1 = message.attachments[0]218 self.assertIsNotNone(file1.id)219 self.assertIsNotNone(file1.url)220 self.assertEqual(82138, file1.length)221 self.assertEqual("cat.png", file1.file_name)222 self.assertEqual("image/png", file1.content_type)223 def validate_email(self, email):224 self.validate_metadata(email)225 self.validate_attachments(email)226 self.validate_html(email)227 self.validate_text(email)228 self.assertIsNotNone(email.metadata.ehlo)229 self.assertIsNotNone(email.metadata.mail_from)230 self.assertEqual(1, len(email.metadata.rcpt_to))231 def validate_email_summary(self, email):232 self.validate_metadata(email)233 self.assertIsNotNone(email.summary)234 self.assertEqual(2, email.attachments)235 def validate_html(self, email):236 # Html.Body237 self.assertTrue(email.html.body.startswith("<div dir=\"ltr\">"))238 # Html.Links239 self.assertEqual(3, len(email.html.links))240 self.assertEqual("https://mailosaur.com/", email.html.links[0].href)241 self.assertEqual("mailosaur", email.html.links[0].text)242 self.assertEqual("https://mailosaur.com/", email.html.links[1].href)243 self.assertIsNone(email.html.links[1].text)244 self.assertEqual("http://invalid/", email.html.links[2].href)245 self.assertEqual("invalid", email.html.links[2].text)...

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 mailosaur-python 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