Last active
March 13, 2016 14:26
Revisions
-
devsli revised this gist
Mar 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ def test_send(SmtpServer): sender = smtplib.SMTP() sender.connect('localhost', 1125) sender.login('john.doe44', 'correct horse battery staple') sender_email = '[email protected]' -
devsli revised this gist
Mar 13, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def test_get_msg(SmtpServer): Read more about `multiprocessing <https://docs.python.org/2/library/multiprocessing.html>`_ """ sent = Queue() port = 1125 host = 'localhost' class _TestSmtpServer(secure_smtpd.SMTPServer): @@ -38,7 +38,7 @@ def validate(self, user, password): return True def run(host, port, sent_queue): s = _TestSmtpServer(sent_queue, ('0.0.0.0', port), None, require_authentication=True, credential_validator=DufferValidator()) s.run() -
devsli revised this gist
Mar 5, 2016 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ import pytest import secure_smtpd from multiprocessing import Queue, Process @pytest.yield_fixture(scope='module') def SmtpServer(): """ @@ -16,9 +21,6 @@ def test_get_msg(SmtpServer): Read more about `multiprocessing <https://docs.python.org/2/library/multiprocessing.html>`_ """ sent = Queue() port = 1025 host = 'localhost' -
devsli revised this gist
Mar 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ Secure SMTPd py.test fixture Test outgoing messages of your app. It's possible to replace `secure-smtpd <https://github.com/bcoe/secure-smtpd>`_ with default ``smtpd`` if ``AUTH`` is not forced by your application. -
devsli revised this gist
Mar 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ Secure SMTPd py.test fixture Test outgoing messages of your app. It's possible to replace `` `secure-smtpd <https://github.com/bcoe/secure-smtpd>`_ `` with default ``smtpd`` if ``AUTH`` is not forced by your application. -
devsli revised this gist
Mar 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ Secure SMTPd py.test fixture Test outgoing messages of your app. It's possible to replace ```secure-smtpd <https://github.com/bcoe/secure-smtpd>`_`` with default ``smtpd`` if ``AUTH`` is not forced by your application. -
devsli revised this gist
Mar 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def test_send(SmtpServer): sender.sendmail(sender_email, recipient_email, text) addr, sender, recipients, body = SmtpServer.get(timeout=10) assert sender_email == sender assert recipient_email == recipients.pop() -
devsli renamed this gist
Mar 5, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
devsli renamed this gist
Mar 5, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
devsli renamed this gist
Mar 5, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
devsli created this gist
Mar 5, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ Secure SMTPd py.test fixture ============================ Test outgoing messages of your app. It's possible to replace `secure-smtpd <https://github.com/bcoe/secure-smtpd>`_ with default ``smtpd`` if ``AUTH`` is not forced by your application. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ @pytest.yield_fixture(scope='module') def SmtpServer(): """ Return dummy SMTP server to check outgoing messages. The ``multiprocessing.Queue`` of ``tuple`` objects is yelded Sent queue example usage:: def test_get_msg(SmtpServer): addr, sender, recipients, body = SmtpServer.get() Note that execution will be freezed until something is retrieved from ``sent`` queue. You can use ``Queue.get_nowait()`` or ``timeout`` parameter to avoid such behavior. Read more about `multiprocessing <https://docs.python.org/2/library/multiprocessing.html>`_ """ import secure_smtpd from multiprocessing import Queue, Process sent = Queue() port = 1025 host = 'localhost' class _TestSmtpServer(secure_smtpd.SMTPServer): def __init__(self, sent_queue, *args, **kwargs): secure_smtpd.SMTPServer.__init__(self, *args, **kwargs) self.sent_queue = sent_queue def process_message(self, *args): self.sent_queue.put(args) class DufferValidator(object): def validate(self, user, password): return True def run(host, port, sent_queue): s = _TestSmtpServer(sent_queue, ('0.0.0.0', 1025), None, require_authentication=True, credential_validator=DufferValidator()) s.run() srv_proc = Process(target=run, args=(host, port, sent)) srv_proc.start() yield sent srv_proc.terminate() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import pytest import smtplib def test_send(SmtpServer): sender = smtplib.SMTP() sender.connect('localhost', 1025) sender.login('john.doe44', 'correct horse battery staple') sender_email = '[email protected]' recipient_email = '[email protected]' text = 'Hello! Here your invoice.' sender.sendmail(sender_email, recipient_email, text) addr, sender, recipients, body = SmtpServer['sent'].get(timeout=10) assert sender_email == sender assert recipient_email == recipients.pop() assert body == text assert SmtpServer.empty() == True