Rework test_signals
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent b1c0951 · Browse files · 1 file·+18 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+18 added−10 removed
- tests:+18 added−10 removed
Provenance
- Commit
dd6b257- Tree
00f43ba- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
b1c0951
1 file changed+18 added−10 removed
modified:tests/test_signals.py+18 added-10 removed
7 unmodified lines8 :copyright: (c) 2014 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12+import pytest13+14+try:15+ import blinker16+except ImportError:17+ blinker = None18+19 import flask13-import unittest20 from tests import TestFlask21 22 23+pytestmark = pytest.mark.skipif(24+ blinker is None,25+ reason='Signals require the blinker library.'26+)27+28 class TestSignals(TestFlask):29 30 def test_template_rendered(self):31 app = flask.Flask(__name__)2 unmodified lines34 def index():35 return flask.render_template('simple_template.html', whiskey=42)36 37 recorded = []38+39 def record(sender, template, context):40 recorded.append((template, context))41 42 flask.template_rendered.connect(record, app)39 unmodified lines82 rv = app.test_client().get('/')83 self.assert_equal(rv.data, b'stuff')84 85 self.assert_equal(calls, ['before-signal', 'before-handler',74- 'handler', 'after-handler',75- 'after-signal'])86+ 'handler', 'after-handler',87+ 'after-signal'])88 finally:89 flask.request_started.disconnect(before_request_signal, app)90 flask.request_finished.disconnect(after_request_signal, app)91 18 unmodified lines110 111 def test_appcontext_signals(self):112 app = flask.Flask(__name__)113 recorded = []114+115 def record_push(sender, **kwargs):116 recorded.append('push')117+118 def record_pop(sender, **kwargs):119 recorded.append('pop')120 121 @app.route('/')21 unmodified lines143 flask.flash('This is a flash message', category='notice')144 return flask.redirect('/other')145 146 recorded = []147+148 def record(sender, message, category):149 recorded.append((message, category))150 151 flask.message_flashed.connect(record, app)6 unmodified lines158 self.assert_equal(message, 'This is a flash message')159 self.assert_equal(category, 'notice')160 finally:161 flask.message_flashed.disconnect(record, app)147-148-149-def suite():150- suite = unittest.TestSuite()151- if flask.signals_available:152- suite.addTest(unittest.makeSuite(TestSignals))153- return suite