summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSenko Rasic <senko.rasic@dobarkod.hr>2013-05-18 12:26:38 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-05-18 12:50:28 +0200
commit566e284c565a9ea95d81756c6b1f94dfa63fc61b (patch)
tree08150eb4ba97b301bd81fa3037583a7f8b93bf56
parent7b85ef9dfb83bd2f2cde46b9836b9fd12a033b26 (diff)
Added test for multipart, non form-data POST.
Closes #9054. The bug itself is no longer present.
-rw-r--r--tests/requests/tests.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index daf426ea47..56d58c4c75 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -503,9 +503,9 @@ class RequestsTests(SimpleTestCase):
})
self.assertEqual(request.POST, {'key': ['EspaƱa']})
- def test_body_after_POST_multipart(self):
+ def test_body_after_POST_multipart_form_data(self):
"""
- Reading body after parsing multipart is not allowed
+ Reading body after parsing multipart/form-data is not allowed
"""
# Because multipart is used for large amounts fo data i.e. file uploads,
# we don't want the data held in memory twice, and we don't want to
@@ -524,6 +524,29 @@ class RequestsTests(SimpleTestCase):
self.assertEqual(request.POST, {'name': ['value']})
self.assertRaises(Exception, lambda: request.body)
+ def test_body_after_POST_multipart_related(self):
+ """
+ Reading body after parsing multipart that isn't form-data is allowed
+ """
+ # Ticket #9054
+ # There are cases in which the multipart data is related instead of
+ # being a binary upload, in which case it should still be accessible
+ # via body.
+ payload_data = "\r\n".join([
+ '--boundary',
+ 'Content-ID: id; name="name"',
+ '',
+ 'value',
+ '--boundary--'
+ ''])
+ payload = FakePayload(payload_data)
+ request = WSGIRequest({'REQUEST_METHOD': 'POST',
+ 'CONTENT_TYPE': 'multipart/related; boundary=boundary',
+ 'CONTENT_LENGTH': len(payload),
+ 'wsgi.input': payload})
+ self.assertEqual(request.POST, {})
+ self.assertEqual(request.body, payload_data)
+
def test_POST_multipart_with_content_length_zero(self):
"""
Multipart POST requests with Content-Length >= 0 are valid and need to be handled.