/tests/regressiontests/handlers/tests.py

https://code.google.com/p/mango-py/ · Python · 34 lines · 14 code · 3 blank · 17 comment · 1 complexity · fb748e732faf1f32acf2567e22493bd2 MD5 · raw file

  1. from django.utils import unittest
  2. from django.conf import settings
  3. from django.core.handlers.wsgi import WSGIHandler
  4. from django.test import RequestFactory
  5. class HandlerTests(unittest.TestCase):
  6. def test_lock_safety(self):
  7. """
  8. Tests for bug #11193 (errors inside middleware shouldn't leave
  9. the initLock locked).
  10. """
  11. # Mangle settings so the handler will fail
  12. old_middleware_classes = settings.MIDDLEWARE_CLASSES
  13. settings.MIDDLEWARE_CLASSES = 42
  14. # Try running the handler, it will fail in load_middleware
  15. handler = WSGIHandler()
  16. self.assertEqual(handler.initLock.locked(), False)
  17. try:
  18. handler(None, None)
  19. except:
  20. pass
  21. self.assertEqual(handler.initLock.locked(), False)
  22. # Reset settings
  23. settings.MIDDLEWARE_CLASSES = old_middleware_classes
  24. def test_bad_path_info(self):
  25. """Tests for bug #15672 ('request' referenced before assignment)"""
  26. environ = RequestFactory().get('/').environ
  27. environ['PATH_INFO'] = '\xed'
  28. handler = WSGIHandler()
  29. response = handler(environ, lambda *a, **k: None)
  30. self.assertEqual(response.status_code, 400)