I write my handler for server errors and define it at root urls.py: handler500 = 'myhandler' And I want to write unittest for testing how it works. For testing I write view with error and define it in test URLs configuration, when I make request to this view in browser I see my handler and receive status code 500, but when I launch test that make request to this view I see stack trace and my test failed. Have you some ideas for testing handler500 by unittests?
Asked
Active
Viewed 550 times
4
-
What part do you want to test exactly? The behavior of your handler? The fact that it's registered as the handler? – Thomas Orozco Oct 06 '12 at 21:36
-
I want to test that my handler registered as default handler500 (my content in response and status code equals 500) – Gr1N Oct 06 '12 at 21:43
-
2I think you might want to an actual test framework such as selenium then. – Thomas Orozco Oct 06 '12 at 22:05
-
Selenium not good for me, because a want to launch tests without server. Unittests more usefull in my way. – Gr1N Oct 07 '12 at 10:51
-
You could check out the Django docs on testing with Selenium I think. – Thomas Orozco Oct 07 '12 at 10:55
-
I now read selenium python bindings documentation and I can't find how can I get status code from loaded page. – Gr1N Oct 07 '12 at 11:02
1 Answers
3
What you want to do here is integration testing; unit-tests won't be the appropriate tools for it.
Django includes support for using famous live browser testing tools such as Selenium.
As you pointed out and for your specific case, it is indeed pretty complicated to retrieve the status code for a page using Selenium, you might therefore want to use a simpler approach:
- Use a
LiveServerTestCase
- Use a python HTTP client such as
requests
to access the test page - Check that the test page does generate an HTTP 500 error
- Check that the test page contains the expected content.
If you want to test some JS on the test page, then use Selenium for that part, in combination of requests to test the status.

Community
- 1
- 1

Thomas Orozco
- 53,284
- 11
- 113
- 116
-
Thnx! `LiveServerTestCase` great feature, with it I can do all what I want. – Gr1N Oct 07 '12 at 13:06