Skip to content
Myr

Added some basic tests for flask itself

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent a01e8b4 · Browse files · 1 file+74 added−0 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+74 added−0 removed

  • other:+74 added−0 removed

1 file+74 added−0 removed

added:flask_tests.py+74 added
1# -*- coding: utf-8 -*-2"""3 Flask Tests4 ~~~~~~~~~~~56 Tests Flask itself. The majority of Flask is already tested7 as part of Werkzeug.89 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12from __future__ import with_statement13import flask14import unittest15import tempfile161718class ContextTestCase(unittest.TestCase):1920 def test_context_binding(self):21 app = flask.Flask(__name__)22 @app.route('/')23 def index():24 return 'Hello %s!' % flask.request.args['name']25 @app.route('/meh')26 def meh():27 return flask.request.url2829 with app.test_request_context('/?name=World'):30 assert index() == 'Hello World!'31 with app.test_request_context('/meh'):32 assert meh() == 'http://localhost/meh'3334 def test_request_dispatching(self):35 app = flask.Flask(__name__)36 @app.route('/')37 def index():38 return flask.request.method39 @app.route('/more', methods=['GET', 'POST'])40 def more():41 return flask.request.method4243 c = app.test_client()44 assert c.get('/').data == 'GET'45 rv = c.post('/')46 assert rv.status_code == 40547 assert sorted(rv.allow) == ['GET', 'HEAD']48 rv = c.head('/')49 assert rv.status_code == 20050 assert not rv.data # head truncates51 assert c.post('/more').data == 'POST'52 assert c.get('/more').data == 'GET'53 rv = c.delete('/more')54 assert rv.status_code == 40555 assert sorted(rv.allow) == ['GET', 'HEAD', 'POST']5657 def test_session(self):58 app = flask.Flask(__name__)59 app.secret_key = 'testkey'60 @app.route('/set', methods=['POST'])61 def set():62 flask.session['value'] = flask.request.form['value']63 return 'value set'64 @app.route('/get')65 def get():66 return flask.session['value']6768 c = app.test_client()69 assert c.post('/set', data={'value': '42'}).data == 'value set'70 assert c.get('/get').data == '42'717273if __name__ == '__main__':74 unittest.main()