Snippet List
When debugging tests you frequently need to inspect response content, making a pdb. set_trace() breakpoint and printing response.content
but html isn't enough human readable (even for programmers :D) so, why not open it in your browser? Suposse you save this code in utils.py and you break your testcase as this:
response = self.client.get(self.url)
import pdb; pdb.set_trace()
Then:
(pdb) from utils import load_response_on_firefox
(pdb) load_response_on_firefox(response)
Ta-Da!
- debug
- testing
- response
- response.content
I often insert `pdb.set_trace()` in my test cases to debug and examine behavior. When tests fail with assertions like `assertContains(response, 'Some text')`, it would be useful to see the response's contents in a browser window. This snippet does just that. Simply put this code in a python script on your `PYTHONPATH` and import/call the function when the debugger starts.
Only tested on Ubuntu and you might want to change `URL_OPENER` to whatever you want to open the URLs. Simple, but hopefully useful.
Another `JsonResponse` class, including comment wrapping. Extensions to other kinds of CSRF protection should be obvious. Good explanations of why such protections are needed would make excellent comments on this snippet.
This depends on the `json_encode` method in [snippet 800](http://www.djangosnippets.org/snippets/800/).
- json
- response
- jsonresponse
8 snippets posted so far.