diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-09 13:47:36 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-09 13:47:36 +0000 |
| commit | 9ba27afce09cb5f19f429844bd699f5042eb2108 (patch) | |
| tree | 86050ae40f51d5dbb088bd6453ad82d864d2a23b /django | |
| parent | 4ccdf127d07afe88ef5367f7b4b4b0040e3618dc (diff) | |
Added a ``session`` attribute to the test Client, to make it easier to test if session variables have been modified in a view. Also renamed Client.cookie to Client.cookies, to match documentation and common sense.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4464 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/client.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/django/test/client.py b/django/test/client.py index 6e0b443f83..f66b180867 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -1,4 +1,5 @@ from cStringIO import StringIO +from django.conf import settings from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest from django.dispatch import dispatcher @@ -97,7 +98,8 @@ class Client: def __init__(self, **defaults): self.handler = ClientHandler() self.defaults = defaults - self.cookie = SimpleCookie() + self.cookies = SimpleCookie() + self.session = {} def request(self, **request): """ @@ -108,7 +110,7 @@ class Client: """ environ = { - 'HTTP_COOKIE': self.cookie, + 'HTTP_COOKIE': self.cookies, 'PATH_INFO': '/', 'QUERY_STRING': '', 'REQUEST_METHOD': 'GET', @@ -141,8 +143,14 @@ class Client: setattr(response, detail, None) if response.cookies: - self.cookie.update(response.cookies) + self.cookies.update(response.cookies) + if 'django.contrib.sessions' in settings.INSTALLED_APPS: + from django.contrib.sessions.middleware import SessionWrapper + cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None) + if cookie: + self.session = SessionWrapper(cookie.value) + return response def get(self, path, data={}, **extra): |
