Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added test for multipart, non form-data POST.

Closes #9054. The bug itself is no longer present.
  • Loading branch information...
commit 566e284c565a9ea95d81756c6b1f94dfa63fc61b 1 parent 7b85ef9
Senko Rašić authored May 18, 2013 aaugustin committed May 18, 2013

Showing 1 changed file with 25 additions and 2 deletions. Show diff stats Hide diff stats

  1. 27  tests/requests/tests.py
27  tests/requests/tests.py
@@ -503,9 +503,9 @@ def test_alternate_charset_POST(self):
503 503
         })
504 504
         self.assertEqual(request.POST, {'key': ['España']})
505 505
 
506  
-    def test_body_after_POST_multipart(self):
  506
+    def test_body_after_POST_multipart_form_data(self):
507 507
         """
508  
-        Reading body after parsing multipart is not allowed
  508
+        Reading body after parsing multipart/form-data is not allowed
509 509
         """
510 510
         # Because multipart is used for large amounts fo data i.e. file uploads,
511 511
         # we don't want the data held in memory twice, and we don't want to
@@ -524,6 +524,29 @@ def test_body_after_POST_multipart(self):
524 524
         self.assertEqual(request.POST, {'name': ['value']})
525 525
         self.assertRaises(Exception, lambda: request.body)
526 526
 
  527
+    def test_body_after_POST_multipart_related(self):
  528
+        """
  529
+        Reading body after parsing multipart that isn't form-data is allowed
  530
+        """
  531
+        # Ticket #9054
  532
+        # There are cases in which the multipart data is related instead of
  533
+        # being a binary upload, in which case it should still be accessible
  534
+        # via body.
  535
+        payload_data = "\r\n".join([
  536
+                '--boundary',
  537
+                'Content-ID: id; name="name"',
  538
+                '',
  539
+                'value',
  540
+                '--boundary--'
  541
+                ''])
  542
+        payload = FakePayload(payload_data)
  543
+        request = WSGIRequest({'REQUEST_METHOD': 'POST',
  544
+                               'CONTENT_TYPE': 'multipart/related; boundary=boundary',
  545
+                               'CONTENT_LENGTH': len(payload),
  546
+                               'wsgi.input': payload})
  547
+        self.assertEqual(request.POST, {})
  548
+        self.assertEqual(request.body, payload_data)
  549
+
527 550
     def test_POST_multipart_with_content_length_zero(self):
528 551
         """
529 552
         Multipart POST requests with Content-Length >= 0 are valid and need to be handled.

0 notes on commit 566e284

Please sign in to comment.
Something went wrong with that request. Please try again.