Add pop and setdefault to AppCtxGlobals
This commit is contained in:
parent
87222087b3
commit
bbaf20de7c
4 changed files with 35 additions and 0 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue