PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/handlers/tests.py

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