1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00
This commit is contained in:
Ben Cail 2024-03-18 15:10:50 -04:00
parent 5aafc222ad
commit fe089902e1
2 changed files with 29 additions and 22 deletions

View File

@ -1053,21 +1053,28 @@ class RequestsTests(SimpleTestCase):
"""
MultiPartParser.parse() leaves request.FILES immutable.
"""
payload = FakePayload("\r\n".join([
'--boundary',
'Content-Disposition: form-data; name="upload_file"; filename="asd.txt"',
'Content-Type: text/plain',
'',
'asd',
'--boundary--',
]))
request = WSGIRequest({
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'multipart/form-data; boundary=boundary',
'CONTENT_LENGTH': len(payload),
'wsgi.input': payload,
})
self.assertTrue('upload_file' in request.FILES)
content_disposition = 'form-data; name="upload_file"; filename="asd.txt"'
payload = FakePayload(
"\r\n".join(
[
"--boundary",
f"Content-Disposition: {content_disposition}",
"Content-Type: text/plain",
"",
"asd",
"--boundary--",
]
)
)
request = WSGIRequest(
{
"REQUEST_METHOD": "POST",
"CONTENT_TYPE": "multipart/form-data; boundary=boundary",
"CONTENT_LENGTH": len(payload),
"wsgi.input": payload,
}
)
self.assertTrue("upload_file" in request.FILES)
self.assertFalse(request.FILES._mutable)
def test_FILES_connection_error(self):

View File

@ -253,15 +253,15 @@ class ImmutableMultiValueDictTests(SimpleTestCase):
def test_immutability(self):
q = MultiValueDict(mutable=False)
with self.assertRaises(AttributeError):
q.__setitem__('something', 'bar')
q.__setitem__("something", "bar")
with self.assertRaises(AttributeError):
q.setlist('foo', ['bar'])
q.setlist("foo", ["bar"])
with self.assertRaises(AttributeError):
q.appendlist('foo', ['bar'])
q.appendlist("foo", ["bar"])
with self.assertRaises(AttributeError):
q.update({'foo': 'bar'})
q.update({"foo": "bar"})
with self.assertRaises(AttributeError):
q.pop('foo')
q.pop("foo")
with self.assertRaises(AttributeError):
q.popitem()
with self.assertRaises(AttributeError):
@ -272,8 +272,8 @@ class ImmutableMultiValueDictTests(SimpleTestCase):
q = MultiValueDict(mutable=False).copy()
with self.assertRaises(KeyError):
q.__getitem__("foo")
q['name'] = 'john'
self.assertEqual(q['name'], 'john')
q["name"] = "john"
self.assertEqual(q["name"], "john")
class ImmutableListTests(SimpleTestCase):