flask.g is now on the app context and not the request context

This commit is contained in:
Armin Ronacher 2012-12-21 11:45:42 +01:00
parent 61d43c7f12
commit 1949c4a9ab
9 changed files with 71 additions and 20 deletions

View file

@ -65,13 +65,13 @@ class AppContextTestCase(FlaskTestCase):
self.assert_equal(cleanup_stuff, [None])
def test_custom_request_globals_class(self):
def test_custom_app_ctx_globals_class(self):
class CustomRequestGlobals(object):
def __init__(self):
self.spam = 'eggs'
app = flask.Flask(__name__)
app.request_globals_class = CustomRequestGlobals
with app.test_request_context():
app.app_ctx_globals_class = CustomRequestGlobals
with app.app_context():
self.assert_equal(
flask.render_template_string('{{ g.spam }}'), 'eggs')

View file

@ -1104,8 +1104,11 @@ class BasicFunctionalityTestCase(FlaskTestCase):
c.get('/fail')
self.assert_(flask._request_ctx_stack.top is not None)
flask._request_ctx_stack.pop()
self.assert_(flask._app_ctx_stack.top is not None)
# implicit appctx disappears too
flask._request_ctx_stack.top.pop()
self.assert_(flask._request_ctx_stack.top is None)
self.assert_(flask._app_ctx_stack.top is None)
class ContextTestCase(FlaskTestCase):