|
|
@ -9,8 +9,6 @@ |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
:license: BSD, see LICENSE for more details. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
from __future__ import with_statement |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import re |
|
|
|
import re |
|
|
|
import uuid |
|
|
|
import uuid |
|
|
|
import flask |
|
|
|
import flask |
|
|
@ -19,6 +17,7 @@ import unittest |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from threading import Thread |
|
|
|
from threading import Thread |
|
|
|
from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning |
|
|
|
from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning |
|
|
|
|
|
|
|
from flask._compat import text_type |
|
|
|
from werkzeug.exceptions import BadRequest, NotFound |
|
|
|
from werkzeug.exceptions import BadRequest, NotFound |
|
|
|
from werkzeug.http import parse_date |
|
|
|
from werkzeug.http import parse_date |
|
|
|
from werkzeug.routing import BuildError |
|
|
|
from werkzeug.routing import BuildError |
|
|
@ -33,7 +32,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().open('/', method='OPTIONS') |
|
|
|
rv = app.test_client().open('/', method='OPTIONS') |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
|
self.assert_equal(rv.data, '') |
|
|
|
self.assert_equal(rv.data, b'') |
|
|
|
|
|
|
|
|
|
|
|
def test_options_on_multiple_rules(self): |
|
|
|
def test_options_on_multiple_rules(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -73,15 +72,15 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return flask.request.method |
|
|
|
return flask.request.method |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/').data, 'GET') |
|
|
|
self.assert_equal(c.get('/').data, b'GET') |
|
|
|
rv = c.post('/') |
|
|
|
rv = c.post('/') |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) |
|
|
|
rv = c.head('/') |
|
|
|
rv = c.head('/') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_(not rv.data) # head truncates |
|
|
|
self.assert_false(rv.data) # head truncates |
|
|
|
self.assert_equal(c.post('/more').data, 'POST') |
|
|
|
self.assert_equal(c.post('/more').data, b'POST') |
|
|
|
self.assert_equal(c.get('/more').data, 'GET') |
|
|
|
self.assert_equal(c.get('/more').data, b'GET') |
|
|
|
rv = c.delete('/more') |
|
|
|
rv = c.delete('/more') |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
@ -97,15 +96,15 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
app.add_url_rule('/more', 'more', more, methods=['GET', 'POST']) |
|
|
|
app.add_url_rule('/more', 'more', more, methods=['GET', 'POST']) |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/').data, 'GET') |
|
|
|
self.assert_equal(c.get('/').data, b'GET') |
|
|
|
rv = c.post('/') |
|
|
|
rv = c.post('/') |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) |
|
|
|
rv = c.head('/') |
|
|
|
rv = c.head('/') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_(not rv.data) # head truncates |
|
|
|
self.assert_false(rv.data) # head truncates |
|
|
|
self.assert_equal(c.post('/more').data, 'POST') |
|
|
|
self.assert_equal(c.post('/more').data, b'POST') |
|
|
|
self.assert_equal(c.get('/more').data, 'GET') |
|
|
|
self.assert_equal(c.get('/more').data, b'GET') |
|
|
|
rv = c.delete('/more') |
|
|
|
rv = c.delete('/more') |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(rv.status_code, 405) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
|
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST']) |
|
|
@ -125,8 +124,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
app.view_functions['index'] = index |
|
|
|
app.view_functions['index'] = index |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/foo/').data, 'index') |
|
|
|
self.assert_equal(c.get('/foo/').data, b'index') |
|
|
|
self.assert_equal(c.get('/foo/bar').data, 'bar') |
|
|
|
self.assert_equal(c.get('/foo/bar').data, b'bar') |
|
|
|
|
|
|
|
|
|
|
|
def test_endpoint_decorator(self): |
|
|
|
def test_endpoint_decorator(self): |
|
|
|
from werkzeug.routing import Submount, Rule |
|
|
|
from werkzeug.routing import Submount, Rule |
|
|
@ -145,8 +144,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return 'index' |
|
|
|
return 'index' |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/foo/').data, 'index') |
|
|
|
self.assert_equal(c.get('/foo/').data, b'index') |
|
|
|
self.assert_equal(c.get('/foo/bar').data, 'bar') |
|
|
|
self.assert_equal(c.get('/foo/bar').data, b'bar') |
|
|
|
|
|
|
|
|
|
|
|
def test_session(self): |
|
|
|
def test_session(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -160,8 +159,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return flask.session['value'] |
|
|
|
return flask.session['value'] |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.post('/set', data={'value': '42'}).data, 'value set') |
|
|
|
self.assert_equal(c.post('/set', data={'value': '42'}).data, b'value set') |
|
|
|
self.assert_equal(c.get('/get').data, '42') |
|
|
|
self.assert_equal(c.get('/get').data, b'42') |
|
|
|
|
|
|
|
|
|
|
|
def test_session_using_server_name(self): |
|
|
|
def test_session_using_server_name(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -174,8 +173,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
flask.session['testing'] = 42 |
|
|
|
flask.session['testing'] = 42 |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().get('/', 'http://example.com/') |
|
|
|
rv = app.test_client().get('/', 'http://example.com/') |
|
|
|
self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('domain=.example.com', rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
|
|
def test_session_using_server_name_and_port(self): |
|
|
|
def test_session_using_server_name_and_port(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -188,8 +187,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
flask.session['testing'] = 42 |
|
|
|
flask.session['testing'] = 42 |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('domain=.example.com', rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
|
|
def test_session_using_server_name_port_and_path(self): |
|
|
|
def test_session_using_server_name_port_and_path(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -203,9 +202,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
flask.session['testing'] = 42 |
|
|
|
flask.session['testing'] = 42 |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/foo') |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/foo') |
|
|
|
self.assert_('domain=example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('domain=example.com', rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_('path=/foo' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('path=/foo', rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
|
|
def test_session_using_application_root(self): |
|
|
|
def test_session_using_application_root(self): |
|
|
|
class PrefixPathMiddleware(object): |
|
|
|
class PrefixPathMiddleware(object): |
|
|
@ -227,7 +226,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
flask.session['testing'] = 42 |
|
|
|
flask.session['testing'] = 42 |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
self.assert_('path=/bar' in rv.headers['set-cookie'].lower()) |
|
|
|
self.assert_in('path=/bar', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
|
|
def test_session_using_session_settings(self): |
|
|
|
def test_session_using_session_settings(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -246,22 +245,22 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return 'Hello World' |
|
|
|
return 'Hello World' |
|
|
|
rv = app.test_client().get('/', 'http://www.example.com:8080/test/') |
|
|
|
rv = app.test_client().get('/', 'http://www.example.com:8080/test/') |
|
|
|
cookie = rv.headers['set-cookie'].lower() |
|
|
|
cookie = rv.headers['set-cookie'].lower() |
|
|
|
self.assert_('domain=.example.com' in cookie) |
|
|
|
self.assert_in('domain=.example.com', cookie) |
|
|
|
self.assert_('path=/;' in cookie) |
|
|
|
self.assert_in('path=/;', cookie) |
|
|
|
self.assert_('secure' in cookie) |
|
|
|
self.assert_in('secure', cookie) |
|
|
|
self.assert_('httponly' not in cookie) |
|
|
|
self.assert_not_in('httponly', cookie) |
|
|
|
|
|
|
|
|
|
|
|
def test_missing_session(self): |
|
|
|
def test_missing_session(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
|
def expect_exception(f, *args, **kwargs): |
|
|
|
def expect_exception(f, *args, **kwargs): |
|
|
|
try: |
|
|
|
try: |
|
|
|
f(*args, **kwargs) |
|
|
|
f(*args, **kwargs) |
|
|
|
except RuntimeError, e: |
|
|
|
except RuntimeError as e: |
|
|
|
self.assert_(e.args and 'session is unavailable' in e.args[0]) |
|
|
|
self.assert_true(e.args and 'session is unavailable' in e.args[0]) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.assert_(False, 'expected exception') |
|
|
|
self.assert_true(False, 'expected exception') |
|
|
|
with app.test_request_context(): |
|
|
|
with app.test_request_context(): |
|
|
|
self.assert_(flask.session.get('missing_key') is None) |
|
|
|
self.assert_true(flask.session.get('missing_key') is None) |
|
|
|
expect_exception(flask.session.__setitem__, 'foo', 42) |
|
|
|
expect_exception(flask.session.__setitem__, 'foo', 42) |
|
|
|
expect_exception(flask.session.pop, 'foo') |
|
|
|
expect_exception(flask.session.pop, 'foo') |
|
|
|
|
|
|
|
|
|
|
@ -277,11 +276,11 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/test') |
|
|
|
@app.route('/test') |
|
|
|
def test(): |
|
|
|
def test(): |
|
|
|
return unicode(flask.session.permanent) |
|
|
|
return text_type(flask.session.permanent) |
|
|
|
|
|
|
|
|
|
|
|
client = app.test_client() |
|
|
|
client = app.test_client() |
|
|
|
rv = client.get('/') |
|
|
|
rv = client.get('/') |
|
|
|
self.assert_('set-cookie' in rv.headers) |
|
|
|
self.assert_in('set-cookie', rv.headers) |
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
expires = parse_date(match.group()) |
|
|
|
expires = parse_date(match.group()) |
|
|
|
expected = datetime.utcnow() + app.permanent_session_lifetime |
|
|
|
expected = datetime.utcnow() + app.permanent_session_lifetime |
|
|
@ -290,13 +289,13 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
self.assert_equal(expires.day, expected.day) |
|
|
|
self.assert_equal(expires.day, expected.day) |
|
|
|
|
|
|
|
|
|
|
|
rv = client.get('/test') |
|
|
|
rv = client.get('/test') |
|
|
|
self.assert_equal(rv.data, 'True') |
|
|
|
self.assert_equal(rv.data, b'True') |
|
|
|
|
|
|
|
|
|
|
|
permanent = False |
|
|
|
permanent = False |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_('set-cookie' in rv.headers) |
|
|
|
self.assert_in('set-cookie', rv.headers) |
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
self.assert_(match is None) |
|
|
|
self.assert_true(match is None) |
|
|
|
|
|
|
|
|
|
|
|
def test_session_stored_last(self): |
|
|
|
def test_session_stored_last(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -312,8 +311,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return repr(flask.session.get('foo')) |
|
|
|
return repr(flask.session.get('foo')) |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/').data, 'None') |
|
|
|
self.assert_equal(c.get('/').data, b'None') |
|
|
|
self.assert_equal(c.get('/').data, '42') |
|
|
|
self.assert_equal(c.get('/').data, b'42') |
|
|
|
|
|
|
|
|
|
|
|
def test_session_special_types(self): |
|
|
|
def test_session_special_types(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -348,11 +347,11 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
app.secret_key = 'testkey' |
|
|
|
app.secret_key = 'testkey' |
|
|
|
|
|
|
|
|
|
|
|
with app.test_request_context(): |
|
|
|
with app.test_request_context(): |
|
|
|
self.assert_(not flask.session.modified) |
|
|
|
self.assert_false(flask.session.modified) |
|
|
|
flask.flash('Zap') |
|
|
|
flask.flash('Zap') |
|
|
|
flask.session.modified = False |
|
|
|
flask.session.modified = False |
|
|
|
flask.flash('Zip') |
|
|
|
flask.flash('Zip') |
|
|
|
self.assert_(flask.session.modified) |
|
|
|
self.assert_true(flask.session.modified) |
|
|
|
self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) |
|
|
|
self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip']) |
|
|
|
|
|
|
|
|
|
|
|
def test_extended_flashing(self): |
|
|
|
def test_extended_flashing(self): |
|
|
@ -444,18 +443,18 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
evts.append('before') |
|
|
|
evts.append('before') |
|
|
|
@app.after_request |
|
|
|
@app.after_request |
|
|
|
def after_request(response): |
|
|
|
def after_request(response): |
|
|
|
response.data += '|after' |
|
|
|
response.data += b'|after' |
|
|
|
evts.append('after') |
|
|
|
evts.append('after') |
|
|
|
return response |
|
|
|
return response |
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
self.assert_('before' in evts) |
|
|
|
self.assert_in('before', evts) |
|
|
|
self.assert_('after' not in evts) |
|
|
|
self.assert_not_in('after', evts) |
|
|
|
return 'request' |
|
|
|
return 'request' |
|
|
|
self.assert_('after' not in evts) |
|
|
|
self.assert_not_in('after', evts) |
|
|
|
rv = app.test_client().get('/').data |
|
|
|
rv = app.test_client().get('/').data |
|
|
|
self.assert_('after' in evts) |
|
|
|
self.assert_in('after', evts) |
|
|
|
self.assert_equal(rv, 'request|after') |
|
|
|
self.assert_equal(rv, b'request|after') |
|
|
|
|
|
|
|
|
|
|
|
def test_after_request_processing(self): |
|
|
|
def test_after_request_processing(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -484,7 +483,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return "Response" |
|
|
|
return "Response" |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_('Response' in rv.data) |
|
|
|
self.assert_in(b'Response', rv.data) |
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
|
|
|
|
|
|
|
|
def test_teardown_request_handler_debug_mode(self): |
|
|
|
def test_teardown_request_handler_debug_mode(self): |
|
|
@ -500,7 +499,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return "Response" |
|
|
|
return "Response" |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_('Response' in rv.data) |
|
|
|
self.assert_in(b'Response', rv.data) |
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
|
|
|
|
|
|
|
|
def test_teardown_request_handler_error(self): |
|
|
|
def test_teardown_request_handler_error(self): |
|
|
@ -514,7 +513,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
# test that all teardown_requests get passed the same original |
|
|
|
# test that all teardown_requests get passed the same original |
|
|
|
# exception. |
|
|
|
# exception. |
|
|
|
try: |
|
|
|
try: |
|
|
|
raise TypeError |
|
|
|
raise TypeError() |
|
|
|
except: |
|
|
|
except: |
|
|
|
pass |
|
|
|
pass |
|
|
|
@app.teardown_request |
|
|
|
@app.teardown_request |
|
|
@ -525,15 +524,15 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
# test that all teardown_requests get passed the same original |
|
|
|
# test that all teardown_requests get passed the same original |
|
|
|
# exception. |
|
|
|
# exception. |
|
|
|
try: |
|
|
|
try: |
|
|
|
raise TypeError |
|
|
|
raise TypeError() |
|
|
|
except: |
|
|
|
except: |
|
|
|
pass |
|
|
|
pass |
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def fails(): |
|
|
|
def fails(): |
|
|
|
1/0 |
|
|
|
1 // 0 |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.status_code, 500) |
|
|
|
self.assert_equal(rv.status_code, 500) |
|
|
|
self.assert_('Internal Server Error' in rv.data) |
|
|
|
self.assert_in(b'Internal Server Error', rv.data) |
|
|
|
self.assert_equal(len(called), 2) |
|
|
|
self.assert_equal(len(called), 2) |
|
|
|
|
|
|
|
|
|
|
|
def test_before_after_request_order(self): |
|
|
|
def test_before_after_request_order(self): |
|
|
@ -563,7 +562,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
return '42' |
|
|
|
return '42' |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.data, '42') |
|
|
|
self.assert_equal(rv.data, b'42') |
|
|
|
self.assert_equal(called, [1, 2, 3, 4, 5, 6]) |
|
|
|
self.assert_equal(called, [1, 2, 3, 4, 5, 6]) |
|
|
|
|
|
|
|
|
|
|
|
def test_error_handling(self): |
|
|
|
def test_error_handling(self): |
|
|
@ -583,10 +582,10 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/') |
|
|
|
rv = c.get('/') |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.data, 'not found') |
|
|
|
self.assert_equal(rv.data, b'not found') |
|
|
|
rv = c.get('/error') |
|
|
|
rv = c.get('/error') |
|
|
|
self.assert_equal(rv.status_code, 500) |
|
|
|
self.assert_equal(rv.status_code, 500) |
|
|
|
self.assert_equal('internal server error', rv.data) |
|
|
|
self.assert_equal(b'internal server error', rv.data) |
|
|
|
|
|
|
|
|
|
|
|
def test_before_request_and_routing_errors(self): |
|
|
|
def test_before_request_and_routing_errors(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -598,7 +597,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return flask.g.something, 404 |
|
|
|
return flask.g.something, 404 |
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.data, 'value') |
|
|
|
self.assert_equal(rv.data, b'value') |
|
|
|
|
|
|
|
|
|
|
|
def test_user_error_handling(self): |
|
|
|
def test_user_error_handling(self): |
|
|
|
class MyException(Exception): |
|
|
|
class MyException(Exception): |
|
|
@ -607,14 +606,14 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
|
@app.errorhandler(MyException) |
|
|
|
@app.errorhandler(MyException) |
|
|
|
def handle_my_exception(e): |
|
|
|
def handle_my_exception(e): |
|
|
|
self.assert_(isinstance(e, MyException)) |
|
|
|
self.assert_true(isinstance(e, MyException)) |
|
|
|
return '42' |
|
|
|
return '42' |
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
raise MyException() |
|
|
|
raise MyException() |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/').data, '42') |
|
|
|
self.assert_equal(c.get('/').data, b'42') |
|
|
|
|
|
|
|
|
|
|
|
def test_trapping_of_bad_request_key_errors(self): |
|
|
|
def test_trapping_of_bad_request_key_errors(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -629,8 +628,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
try: |
|
|
|
try: |
|
|
|
c.get('/fail') |
|
|
|
c.get('/fail') |
|
|
|
except KeyError, e: |
|
|
|
except KeyError as e: |
|
|
|
self.assert_(isinstance(e, BadRequest)) |
|
|
|
self.assert_true(isinstance(e, BadRequest)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.fail('Expected exception') |
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
|
|
@ -645,7 +644,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
try: |
|
|
|
try: |
|
|
|
c.get('/fail') |
|
|
|
c.get('/fail') |
|
|
|
except NotFound, e: |
|
|
|
except NotFound as e: |
|
|
|
pass |
|
|
|
pass |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.fail('Expected exception') |
|
|
|
self.fail('Expected exception') |
|
|
@ -664,9 +663,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
with app.test_client() as c: |
|
|
|
with app.test_client() as c: |
|
|
|
try: |
|
|
|
try: |
|
|
|
c.post('/fail', data={'foo': 'index.txt'}) |
|
|
|
c.post('/fail', data={'foo': 'index.txt'}) |
|
|
|
except DebugFilesKeyError, e: |
|
|
|
except DebugFilesKeyError as e: |
|
|
|
self.assert_('no file contents were transmitted' in str(e)) |
|
|
|
self.assert_in('no file contents were transmitted', str(e)) |
|
|
|
self.assert_('This was submitted: "index.txt"' in str(e)) |
|
|
|
self.assert_in('This was submitted: "index.txt"', str(e)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.fail('Expected exception') |
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
|
|
@ -688,7 +687,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8')) |
|
|
|
self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8')) |
|
|
|
self.assert_equal(c.get('/string').data, u'Hällo Wörld'.encode('utf-8')) |
|
|
|
self.assert_equal(c.get('/string').data, u'Hällo Wörld'.encode('utf-8')) |
|
|
|
rv = c.get('/args') |
|
|
|
rv = c.get('/args') |
|
|
|
self.assert_equal(rv.data, 'Meh') |
|
|
|
self.assert_equal(rv.data, b'Meh') |
|
|
|
self.assert_equal(rv.headers['X-Foo'], 'Testing') |
|
|
|
self.assert_equal(rv.headers['X-Foo'], 'Testing') |
|
|
|
self.assert_equal(rv.status_code, 400) |
|
|
|
self.assert_equal(rv.status_code, 400) |
|
|
|
self.assert_equal(rv.mimetype, 'text/plain') |
|
|
|
self.assert_equal(rv.mimetype, 'text/plain') |
|
|
@ -698,17 +697,17 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
with app.test_request_context(): |
|
|
|
with app.test_request_context(): |
|
|
|
rv = flask.make_response() |
|
|
|
rv = flask.make_response() |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.data, '') |
|
|
|
self.assert_equal(rv.data, b'') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
|
|
|
|
|
|
|
|
rv = flask.make_response('Awesome') |
|
|
|
rv = flask.make_response('Awesome') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.data, 'Awesome') |
|
|
|
self.assert_equal(rv.data, b'Awesome') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
|
|
|
|
|
|
|
|
rv = flask.make_response('W00t', 404) |
|
|
|
rv = flask.make_response('W00t', 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.data, 'W00t') |
|
|
|
self.assert_equal(rv.data, b'W00t') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
self.assert_equal(rv.mimetype, 'text/html') |
|
|
|
|
|
|
|
|
|
|
|
def test_make_response_with_response_instance(self): |
|
|
|
def test_make_response_with_response_instance(self): |
|
|
@ -717,14 +716,13 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
rv = flask.make_response( |
|
|
|
rv = flask.make_response( |
|
|
|
flask.jsonify({'msg': 'W00t'}), 400) |
|
|
|
flask.jsonify({'msg': 'W00t'}), 400) |
|
|
|
self.assertEqual(rv.status_code, 400) |
|
|
|
self.assertEqual(rv.status_code, 400) |
|
|
|
self.assertEqual(rv.data, |
|
|
|
self.assertEqual(rv.data, b'{\n "msg": "W00t"\n}') |
|
|
|
'{\n "msg": "W00t"\n}') |
|
|
|
|
|
|
|
self.assertEqual(rv.mimetype, 'application/json') |
|
|
|
self.assertEqual(rv.mimetype, 'application/json') |
|
|
|
|
|
|
|
|
|
|
|
rv = flask.make_response( |
|
|
|
rv = flask.make_response( |
|
|
|
flask.Response(''), 400) |
|
|
|
flask.Response(''), 400) |
|
|
|
self.assertEqual(rv.status_code, 400) |
|
|
|
self.assertEqual(rv.status_code, 400) |
|
|
|
self.assertEqual(rv.data, '') |
|
|
|
self.assertEqual(rv.data, b'') |
|
|
|
self.assertEqual(rv.mimetype, 'text/html') |
|
|
|
self.assertEqual(rv.mimetype, 'text/html') |
|
|
|
|
|
|
|
|
|
|
|
rv = flask.make_response( |
|
|
|
rv = flask.make_response( |
|
|
@ -755,8 +753,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
try: |
|
|
|
try: |
|
|
|
with app.test_request_context(): |
|
|
|
with app.test_request_context(): |
|
|
|
flask.url_for('spam') |
|
|
|
flask.url_for('spam') |
|
|
|
except BuildError, error: |
|
|
|
except BuildError as err: |
|
|
|
pass |
|
|
|
error = err |
|
|
|
try: |
|
|
|
try: |
|
|
|
raise RuntimeError('Test case where BuildError is not current.') |
|
|
|
raise RuntimeError('Test case where BuildError is not current.') |
|
|
|
except RuntimeError: |
|
|
|
except RuntimeError: |
|
|
@ -784,16 +782,18 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
def index(args): |
|
|
|
def index(args): |
|
|
|
return '|'.join(args) |
|
|
|
return '|'.join(args) |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assert_equal(c.get('/1,2,3').data, '1|2|3') |
|
|
|
self.assert_equal(c.get('/1,2,3').data, b'1|2|3') |
|
|
|
|
|
|
|
|
|
|
|
def test_static_files(self): |
|
|
|
def test_static_files(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
|
|
|
|
|
app.testing = True |
|
|
|
rv = app.test_client().get('/static/index.html') |
|
|
|
rv = app.test_client().get('/static/index.html') |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
self.assert_equal(rv.data.strip(), '<h1>Hello World!</h1>') |
|
|
|
self.assert_equal(rv.data.strip(), b'<h1>Hello World!</h1>') |
|
|
|
with app.test_request_context(): |
|
|
|
with app.test_request_context(): |
|
|
|
self.assert_equal(flask.url_for('static', filename='index.html'), |
|
|
|
self.assert_equal(flask.url_for('static', filename='index.html'), |
|
|
|
'/static/index.html') |
|
|
|
'/static/index.html') |
|
|
|
|
|
|
|
rv.close() |
|
|
|
|
|
|
|
|
|
|
|
def test_none_response(self): |
|
|
|
def test_none_response(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -802,11 +802,11 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return None |
|
|
|
return None |
|
|
|
try: |
|
|
|
try: |
|
|
|
app.test_client().get('/') |
|
|
|
app.test_client().get('/') |
|
|
|
except ValueError, e: |
|
|
|
except ValueError as e: |
|
|
|
self.assert_equal(str(e), 'View function did not return a response') |
|
|
|
self.assert_equal(str(e), 'View function did not return a response') |
|
|
|
pass |
|
|
|
pass |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.assert_("Expected ValueError") |
|
|
|
self.assert_true("Expected ValueError") |
|
|
|
|
|
|
|
|
|
|
|
def test_request_locals(self): |
|
|
|
def test_request_locals(self): |
|
|
|
self.assert_equal(repr(flask.g), '<LocalProxy unbound>') |
|
|
|
self.assert_equal(repr(flask.g), '<LocalProxy unbound>') |
|
|
@ -826,24 +826,24 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
return 'Foo SubDomain' |
|
|
|
return 'Foo SubDomain' |
|
|
|
|
|
|
|
|
|
|
|
rv = app.test_client().get('/') |
|
|
|
rv = app.test_client().get('/') |
|
|
|
self.assert_equal(rv.data, 'Foo') |
|
|
|
self.assert_equal(rv.data, b'Foo') |
|
|
|
|
|
|
|
|
|
|
|
rv = app.test_client().get('/', 'http://localhost.localdomain:5000') |
|
|
|
rv = app.test_client().get('/', 'http://localhost.localdomain:5000') |
|
|
|
self.assert_equal(rv.data, 'Foo') |
|
|
|
self.assert_equal(rv.data, b'Foo') |
|
|
|
|
|
|
|
|
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain:5000') |
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain:5000') |
|
|
|
self.assert_equal(rv.data, 'Foo') |
|
|
|
self.assert_equal(rv.data, b'Foo') |
|
|
|
|
|
|
|
|
|
|
|
app.config.update(SERVER_NAME='localhost.localdomain') |
|
|
|
app.config.update(SERVER_NAME='localhost.localdomain') |
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain') |
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain') |
|
|
|
self.assert_equal(rv.data, 'Foo') |
|
|
|
self.assert_equal(rv.data, b'Foo') |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
app.config.update(SERVER_NAME='localhost.localdomain:443') |
|
|
|
app.config.update(SERVER_NAME='localhost.localdomain:443') |
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain') |
|
|
|
rv = app.test_client().get('/', 'https://localhost.localdomain') |
|
|
|
# Werkzeug 0.8 |
|
|
|
# Werkzeug 0.8 |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
except ValueError, e: |
|
|
|
except ValueError as e: |
|
|
|
# Werkzeug 0.7 |
|
|
|
# Werkzeug 0.7 |
|
|
|
self.assert_equal(str(e), "the server name provided " + |
|
|
|
self.assert_equal(str(e), "the server name provided " + |
|
|
|
"('localhost.localdomain:443') does not match the " + \ |
|
|
|
"('localhost.localdomain:443') does not match the " + \ |
|
|
@ -854,21 +854,21 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
rv = app.test_client().get('/', 'http://foo.localhost') |
|
|
|
rv = app.test_client().get('/', 'http://foo.localhost') |
|
|
|
# Werkzeug 0.8 |
|
|
|
# Werkzeug 0.8 |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
self.assert_equal(rv.status_code, 404) |
|
|
|
except ValueError, e: |
|
|
|
except ValueError as e: |
|
|
|
# Werkzeug 0.7 |
|
|
|
# Werkzeug 0.7 |
|
|
|
self.assert_equal(str(e), "the server name provided " + \ |
|
|
|
self.assert_equal(str(e), "the server name provided " + \ |
|
|
|
"('localhost.localdomain') does not match the " + \ |
|
|
|
"('localhost.localdomain') does not match the " + \ |
|
|
|
"server name from the WSGI environment ('foo.localhost')") |
|
|
|
"server name from the WSGI environment ('foo.localhost')") |
|
|
|
|
|
|
|
|
|
|
|
rv = app.test_client().get('/', 'http://foo.localhost.localdomain') |
|
|
|
rv = app.test_client().get('/', 'http://foo.localhost.localdomain') |
|
|
|
self.assert_equal(rv.data, 'Foo SubDomain') |
|
|
|
self.assert_equal(rv.data, b'Foo SubDomain') |
|
|
|
|
|
|
|
|
|
|
|
def test_exception_propagation(self): |
|
|
|
def test_exception_propagation(self): |
|
|
|
def apprunner(configkey): |
|
|
|
def apprunner(configkey): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
1/0 |
|
|
|
1 // 0 |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
if config_key is not None: |
|
|
|
if config_key is not None: |
|
|
|
app.config[config_key] = True |
|
|
|
app.config[config_key] = True |
|
|
@ -896,18 +896,18 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
@app.before_request |
|
|
|
@app.before_request |
|
|
|
def always_first(): |
|
|
|
def always_first(): |
|
|
|
flask.request.form['myfile'] |
|
|
|
flask.request.form['myfile'] |
|
|
|
self.assert_(False) |
|
|
|
self.assert_true(False) |
|
|
|
@app.route('/accept', methods=['POST']) |
|
|
|
@app.route('/accept', methods=['POST']) |
|
|
|
def accept_file(): |
|
|
|
def accept_file(): |
|
|
|
flask.request.form['myfile'] |
|
|
|
flask.request.form['myfile'] |
|
|
|
self.assert_(False) |
|
|
|
self.assert_true(False) |
|
|
|
@app.errorhandler(413) |
|
|
|
@app.errorhandler(413) |
|
|
|
def catcher(error): |
|
|
|
def catcher(error): |
|
|
|
return '42' |
|
|
|
return '42' |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.post('/accept', data={'myfile': 'foo' * 100}) |
|
|
|
rv = c.post('/accept', data={'myfile': 'foo' * 100}) |
|
|
|
self.assert_equal(rv.data, '42') |
|
|
|
self.assert_equal(rv.data, b'42') |
|
|
|
|
|
|
|
|
|
|
|
def test_url_processors(self): |
|
|
|
def test_url_processors(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -936,9 +936,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
|
|
|
|
|
|
|
|
self.assert_equal(c.get('/de/').data, '/de/about') |
|
|
|
self.assert_equal(c.get('/de/').data, b'/de/about') |
|
|
|
self.assert_equal(c.get('/de/about').data, '/foo') |
|
|
|
self.assert_equal(c.get('/de/about').data, b'/foo') |
|
|
|
self.assert_equal(c.get('/foo').data, '/en/about') |
|
|
|
self.assert_equal(c.get('/foo').data, b'/en/about') |
|
|
|
|
|
|
|
|
|
|
|
def test_inject_blueprint_url_defaults(self): |
|
|
|
def test_inject_blueprint_url_defaults(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -969,14 +969,14 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
return 'Awesome' |
|
|
|
return 'Awesome' |
|
|
|
self.assert_(not app.got_first_request) |
|
|
|
self.assert_false(app.got_first_request) |
|
|
|
self.assert_equal(app.test_client().get('/').data, 'Awesome') |
|
|
|
self.assert_equal(app.test_client().get('/').data, b'Awesome') |
|
|
|
try: |
|
|
|
try: |
|
|
|
@app.route('/foo') |
|
|
|
@app.route('/foo') |
|
|
|
def broken(): |
|
|
|
def broken(): |
|
|
|
return 'Meh' |
|
|
|
return 'Meh' |
|
|
|
except AssertionError, e: |
|
|
|
except AssertionError as e: |
|
|
|
self.assert_('A setup function was called' in str(e)) |
|
|
|
self.assert_in('A setup function was called', str(e)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.fail('Expected exception') |
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
|
|
@ -984,8 +984,8 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
@app.route('/foo') |
|
|
|
@app.route('/foo') |
|
|
|
def working(): |
|
|
|
def working(): |
|
|
|
return 'Meh' |
|
|
|
return 'Meh' |
|
|
|
self.assert_equal(app.test_client().get('/foo').data, 'Meh') |
|
|
|
self.assert_equal(app.test_client().get('/foo').data, b'Meh') |
|
|
|
self.assert_(app.got_first_request) |
|
|
|
self.assert_true(app.got_first_request) |
|
|
|
|
|
|
|
|
|
|
|
def test_before_first_request_functions(self): |
|
|
|
def test_before_first_request_functions(self): |
|
|
|
got = [] |
|
|
|
got = [] |
|
|
@ -998,7 +998,7 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
self.assert_equal(got, [42]) |
|
|
|
self.assert_equal(got, [42]) |
|
|
|
c.get('/') |
|
|
|
c.get('/') |
|
|
|
self.assert_equal(got, [42]) |
|
|
|
self.assert_equal(got, [42]) |
|
|
|
self.assert_(app.got_first_request) |
|
|
|
self.assert_true(app.got_first_request) |
|
|
|
|
|
|
|
|
|
|
|
def test_routing_redirect_debugging(self): |
|
|
|
def test_routing_redirect_debugging(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -1009,20 +1009,20 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
with app.test_client() as c: |
|
|
|
with app.test_client() as c: |
|
|
|
try: |
|
|
|
try: |
|
|
|
c.post('/foo', data={}) |
|
|
|
c.post('/foo', data={}) |
|
|
|
except AssertionError, e: |
|
|
|
except AssertionError as e: |
|
|
|
self.assert_('http://localhost/foo/' in str(e)) |
|
|
|
self.assert_in('http://localhost/foo/', str(e)) |
|
|
|
self.assert_('Make sure to directly send your POST-request ' |
|
|
|
self.assert_in('Make sure to directly send your POST-request ' |
|
|
|
'to this URL' in str(e)) |
|
|
|
'to this URL', str(e)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.fail('Expected exception') |
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
|
|
|
rv = c.get('/foo', data={}, follow_redirects=True) |
|
|
|
rv = c.get('/foo', data={}, follow_redirects=True) |
|
|
|
self.assert_equal(rv.data, 'success') |
|
|
|
self.assert_equal(rv.data, b'success') |
|
|
|
|
|
|
|
|
|
|
|
app.debug = False |
|
|
|
app.debug = False |
|
|
|
with app.test_client() as c: |
|
|
|
with app.test_client() as c: |
|
|
|
rv = c.post('/foo', data={}, follow_redirects=True) |
|
|
|
rv = c.post('/foo', data={}, follow_redirects=True) |
|
|
|
self.assert_equal(rv.data, 'success') |
|
|
|
self.assert_equal(rv.data, b'success') |
|
|
|
|
|
|
|
|
|
|
|
def test_route_decorator_custom_endpoint(self): |
|
|
|
def test_route_decorator_custom_endpoint(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -1046,9 +1046,9 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
assert flask.url_for('123') == '/bar/123' |
|
|
|
assert flask.url_for('123') == '/bar/123' |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
self.assertEqual(c.get('/foo/').data, 'foo') |
|
|
|
self.assertEqual(c.get('/foo/').data, b'foo') |
|
|
|
self.assertEqual(c.get('/bar/').data, 'bar') |
|
|
|
self.assertEqual(c.get('/bar/').data, b'bar') |
|
|
|
self.assertEqual(c.get('/bar/123').data, '123') |
|
|
|
self.assertEqual(c.get('/bar/123').data, b'123') |
|
|
|
|
|
|
|
|
|
|
|
def test_preserve_only_once(self): |
|
|
|
def test_preserve_only_once(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -1056,19 +1056,19 @@ class BasicFunctionalityTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/fail') |
|
|
|
@app.route('/fail') |
|
|
|
def fail_func(): |
|
|
|
def fail_func(): |
|
|
|
1/0 |
|
|
|
1 // 0 |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
for x in xrange(3): |
|
|
|
for x in range(3): |
|
|
|
with self.assert_raises(ZeroDivisionError): |
|
|
|
with self.assert_raises(ZeroDivisionError): |
|
|
|
c.get('/fail') |
|
|
|
c.get('/fail') |
|
|
|
|
|
|
|
|
|
|
|
self.assert_(flask._request_ctx_stack.top is not None) |
|
|
|
self.assert_true(flask._request_ctx_stack.top is not None) |
|
|
|
self.assert_(flask._app_ctx_stack.top is not None) |
|
|
|
self.assert_true(flask._app_ctx_stack.top is not None) |
|
|
|
# implicit appctx disappears too |
|
|
|
# implicit appctx disappears too |
|
|
|
flask._request_ctx_stack.top.pop() |
|
|
|
flask._request_ctx_stack.top.pop() |
|
|
|
self.assert_(flask._request_ctx_stack.top is None) |
|
|
|
self.assert_true(flask._request_ctx_stack.top is None) |
|
|
|
self.assert_(flask._app_ctx_stack.top is None) |
|
|
|
self.assert_true(flask._app_ctx_stack.top is None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SubdomainTestCase(FlaskTestCase): |
|
|
|
class SubdomainTestCase(FlaskTestCase): |
|
|
@ -1085,10 +1085,10 @@ class SubdomainTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/', 'http://localhost/') |
|
|
|
rv = c.get('/', 'http://localhost/') |
|
|
|
self.assert_equal(rv.data, 'normal index') |
|
|
|
self.assert_equal(rv.data, b'normal index') |
|
|
|
|
|
|
|
|
|
|
|
rv = c.get('/', 'http://test.localhost/') |
|
|
|
rv = c.get('/', 'http://test.localhost/') |
|
|
|
self.assert_equal(rv.data, 'test index') |
|
|
|
self.assert_equal(rv.data, b'test index') |
|
|
|
|
|
|
|
|
|
|
|
@emits_module_deprecation_warning |
|
|
|
@emits_module_deprecation_warning |
|
|
|
def test_module_static_path_subdomain(self): |
|
|
|
def test_module_static_path_subdomain(self): |
|
|
@ -1098,7 +1098,9 @@ class SubdomainTestCase(FlaskTestCase): |
|
|
|
app.register_module(mod) |
|
|
|
app.register_module(mod) |
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/static/hello.txt', 'http://foo.example.com/') |
|
|
|
rv = c.get('/static/hello.txt', 'http://foo.example.com/') |
|
|
|
self.assert_equal(rv.data.strip(), 'Hello Subdomain') |
|
|
|
rv.direct_passthrough = False |
|
|
|
|
|
|
|
self.assert_equal(rv.data.strip(), b'Hello Subdomain') |
|
|
|
|
|
|
|
rv.close() |
|
|
|
|
|
|
|
|
|
|
|
def test_subdomain_matching(self): |
|
|
|
def test_subdomain_matching(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -1109,7 +1111,7 @@ class SubdomainTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/', 'http://mitsuhiko.localhost/') |
|
|
|
rv = c.get('/', 'http://mitsuhiko.localhost/') |
|
|
|
self.assert_equal(rv.data, 'index for mitsuhiko') |
|
|
|
self.assert_equal(rv.data, b'index for mitsuhiko') |
|
|
|
|
|
|
|
|
|
|
|
def test_subdomain_matching_with_ports(self): |
|
|
|
def test_subdomain_matching_with_ports(self): |
|
|
|
app = flask.Flask(__name__) |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -1120,7 +1122,7 @@ class SubdomainTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/', 'http://mitsuhiko.localhost:3000/') |
|
|
|
rv = c.get('/', 'http://mitsuhiko.localhost:3000/') |
|
|
|
self.assert_equal(rv.data, 'index for mitsuhiko') |
|
|
|
self.assert_equal(rv.data, b'index for mitsuhiko') |
|
|
|
|
|
|
|
|
|
|
|
@emits_module_deprecation_warning |
|
|
|
@emits_module_deprecation_warning |
|
|
|
def test_module_subdomain_support(self): |
|
|
|
def test_module_subdomain_support(self): |
|
|
@ -1140,9 +1142,9 @@ class SubdomainTestCase(FlaskTestCase): |
|
|
|
|
|
|
|
|
|
|
|
c = app.test_client() |
|
|
|
c = app.test_client() |
|
|
|
rv = c.get('/test', 'http://testing.localhost/') |
|
|
|
rv = c.get('/test', 'http://testing.localhost/') |
|
|
|
self.assert_equal(rv.data, 'Test') |
|
|
|
self.assert_equal(rv.data, b'Test') |
|
|
|
rv = c.get('/outside', 'http://xtesting.localhost/') |
|
|
|
rv = c.get('/outside', 'http://xtesting.localhost/') |
|
|
|
self.assert_equal(rv.data, 'Outside') |
|
|
|
self.assert_equal(rv.data, b'Outside') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def suite(): |
|
|
|
def suite(): |
|
|
|