-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multipart forms and RawPostDataException (#592)
* Multipart forms only allow reading response.body once. When silk reads it, it breaks any other readers including middleware and views. This skips the request body for those forms. * Add test for multipart forms not reading the post body. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e2cf24f
commit b15da76
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from unittest.mock import Mock | ||
|
||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from silk.model_factory import RequestModelFactory, multipart_form | ||
|
||
|
||
class TestMultipartForms(TestCase): | ||
|
||
def test_no_max_request(self): | ||
mock_request = Mock() | ||
mock_request.META = {'CONTENT_TYPE': multipart_form} | ||
mock_request.GET = {} | ||
mock_request.path = reverse('silk:requests') | ||
mock_request.method = 'post' | ||
mock_request.body = Mock() | ||
request_model = RequestModelFactory(mock_request).construct_request_model() | ||
self.assertFalse(request_model.body) | ||
self.assertEqual(b"Raw body not available for multipart_form data, Silk is not showing file uploads.", request_model.raw_body) | ||
mock_request.body.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters