Skip to content
Myr

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

1 file+18 added−10 removed

modified:tests/test_signals.py+18 added-10 removed
7 unmodified lines
8 :copyright: (c) 2014 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import pytest1314try:15 import blinker16except ImportError:17 blinker = None1819import flask13import unittest20from tests import TestFlask212223pytestmark = pytest.mark.skipif(24 blinker is None,25 reason='Signals require the blinker library.'26)2728class TestSignals(TestFlask):2930 def test_template_rendered(self):31 app = flask.Flask(__name__)
2 unmodified lines
34 def index():35 return flask.render_template('simple_template.html', whiskey=42)3637 recorded = []3839 def record(sender, template, context):40 recorded.append((template, context))4142 flask.template_rendered.connect(record, app)
39 unmodified lines
82 rv = app.test_client().get('/')83 self.assert_equal(rv.data, b'stuff')8485 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 lines
110111 def test_appcontext_signals(self):112 app = flask.Flask(__name__)113 recorded = []114115 def record_push(sender, **kwargs):116 recorded.append('push')117118 def record_pop(sender, **kwargs):119 recorded.append('pop')120121 @app.route('/')
21 unmodified lines
143 flask.flash('This is a flash message', category='notice')144 return flask.redirect('/other')145146 recorded = []147148 def record(sender, message, category):149 recorded.append((message, category))150151 flask.message_flashed.connect(record, app)
6 unmodified lines
158 self.assert_equal(message, 'This is a flash message')159 self.assert_equal(category, 'notice')160 finally:161 flask.message_flashed.disconnect(record, app)147148149def suite():150 suite = unittest.TestSuite()151 if flask.signals_available:152 suite.addTest(unittest.makeSuite(TestSignals))153 return suite