Search code examples
pythondjangounit-testinginternal-server-error

Django - testing pages for 500 status


I've got a project where some changes may lead to 500 status in some views.

What is the most elegant way to make unit tests that will check all the views/pages (with static routes, without vars in them, of course) for not returning 500 status?


Solution

  • For unit tests you can use something like:

    from django import test
    from django.core.urlresolvers import reverse
    from page.urls import urlpatterns
    
    class PageTest(test.TestCase):
    
       def test_responses(self):
           for url in urlpatterns:
               response = self.client.get(reverse(url.name))
               self.assertEqual(response.status_code, 200)