Add Flask.request_globals_class to customize g.

Requested by toothr on #pocoo.
This commit is contained in:
Ron DuPlain 2012-04-18 20:46:07 -04:00
parent 26da6a5365
commit 33bae1a8dc
4 changed files with 20 additions and 2 deletions

View file

@ -65,6 +65,16 @@ class AppContextTestCase(FlaskTestCase):
self.assert_equal(cleanup_stuff, [None])
def test_custom_request_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():
self.assert_equal(
flask.render_template_string('{{ g.spam }}'), 'eggs')
def suite():
suite = unittest.TestSuite()