mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -5,19 +5,23 @@ from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.client import FakePayload
|
||||
|
||||
TOO_MANY_FIELDS_MSG = 'The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.'
|
||||
TOO_MUCH_DATA_MSG = 'Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.'
|
||||
TOO_MANY_FIELDS_MSG = (
|
||||
"The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS."
|
||||
)
|
||||
TOO_MUCH_DATA_MSG = "Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE."
|
||||
|
||||
|
||||
class DataUploadMaxMemorySizeFormPostTests(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload('a=1&a=2&a=3\r\n')
|
||||
self.request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
payload = FakePayload("a=1&a=2&a=3\r\n")
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "application/x-www-form-urlencoded",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
|
||||
def test_size_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_MEMORY_SIZE=12):
|
||||
@@ -35,19 +39,25 @@ class DataUploadMaxMemorySizeFormPostTests(SimpleTestCase):
|
||||
|
||||
class DataUploadMaxMemorySizeMultipartPostTests(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload("\r\n".join([
|
||||
'--boundary',
|
||||
'Content-Disposition: form-data; name="name"',
|
||||
'',
|
||||
'value',
|
||||
'--boundary--'
|
||||
]))
|
||||
self.request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
payload = FakePayload(
|
||||
"\r\n".join(
|
||||
[
|
||||
"--boundary",
|
||||
'Content-Disposition: form-data; name="name"',
|
||||
"",
|
||||
"value",
|
||||
"--boundary--",
|
||||
]
|
||||
)
|
||||
)
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "multipart/form-data; boundary=boundary",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
|
||||
def test_size_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_MEMORY_SIZE=10):
|
||||
@@ -63,31 +73,39 @@ class DataUploadMaxMemorySizeMultipartPostTests(SimpleTestCase):
|
||||
self.request._load_post_and_files()
|
||||
|
||||
def test_file_passes(self):
|
||||
payload = FakePayload("\r\n".join([
|
||||
'--boundary',
|
||||
'Content-Disposition: form-data; name="file1"; filename="test.file"',
|
||||
'',
|
||||
'value',
|
||||
'--boundary--'
|
||||
]))
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
payload = FakePayload(
|
||||
"\r\n".join(
|
||||
[
|
||||
"--boundary",
|
||||
'Content-Disposition: form-data; name="file1"; filename="test.file"',
|
||||
"",
|
||||
"value",
|
||||
"--boundary--",
|
||||
]
|
||||
)
|
||||
)
|
||||
request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "multipart/form-data; boundary=boundary",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
with self.settings(DATA_UPLOAD_MAX_MEMORY_SIZE=1):
|
||||
request._load_post_and_files()
|
||||
self.assertIn('file1', request.FILES, "Upload file not present")
|
||||
self.assertIn("file1", request.FILES, "Upload file not present")
|
||||
|
||||
|
||||
class DataUploadMaxMemorySizeGetTests(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'GET',
|
||||
'wsgi.input': BytesIO(b''),
|
||||
'CONTENT_LENGTH': 3,
|
||||
})
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "GET",
|
||||
"wsgi.input": BytesIO(b""),
|
||||
"CONTENT_LENGTH": 3,
|
||||
}
|
||||
)
|
||||
|
||||
def test_data_upload_max_memory_size_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_MEMORY_SIZE=2):
|
||||
@@ -103,51 +121,60 @@ class DataUploadMaxMemorySizeGetTests(SimpleTestCase):
|
||||
self.request.body
|
||||
|
||||
def test_empty_content_length(self):
|
||||
self.request.environ['CONTENT_LENGTH'] = ''
|
||||
self.request.environ["CONTENT_LENGTH"] = ""
|
||||
self.request.body
|
||||
|
||||
|
||||
class DataUploadMaxNumberOfFieldsGet(SimpleTestCase):
|
||||
|
||||
def test_get_max_fields_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FIELDS=1):
|
||||
with self.assertRaisesMessage(TooManyFieldsSent, TOO_MANY_FIELDS_MSG):
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'GET',
|
||||
'wsgi.input': BytesIO(b''),
|
||||
'QUERY_STRING': 'a=1&a=2&a=3',
|
||||
})
|
||||
request.GET['a']
|
||||
request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "GET",
|
||||
"wsgi.input": BytesIO(b""),
|
||||
"QUERY_STRING": "a=1&a=2&a=3",
|
||||
}
|
||||
)
|
||||
request.GET["a"]
|
||||
|
||||
def test_get_max_fields_not_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FIELDS=3):
|
||||
request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'GET',
|
||||
'wsgi.input': BytesIO(b''),
|
||||
'QUERY_STRING': 'a=1&a=2&a=3',
|
||||
})
|
||||
request.GET['a']
|
||||
request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "GET",
|
||||
"wsgi.input": BytesIO(b""),
|
||||
"QUERY_STRING": "a=1&a=2&a=3",
|
||||
}
|
||||
)
|
||||
request.GET["a"]
|
||||
|
||||
|
||||
class DataUploadMaxNumberOfFieldsMultipartPost(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload("\r\n".join([
|
||||
'--boundary',
|
||||
'Content-Disposition: form-data; name="name1"',
|
||||
'',
|
||||
'value1',
|
||||
'--boundary',
|
||||
'Content-Disposition: form-data; name="name2"',
|
||||
'',
|
||||
'value2',
|
||||
'--boundary--'
|
||||
]))
|
||||
self.request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
payload = FakePayload(
|
||||
"\r\n".join(
|
||||
[
|
||||
"--boundary",
|
||||
'Content-Disposition: form-data; name="name1"',
|
||||
"",
|
||||
"value1",
|
||||
"--boundary",
|
||||
'Content-Disposition: form-data; name="name2"',
|
||||
"",
|
||||
"value2",
|
||||
"--boundary--",
|
||||
]
|
||||
)
|
||||
)
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "multipart/form-data; boundary=boundary",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
|
||||
def test_number_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FIELDS=1):
|
||||
@@ -165,13 +192,15 @@ class DataUploadMaxNumberOfFieldsMultipartPost(SimpleTestCase):
|
||||
|
||||
class DataUploadMaxNumberOfFieldsFormPost(SimpleTestCase):
|
||||
def setUp(self):
|
||||
payload = FakePayload("\r\n".join(['a=1&a=2&a=3', '']))
|
||||
self.request = WSGIRequest({
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
|
||||
'CONTENT_LENGTH': len(payload),
|
||||
'wsgi.input': payload,
|
||||
})
|
||||
payload = FakePayload("\r\n".join(["a=1&a=2&a=3", ""]))
|
||||
self.request = WSGIRequest(
|
||||
{
|
||||
"REQUEST_METHOD": "POST",
|
||||
"CONTENT_TYPE": "application/x-www-form-urlencoded",
|
||||
"CONTENT_LENGTH": len(payload),
|
||||
"wsgi.input": payload,
|
||||
}
|
||||
)
|
||||
|
||||
def test_number_exceeded(self):
|
||||
with self.settings(DATA_UPLOAD_MAX_NUMBER_FIELDS=2):
|
||||
|
||||
Reference in New Issue
Block a user