Browse Source

Documented changes on the g object some more

pull/764/head
Armin Ronacher 11 years ago
parent
commit
93073489a0
  1. 11
      docs/api.rst
  2. 1
      docs/testing.rst
  3. 13
      flask/testsuite/basic.py

11
docs/api.rst

@ -272,7 +272,16 @@ thing, like it does for :class:`request` and :class:`session`.
Starting with Flask 0.10 this is stored on the application context and
no longer on the request context which means it becomes available if
only the application context is bound and not yet a request.
only the application context is bound and not yet a request. This
is especially useful when combined with the :ref:`faking-resources`
pattern for testing.
Additionally as of 0.10 you can use the subscription operator syntax to
get an attribute or `None` if it's not set. These two usages are now
equivalent::
user = getattr(flask.g, 'user', None)
user = flask.g['user']
This is a proxy. See :ref:`notes-on-proxies` for more information.

1
docs/testing.rst

@ -250,6 +250,7 @@ requires that you pass it a response object::
This in general is less useful because at that point you can directly
start using the test client.
.. _faking-resources:
Faking Resources and Context
----------------------------

13
flask/testsuite/basic.py

@ -1116,6 +1116,19 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(len(errors), 3)
self.assert_equal(errors[1], None)
def test_subscript_syntax_on_g(self):
app = flask.Flask(__name__)
app.testing = True
with app.app_context():
self.assert_equal(flask.g['x'], None)
flask.g.x = 42
self.assert_equal(flask.g['x'], 42)
self.assert_equal(flask.g.x, 42)
flask.g['x'] = 23
self.assert_equal(flask.g['x'], 23)
self.assert_equal(flask.g.x, 23)
class SubdomainTestCase(FlaskTestCase):

Loading…
Cancel
Save