MCPcopy
hub / github.com/pallets/flask / test_proper_test_request_context

Function test_proper_test_request_context

tests/test_reqctx.py:63–104  ·  view source on GitHub ↗
(app)

Source from the content-addressed store, hash-verified

61
62
63def test_proper_test_request_context(app):
64 app.config.update(SERVER_NAME="localhost.localdomain:5000")
65
66 @app.route("/")
67 def index():
68 return None
69
70 @app.route("/", subdomain="foo")
71 def sub():
72 return None
73
74 with app.test_request_context("/"):
75 assert (
76 flask.url_for("index", _external=True)
77 == "http://localhost.localdomain:5000/"
78 )
79
80 with app.test_request_context("/"):
81 assert (
82 flask.url_for("sub", _external=True)
83 == "http://foo.localhost.localdomain:5000/"
84 )
85
86 # suppress Werkzeug 0.15 warning about name mismatch
87 with warnings.catch_warnings():
88 warnings.filterwarnings(
89 "ignore", "Current server name", UserWarning, "flask.app"
90 )
91 with app.test_request_context(
92 "/", environ_overrides={"HTTP_HOST": "localhost"}
93 ):
94 pass
95
96 app.config.update(SERVER_NAME="localhost")
97 with app.test_request_context("/", environ_overrides={"SERVER_NAME": "localhost"}):
98 pass
99
100 app.config.update(SERVER_NAME="localhost:80")
101 with app.test_request_context(
102 "/", environ_overrides={"SERVER_NAME": "localhost:80"}
103 ):
104 pass
105
106
107def test_context_binding(app):

Callers

nothing calls this directly

Calls 2

test_request_contextMethod · 0.80
url_forMethod · 0.80

Tested by

no test coverage detected