1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #26546 -- Allowed HTTPStatus enum values for HttpResponse.status.

This commit is contained in:
David Evans
2016-04-26 18:43:34 +01:00
committed by Tim Graham
parent 9f8941eda4
commit 2fcafd169b
4 changed files with 28 additions and 6 deletions

View File

@@ -2,6 +2,8 @@
from __future__ import unicode_literals
import unittest
from django.core.handlers.wsgi import WSGIHandler, WSGIRequest, get_script_name
from django.core.signals import request_finished, request_started
from django.db import close_old_connections, connection
@@ -11,6 +13,11 @@ from django.test import (
from django.utils import six
from django.utils.encoding import force_str
try:
from http import HTTPStatus
except ImportError: # Python < 3.5
HTTPStatus = None
class HandlerTests(SimpleTestCase):
@@ -160,16 +167,12 @@ class SignalsTests(SimpleTestCase):
@override_settings(ROOT_URLCONF='handlers.urls')
class HandlerSuspiciousOpsTest(SimpleTestCase):
class HandlerRequestTests(SimpleTestCase):
def test_suspiciousop_in_view_returns_400(self):
response = self.client.get('/suspicious/')
self.assertEqual(response.status_code, 400)
@override_settings(ROOT_URLCONF='handlers.urls')
class HandlerNotFoundTest(SimpleTestCase):
def test_invalid_urls(self):
response = self.client.get('~%A9helloworld')
self.assertContains(response, '~%A9helloworld', status_code=404)
@@ -187,6 +190,15 @@ class HandlerNotFoundTest(SimpleTestCase):
environ = RequestFactory().get('/%E2%A8%87%87%A5%E2%A8%A0').environ
self.assertIsInstance(environ['PATH_INFO'], six.text_type)
@unittest.skipIf(HTTPStatus is None, 'HTTPStatus only exists on Python 3.5+')
def test_handle_accepts_httpstatus_enum_value(self):
def start_response(status, headers):
start_response.status = status
environ = RequestFactory().get('/httpstatus_enum/').environ
WSGIHandler()(environ, start_response)
self.assertEqual(start_response.status, '200 OK')
class ScriptNameTests(SimpleTestCase):
def test_get_script_name(self):