-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add documentation about how to transform factory request to DRF request #9380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,6 +263,26 @@ def test_explicitly_enforce_csrf_checks(self): | |
assert response.status_code == 403 | ||
assert response.data == expected | ||
|
||
def test_transform_factory_django_request_to_drf_request(self): | ||
from rest_framework.views import APIView | ||
|
||
factory = APIRequestFactory() | ||
|
||
class DummyView(APIView): | ||
... | ||
|
||
request = factory.get('/', {'demo': 'test'}) | ||
DRF_request = DummyView().initialize_request(request) | ||
assert DRF_request.query_params == {'demo': ['test']} | ||
assert not hasattr(DRF_request, 'accepted_media_type') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not readable. Prefer:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 about having room to improve readability, but IMO what is needed is not changing the content, it's adding an empty line before the first |
||
|
||
DummyView().initial(DRF_request) | ||
assert DRF_request.accepted_media_type == 'application/json' | ||
|
||
request = factory.post('/', {'example': 'test'}) | ||
DRF_request = DummyView().initialize_request(request) | ||
assert DRF_request.data.get('example') == 'test' | ||
|
||
def test_invalid_format(self): | ||
""" | ||
Attempting to use a format that is not configured will raise an | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
pass
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...
is commonly used to indicate that something is missing - left blank on purpose. I think it suits here just fine.