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?
I write my handler for server errors and define it at root urls.py: handler500
Share
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:
LiveServerTestCaserequeststo access the test pageIf you want to test some JS on the test page, then use Selenium for that part, in combination of requests to test the status.