|
|
@ -149,58 +149,58 @@ def test_manual_context_binding(app): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(greenlet is None, reason='greenlet not installed') |
|
|
|
@pytest.mark.skipif(greenlet is None, reason='greenlet not installed') |
|
|
|
def test_greenlet_context_copying(app, client): |
|
|
|
class TestGreenletContextCopying(object): |
|
|
|
greenlets = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
def test_greenlet_context_copying(self, app, client): |
|
|
|
def index(): |
|
|
|
greenlets = [] |
|
|
|
reqctx = flask._request_ctx_stack.top.copy() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def g(): |
|
|
|
@app.route('/') |
|
|
|
assert not flask.request |
|
|
|
def index(): |
|
|
|
assert not flask.current_app |
|
|
|
reqctx = flask._request_ctx_stack.top.copy() |
|
|
|
with reqctx: |
|
|
|
|
|
|
|
assert flask.request |
|
|
|
|
|
|
|
assert flask.current_app == app |
|
|
|
|
|
|
|
assert flask.request.path == '/' |
|
|
|
|
|
|
|
assert flask.request.args['foo'] == 'bar' |
|
|
|
|
|
|
|
assert not flask.request |
|
|
|
|
|
|
|
return 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
greenlets.append(greenlet(g)) |
|
|
|
def g(): |
|
|
|
return 'Hello World!' |
|
|
|
assert not flask.request |
|
|
|
|
|
|
|
assert not flask.current_app |
|
|
|
|
|
|
|
with reqctx: |
|
|
|
|
|
|
|
assert flask.request |
|
|
|
|
|
|
|
assert flask.current_app == app |
|
|
|
|
|
|
|
assert flask.request.path == '/' |
|
|
|
|
|
|
|
assert flask.request.args['foo'] == 'bar' |
|
|
|
|
|
|
|
assert not flask.request |
|
|
|
|
|
|
|
return 42 |
|
|
|
|
|
|
|
|
|
|
|
rv = client.get('/?foo=bar') |
|
|
|
greenlets.append(greenlet(g)) |
|
|
|
assert rv.data == b'Hello World!' |
|
|
|
return 'Hello World!' |
|
|
|
|
|
|
|
|
|
|
|
result = greenlets[0].run() |
|
|
|
rv = client.get('/?foo=bar') |
|
|
|
assert result == 42 |
|
|
|
assert rv.data == b'Hello World!' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = greenlets[0].run() |
|
|
|
|
|
|
|
assert result == 42 |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(greenlet is None, reason='greenlet not installed') |
|
|
|
def test_greenlet_context_copying_api(self, app, client): |
|
|
|
def test_greenlet_context_copying_api(app, client): |
|
|
|
greenlets = [] |
|
|
|
greenlets = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
@app.route('/') |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
reqctx = flask._request_ctx_stack.top.copy() |
|
|
|
reqctx = flask._request_ctx_stack.top.copy() |
|
|
|
|
|
|
|
|
|
|
|
@flask.copy_current_request_context |
|
|
|
@flask.copy_current_request_context |
|
|
|
def g(): |
|
|
|
def g(): |
|
|
|
assert flask.request |
|
|
|
assert flask.request |
|
|
|
assert flask.current_app == app |
|
|
|
assert flask.current_app == app |
|
|
|
assert flask.request.path == '/' |
|
|
|
assert flask.request.path == '/' |
|
|
|
assert flask.request.args['foo'] == 'bar' |
|
|
|
assert flask.request.args['foo'] == 'bar' |
|
|
|
return 42 |
|
|
|
return 42 |
|
|
|
|
|
|
|
|
|
|
|
greenlets.append(greenlet(g)) |
|
|
|
greenlets.append(greenlet(g)) |
|
|
|
return 'Hello World!' |
|
|
|
return 'Hello World!' |
|
|
|
|
|
|
|
|
|
|
|
rv = client.get('/?foo=bar') |
|
|
|
rv = client.get('/?foo=bar') |
|
|
|
assert rv.data == b'Hello World!' |
|
|
|
assert rv.data == b'Hello World!' |
|
|
|
|
|
|
|
|
|
|
|
result = greenlets[0].run() |
|
|
|
result = greenlets[0].run() |
|
|
|
assert result == 42 |
|
|
|
assert result == 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_session_error_pops_context(): |
|
|
|
def test_session_error_pops_context(): |
|
|
|