|
|
|
@ -93,6 +93,28 @@ def test_app_tearing_down_with_handled_exception():
|
|
|
|
|
|
|
|
|
|
assert cleanup_stuff == [None] |
|
|
|
|
|
|
|
|
|
def test_app_ctx_globals_methods(): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
|
with app.app_context(): |
|
|
|
|
# get |
|
|
|
|
assert flask.g.get('foo') is None |
|
|
|
|
assert flask.g.get('foo', 'bar') == 'bar' |
|
|
|
|
# __contains__ |
|
|
|
|
assert 'foo' not in flask.g |
|
|
|
|
flask.g.foo = 'bar' |
|
|
|
|
assert 'foo' in flask.g |
|
|
|
|
# setdefault |
|
|
|
|
flask.g.setdefault('bar', 'the cake is a lie') |
|
|
|
|
flask.g.setdefault('bar', 'hello world') |
|
|
|
|
assert flask.g.bar == 'the cake is a lie' |
|
|
|
|
# pop |
|
|
|
|
assert flask.g.pop('bar') == 'the cake is a lie' |
|
|
|
|
with pytest.raises(KeyError): |
|
|
|
|
flask.g.pop('bar') |
|
|
|
|
assert flask.g.pop('bar', 'more cake') == 'more cake' |
|
|
|
|
# __iter__ |
|
|
|
|
assert list(flask.g) == ['foo'] |
|
|
|
|
|
|
|
|
|
def test_custom_app_ctx_globals_class(): |
|
|
|
|
class CustomRequestGlobals(object): |
|
|
|
|
def __init__(self): |
|
|
|
|