#14341 closed Uncategorized (worksforme)
Session middleware raises exception when unit testing HttpResponseForbidden
Reported by: | dikbrouwer | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | gerdemb | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When verifying the GET response of a view in a unit test (TestCase) the following exception is raised in case a HttpResponseForbidden status is returned and the session middleware is enabled:
if response.has_header('Vary'): TypeError: unbound method has_header() must be called with HttpResponseForbidden instance as first argument (got str instance instead)
Change History (3)
comment:1 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
I also encountered this error and discovered the problem was in my code. Instead of returning an HttpResponseForbidden() instance from my middleware, I was returning a HttpResponseForbidden class.
class MyMiddleware: def process_request(self, request): # Correct return HttpResponseForbidden() # Incorrect return HttpResponseForbidden
Although the error was in my code, Django could have provided a more helpful error message perhaps by catching the incorrect response type sooner.
comment:3 by , 13 years ago
I can't reproduce it either, it seems to work fine for me know. Perhaps I was indeed returning a class, basic mistake. Sorry for the irrelevant bug report in that case.
I can't reproduce. Please reopen if you can provide a programmatic test case example that fails.