Created
November 20, 2014 00:18
-
-
Save nijotz/842a94fc8d43491d9098 to your computer and use it in GitHub Desktop.
Test mail being sent in Flask Selenium tests
This file contains 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 characters
def _worker(app, port, queue): | |
from flask.ext.mail import email_dispatched | |
def queue_message(message, app): | |
if app.testing: | |
queue.put(message) | |
email_dispatched.connect(queue_message) | |
app.run(port=port) | |
class MailServerTestCase(LiveServerTestCase): | |
def _spawn_live_server(self): | |
self._process = None | |
self.port = self.app.config.get('LIVESERVER_PORT', 5000) | |
self.outbox = Queue() | |
self._process = multiprocessing.Process( | |
target=_worker, args=(self.app, self.port, self.outbox) | |
) | |
self._process.start() | |
# we must wait the server start listening | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment