Merge branch 'master' into json-object-hook
This commit is contained in:
commit
ea2e9609bc
42 changed files with 1100 additions and 663 deletions
15
tests/test_apps/cliapp/factory.py
Normal file
15
tests/test_apps/cliapp/factory.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from __future__ import absolute_import, print_function
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
||||
def create_app():
|
||||
return Flask('create_app')
|
||||
|
||||
|
||||
def create_app2(foo, bar):
|
||||
return Flask("_".join(['create_app2', foo, bar]))
|
||||
|
||||
|
||||
def create_app3(foo, bar, script_info):
|
||||
return Flask("_".join(['create_app3', foo, bar]))
|
||||
|
|
@ -9,20 +9,21 @@
|
|||
:license: BSD, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
import re
|
||||
import uuid
|
||||
import time
|
||||
import flask
|
||||
import pickle
|
||||
import re
|
||||
import time
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from threading import Thread
|
||||
from flask._compat import text_type
|
||||
from werkzeug.exceptions import BadRequest, NotFound, Forbidden
|
||||
|
||||
import pytest
|
||||
import werkzeug.serving
|
||||
from werkzeug.exceptions import BadRequest, Forbidden, NotFound
|
||||
from werkzeug.http import parse_date
|
||||
from werkzeug.routing import BuildError
|
||||
import werkzeug.serving
|
||||
|
||||
import flask
|
||||
from flask._compat import text_type
|
||||
|
||||
|
||||
def test_options_work(app, client):
|
||||
|
|
@ -529,14 +530,14 @@ def test_session_vary_cookie(app, client):
|
|||
@app.route('/vary-cookie-header-set')
|
||||
def vary_cookie_header_set():
|
||||
response = flask.Response()
|
||||
response.headers['Vary'] = 'Cookie'
|
||||
response.vary.add('Cookie')
|
||||
flask.session['test'] = 'test'
|
||||
return response
|
||||
|
||||
@app.route('/vary-header-set')
|
||||
def vary_header_set():
|
||||
response = flask.Response()
|
||||
response.headers['Vary'] = 'Accept-Encoding, Accept-Language'
|
||||
response.vary.update(('Accept-Encoding', 'Accept-Language'))
|
||||
flask.session['test'] = 'test'
|
||||
return response
|
||||
|
||||
|
|
@ -875,6 +876,13 @@ def test_error_handling(app, client):
|
|||
assert b'forbidden' == rv.data
|
||||
|
||||
|
||||
def test_error_handler_unknown_code(app):
|
||||
with pytest.raises(KeyError) as exc_info:
|
||||
app.register_error_handler(999, lambda e: ('999', 999))
|
||||
|
||||
assert 'Use a subclass' in exc_info.value.args[0]
|
||||
|
||||
|
||||
def test_error_handling_processing(app, client):
|
||||
app.config['LOGGER_HANDLER_POLICY'] = 'never'
|
||||
app.testing = False
|
||||
|
|
@ -980,12 +988,17 @@ def test_trapping_of_bad_request_key_errors(app, client):
|
|||
def fail():
|
||||
flask.request.form['missing_key']
|
||||
|
||||
assert client.get('/fail').status_code == 400
|
||||
rv = client.get('/fail')
|
||||
assert rv.status_code == 400
|
||||
assert b'missing_key' not in rv.data
|
||||
|
||||
app.config['TRAP_BAD_REQUEST_ERRORS'] = True
|
||||
|
||||
with pytest.raises(KeyError) as e:
|
||||
client.get("/fail")
|
||||
|
||||
assert e.errisinstance(BadRequest)
|
||||
assert 'missing_key' in e.value.description
|
||||
|
||||
|
||||
def test_trapping_of_all_http_exceptions(app, client):
|
||||
|
|
|
|||
|
|
@ -150,15 +150,37 @@ def test_locate_app(test_apps):
|
|||
script_info = ScriptInfo()
|
||||
assert locate_app(script_info, "cliapp.app").name == "testapp"
|
||||
assert locate_app(script_info, "cliapp.app:testapp").name == "testapp"
|
||||
assert locate_app(script_info, "cliapp.factory").name == "create_app"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory").name == "create_app"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory:create_app").name == "create_app"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory:create_app()").name == "create_app"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory:create_app2('foo', 'bar')"
|
||||
).name == "create_app2_foo_bar"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory:create_app2('foo', 'bar', )"
|
||||
).name == "create_app2_foo_bar"
|
||||
assert locate_app(
|
||||
script_info, "cliapp.factory:create_app3('baz', 'qux')"
|
||||
).name == "create_app3_baz_qux"
|
||||
assert locate_app(script_info, "cliapp.multiapp:app1").name == "app1"
|
||||
pytest.raises(NoAppException, locate_app,
|
||||
script_info, "notanpp.py")
|
||||
pytest.raises(NoAppException, locate_app,
|
||||
script_info, "cliapp/app")
|
||||
pytest.raises(RuntimeError, locate_app,
|
||||
script_info, "cliapp.app:notanapp")
|
||||
pytest.raises(NoAppException, locate_app,
|
||||
script_info, "cliapp.importerrorapp")
|
||||
pytest.raises(
|
||||
NoAppException, locate_app, script_info, "notanpp.py")
|
||||
pytest.raises(
|
||||
NoAppException, locate_app, script_info, "cliapp/app")
|
||||
pytest.raises(
|
||||
RuntimeError, locate_app, script_info, "cliapp.app:notanapp")
|
||||
pytest.raises(
|
||||
NoAppException, locate_app,
|
||||
script_info, "cliapp.factory:create_app2('foo')")
|
||||
pytest.raises(
|
||||
NoAppException, locate_app,
|
||||
script_info, "cliapp.factory:create_app ()")
|
||||
pytest.raises(
|
||||
NoAppException, locate_app, script_info, "cliapp.importerrorapp")
|
||||
|
||||
|
||||
def test_find_default_import_path(test_apps, monkeypatch, tmpdir):
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class TestJSON(object):
|
|||
|
||||
def test_post_empty_json_adds_exception_to_response_content_in_debug(self, app, client):
|
||||
app.config['DEBUG'] = True
|
||||
app.config['TRAP_BAD_REQUEST_ERRORS'] = False
|
||||
|
||||
@app.route('/json', methods=['POST'])
|
||||
def post_json():
|
||||
|
|
@ -56,6 +57,7 @@ class TestJSON(object):
|
|||
|
||||
def test_post_empty_json_wont_add_exception_to_response_if_no_debug(self, app, client):
|
||||
app.config['DEBUG'] = False
|
||||
app.config['TRAP_BAD_REQUEST_ERRORS'] = False
|
||||
|
||||
@app.route('/json', methods=['POST'])
|
||||
def post_json():
|
||||
|
|
|
|||
|
|
@ -73,6 +73,38 @@ def test_environ_base_modified(app, client, app_ctx):
|
|||
assert flask.g.user_agent == 'Bar'
|
||||
|
||||
|
||||
def test_specify_url_scheme(app, client):
|
||||
@app.route('/')
|
||||
def index():
|
||||
return flask.request.url
|
||||
|
||||
ctx = app.test_request_context(url_scheme='https')
|
||||
assert ctx.request.url == 'https://localhost/'
|
||||
|
||||
rv = client.get('/', url_scheme='https')
|
||||
assert rv.data == b'https://localhost/'
|
||||
|
||||
|
||||
def test_blueprint_with_subdomain(app, client):
|
||||
app.config['SERVER_NAME'] = 'example.com:1234'
|
||||
app.config['APPLICATION_ROOT'] = '/foo'
|
||||
|
||||
bp = flask.Blueprint('company', __name__, subdomain='xxx')
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return flask.request.url
|
||||
|
||||
app.register_blueprint(bp)
|
||||
|
||||
ctx = app.test_request_context('/', subdomain='xxx')
|
||||
assert ctx.request.url == 'http://xxx.example.com:1234/foo/'
|
||||
assert ctx.request.blueprint == bp.name
|
||||
|
||||
rv = client.get('/', subdomain='xxx')
|
||||
assert rv.data == b'http://xxx.example.com:1234/foo/'
|
||||
|
||||
|
||||
def test_redirect_keep_session(app, client, app_ctx):
|
||||
app.secret_key = 'testing'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue