don't push app context for test client json

This commit is contained in:
David Lord 2019-05-17 08:39:16 -07:00
parent f2c854060a
commit a4f0f19796
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 95 additions and 39 deletions

View file

@ -14,11 +14,17 @@ import pytest
import flask
import werkzeug
from flask import appcontext_popped
from flask._compat import text_type
from flask.cli import ScriptInfo
from flask.json import jsonify
from flask.testing import make_test_environ_builder, FlaskCliRunner
try:
import blinker
except ImportError:
blinker = None
def test_environ_defaults_from_config(app, client):
app.config['SERVER_NAME'] = 'example.com:1234'
@ -306,6 +312,27 @@ def test_json_request_and_response(app, client):
assert rv.get_json() == json_data
@pytest.mark.skipif(blinker is None, reason="blinker is not installed")
def test_client_json_no_app_context(app, client):
@app.route("/hello", methods=["POST"])
def hello():
return "Hello, {}!".format(flask.request.json["name"])
class Namespace(object):
count = 0
def add(self, app):
self.count += 1
ns = Namespace()
with appcontext_popped.connected_to(ns.add, app):
rv = client.post("/hello", json={"name": "Flask"})
assert rv.get_data(as_text=True) == "Hello, Flask!"
assert ns.count == 1
def test_subdomain():
app = flask.Flask(__name__, subdomain_matching=True)
app.config['SERVER_NAME'] = 'example.com'