From b9907b496911d0d8676225151a36c28fe4f4b72f Mon Sep 17 00:00:00 2001 From: Ron DuPlain Date: Mon, 16 Jan 2012 22:22:04 -0500 Subject: [PATCH] Expand get_flashed_messages tests. Ready to pull request #336. http://github.com/mitsuhiko/flask/pull/336 --- flask/testsuite/basic.py | 49 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/flask/testsuite/basic.py b/flask/testsuite/basic.py index a11f7806..5a41d03e 100644 --- a/flask/testsuite/basic.py +++ b/flask/testsuite/basic.py @@ -321,22 +321,61 @@ class BasicFunctionalityTestCase(FlaskTestCase): @app.route('/test') def test(): + messages = flask.get_flashed_messages() + self.assert_equal(len(messages), 3) + self.assert_equal(messages[0], u'Hello World') + self.assert_equal(messages[1], u'Hello World') + self.assert_equal(messages[2], flask.Markup(u'Testing')) + return '' + + @app.route('/test_with_categories') + def test_with_categories(): messages = flask.get_flashed_messages(with_categories=True) self.assert_equal(len(messages), 3) self.assert_equal(messages[0], ('message', u'Hello World')) self.assert_equal(messages[1], ('error', u'Hello World')) self.assert_equal(messages[2], ('warning', flask.Markup(u'Testing'))) return '' - messages = flask.get_flashed_messages() - self.assert_equal(len(messages), 3) + + @app.route('/test_filter') + def test_filter(): + messages = flask.get_flashed_messages(category_filter=['message'], with_categories=True) + self.assert_equal(len(messages), 1) + self.assert_equal(messages[0], ('message', u'Hello World')) + return '' + + @app.route('/test_filters') + def test_filters(): + messages = flask.get_flashed_messages(category_filter=['message', 'warning'], with_categories=True) + self.assert_equal(len(messages), 2) + self.assert_equal(messages[0], ('message', u'Hello World')) + self.assert_equal(messages[1], ('warning', flask.Markup(u'Testing'))) + return '' + + @app.route('/test_filters_without_returning_categories') + def test_filters(): + messages = flask.get_flashed_messages(category_filter=['message', 'warning']) + self.assert_equal(len(messages), 2) self.assert_equal(messages[0], u'Hello World') - self.assert_equal(messages[1], u'Hello World') - self.assert_equal(messages[2], flask.Markup(u'Testing')) + self.assert_equal(messages[1], flask.Markup(u'Testing')) + return '' c = app.test_client() - c.get('/') + c.get('/') # Flash some messages. c.get('/test') + c.get('/') # Flash more messages. + c.get('/test_with_categories') + + c.get('/') # Flash more messages. + c.get('/test_filter') + + c.get('/') # Flash more messages. + c.get('/test_filters') + + c.get('/') # Flash more messages. + c.get('/test_filters_without_returning_categories') + def test_request_processing(self): app = flask.Flask(__name__) evts = []