2011-01-14 23:18:21 +00:00
|
|
|
from django.core.handlers.wsgi import WSGIHandler
|
2011-04-22 12:15:52 +00:00
|
|
|
from django.test import RequestFactory
|
2012-10-20 21:22:46 +00:00
|
|
|
from django.test.utils import override_settings
|
2012-12-17 09:49:26 +00:00
|
|
|
from django.utils import six
|
2011-10-13 21:34:56 +00:00
|
|
|
from django.utils import unittest
|
2011-04-22 12:15:52 +00:00
|
|
|
|
2011-01-14 23:18:21 +00:00
|
|
|
class HandlerTests(unittest.TestCase):
|
|
|
|
|
2012-10-20 21:22:46 +00:00
|
|
|
# Mangle settings so the handler will fail
|
|
|
|
@override_settings(MIDDLEWARE_CLASSES=42)
|
2011-01-14 23:18:21 +00:00
|
|
|
def test_lock_safety(self):
|
|
|
|
"""
|
|
|
|
Tests for bug #11193 (errors inside middleware shouldn't leave
|
|
|
|
the initLock locked).
|
|
|
|
"""
|
|
|
|
# Try running the handler, it will fail in load_middleware
|
|
|
|
handler = WSGIHandler()
|
|
|
|
self.assertEqual(handler.initLock.locked(), False)
|
2012-09-07 19:06:23 +00:00
|
|
|
with self.assertRaises(Exception):
|
2011-01-14 23:18:21 +00:00
|
|
|
handler(None, None)
|
|
|
|
self.assertEqual(handler.initLock.locked(), False)
|
|
|
|
|
2011-04-22 12:15:52 +00:00
|
|
|
def test_bad_path_info(self):
|
|
|
|
"""Tests for bug #15672 ('request' referenced before assignment)"""
|
|
|
|
environ = RequestFactory().get('/').environ
|
2012-12-17 09:49:26 +00:00
|
|
|
environ['PATH_INFO'] = '\xed'
|
2011-04-22 12:15:52 +00:00
|
|
|
handler = WSGIHandler()
|
|
|
|
response = handler(environ, lambda *a, **k: None)
|
|
|
|
self.assertEqual(response.status_code, 400)
|