1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

Fixed #12571 -- Attached originating WSGIRequest to test client responses.

Originating WSGIRequests are now attached to the ``wsgi_request`` attribute of
the ``HttpResponse`` returned by the testing client.

Thanks rvdrijst for the suggestion.
This commit is contained in:
Unai Zalakain
2013-11-19 09:44:30 +01:00
committed by Tim Graham
parent 9ae17d994b
commit 9eb16031ca
4 changed files with 30 additions and 7 deletions

View File

@@ -83,10 +83,9 @@ def closing_iterator_wrapper(iterable, close):
class ClientHandler(BaseHandler):
"""
A HTTP Handler that can be used for testing purposes.
Uses the WSGI interface to compose requests, but returns the raw
HttpResponse object with the originating WSGIRequest attached to its
``request_instance`` attribute.
A HTTP Handler that can be used for testing purposes. Uses the WSGI
interface to compose requests, but returns the raw HttpResponse object with
the originating WSGIRequest attached to its ``wsgi_request`` attribute.
"""
def __init__(self, enforce_csrf_checks=True, *args, **kwargs):
self.enforce_csrf_checks = enforce_csrf_checks
@@ -112,7 +111,7 @@ class ClientHandler(BaseHandler):
response = self.get_response(request)
# Attach the originating request to the response so that it could be
# later retrieved.
response.request_instance = request
response.wsgi_request = request
# We're emulating a WSGI server; we must call the close method
# on completion.
@@ -555,7 +554,7 @@ class Client(RequestFactory):
engine = import_module(settings.SESSION_ENGINE)
# Create a fake request that goes through request middleware
request = self.request().request_instance
request = self.request().wsgi_request
if self.session:
request.session = self.session
@@ -589,7 +588,7 @@ class Client(RequestFactory):
Causes the authenticated user to be logged out.
"""
# Create a fake request that goes through request middleware
request = self.request().request_instance
request = self.request().wsgi_request
engine = import_module(settings.SESSION_ENGINE)
UserModel = get_user_model()