summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Baechler <sb@feinheit.ch>2015-05-05 15:51:31 +0200
committerTim Graham <timograham@gmail.com>2015-05-05 12:35:13 -0400
commitd42cbde0c602dad97bb452280baa4a4c7a056bf4 (patch)
treea92e71bd4097b0eea134cb696bf6fad0132b5468
parent285371bd76afc35b4a83c742edc44b51afc2d888 (diff)
[1.7.x] Refs #21357 -- Added a working session example to the docs.
-rw-r--r--docs/topics/testing/tools.txt22
1 files changed, 15 insertions, 7 deletions
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 99a4634c1c..4b279ab0e3 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -475,14 +475,22 @@ can access these properties as part of a test condition.
A dictionary-like object containing session information. See the
:doc:`session documentation</topics/http/sessions>` for full details.
- To modify the session and then save it, it must be stored in a variable
- first (because a new ``SessionStore`` is created every time this property
- is accessed)::
+ In Django 1.7, ``client.session`` returns a plain dictionary if the session
+ is empty. The following code creates a test client with a fully working
+ session engine::
- def test_something(self):
- session = self.client.session
- session['somekey'] = 'test'
- session.save()
+ from importlib import import_module
+
+ from django.conf import settings
+ from django.test import Client
+
+ def get_client_with_session(self):
+ client = Client()
+ engine = import_module(settings.SESSION_ENGINE)
+ s = engine.SessionStore()
+ s.save()
+ client.cookies[settings.SESSION_COOKIE_NAME] = s.session_key
+ return client
Example
~~~~~~~