#9159: testing Client support for middleware
-----------------------------------+----------------------------------------
Reporter: hvendelbo | Owner: nobody
Status: new | Milestone:
Component: Testing framework | Version: 1.0
Keywords: middleware testclient | Stage: Unreviewed
Has_patch: 1 |
-----------------------------------+----------------------------------------
I propose the following improvement:
The testing client is great for testing the whole request chain.
If you want to test the middleware part of the request, you need
to either,
1) Doing a regular request with an added middleware instance for
testing the request object.
2) Directly call one or more middleware instances passing a request
and response.
If your middleware sets a host_name attribute on the request object you
can test it this way:
{{{
from django.test import Client,LastRequestMiddleware
...
def test_host_name(self):
lrm = LastRequestMiddleware()
c = Client(middleware_instances = [lrm])
response = c.get('/')
assert haskey(lrm.request,"host_name"), "The host name was not set"
}}}
Using this approach you can add any custom middleware to the chain.
If you want to test your middleware without relying on the url resolution
and views
working, you can invoke a simplified handler that returns a blank response
in place
of calling the view.
{{{
c = Client()
mym = MyMiddleware()
response = c.get('/',only_middleware=[mym])
assert 'RESULT' in response, "RESULT header not added to response"
}}}
Calling the client this was means that the middleware classes from
settings are not called,
but only the ones you specify by passing the list of instances.
--
Ticket URL: <http://code.djangoproject.com/ticket/9159>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---