1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

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
This commit is contained in:
Russell Keith-Magee
2007-02-09 13:47:36 +00:00
parent 4ccdf127d0
commit 9ba27afce0
5 changed files with 67 additions and 9 deletions

View File

@@ -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):