I'm looking for a quick and simple way to create a request object - as
it would be received by a specific view - for some very basic
testing. Additionally, I want this object to have all the added
attributes from the middleware modules e.g. request.user.
I tried this:
(1)
I looked at django.http.HttpRequest. Easy to construct, but (based on
what I saw in django.core.handlers.base.py) it requires manually
looping through the middleware. Also, it requires special work of
managing cookies to perform a login.
(2)
I looked at the test code - django.test.client.Client - which makes
building a request much easier and handles the login. However, I'm
not running django's test runner and I do not plan on using it for
this case - which means I lose the "black magic" that pulls context
variables - so when I get a response, I cannot grab the HttpRequest
object - just the dict that gets stored as response.request. Is there
a reason why the HttpRequest object isn't added?
I performed a little hack around this by modifying the test Client
code to add the request as an attribute to the response before it is
returned.
django/test/client.py L38
request = WSGIRequest(environ)
response = self.get_response(request)
response.d_request = request # modified line
This works with the two shortcomings (1) I had to hack the source code
to get the value and (2) I'd prefer if I could grab this object
*without actually making the request*, which may modify my underlying
database.
Does anyone know a solution to this (apart from extending BaseHandler,
rewriting the get_response method, and then performing some more
modifications to a new class that would extends test.Client --
hopefully I'm missing something more obvious here...)? Any help would
be greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---