Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
0ec915e6
Commit
0ec915e6
authored
Aug 30, 2017
by
Ryan P Kilby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Force content_type inclusion in APIRequestFactory
parent
eb88687e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
2 deletions
+11
-2
rest_framework/request.py
+1
-1
rest_framework/test.py
+9
-0
tests/test_testing.py
+1
-1
No files found.
rest_framework/request.py
View file @
0ec915e6
...
@@ -303,7 +303,7 @@ class Request(object):
...
@@ -303,7 +303,7 @@ class Request(object):
stream
=
None
stream
=
None
if
stream
is
None
or
media_type
is
None
:
if
stream
is
None
or
media_type
is
None
:
if
media_type
and
not
is_form_media_type
(
media_type
):
if
media_type
and
is_form_media_type
(
media_type
):
empty_data
=
QueryDict
(
''
,
encoding
=
self
.
_request
.
_encoding
)
empty_data
=
QueryDict
(
''
,
encoding
=
self
.
_request
.
_encoding
)
else
:
else
:
empty_data
=
{}
empty_data
=
{}
...
...
rest_framework/test.py
View file @
0ec915e6
...
@@ -227,6 +227,15 @@ class APIRequestFactory(DjangoRequestFactory):
...
@@ -227,6 +227,15 @@ class APIRequestFactory(DjangoRequestFactory):
data
,
content_type
=
self
.
_encode_data
(
data
,
format
,
content_type
)
data
,
content_type
=
self
.
_encode_data
(
data
,
format
,
content_type
)
return
self
.
generic
(
'OPTIONS'
,
path
,
data
,
content_type
,
**
extra
)
return
self
.
generic
(
'OPTIONS'
,
path
,
data
,
content_type
,
**
extra
)
def
generic
(
self
,
method
,
path
,
data
=
''
,
content_type
=
'application/octet-stream'
,
secure
=
False
,
**
extra
):
# Include the CONTENT_TYPE, regardless of whether or not data is empty.
if
content_type
is
not
None
:
extra
[
'CONTENT_TYPE'
]
=
str
(
content_type
)
return
super
(
APIRequestFactory
,
self
)
.
generic
(
method
,
path
,
data
,
content_type
,
secure
,
**
extra
)
def
request
(
self
,
**
kwargs
):
def
request
(
self
,
**
kwargs
):
request
=
super
(
APIRequestFactory
,
self
)
.
request
(
**
kwargs
)
request
=
super
(
APIRequestFactory
,
self
)
.
request
(
**
kwargs
)
request
.
_dont_enforce_csrf_checks
=
not
self
.
enforce_csrf_checks
request
.
_dont_enforce_csrf_checks
=
not
self
.
enforce_csrf_checks
...
...
tests/test_testing.py
View file @
0ec915e6
...
@@ -282,4 +282,4 @@ class TestAPIRequestFactory(TestCase):
...
@@ -282,4 +282,4 @@ class TestAPIRequestFactory(TestCase):
data
=
None
,
data
=
None
,
content_type
=
'application/json'
,
content_type
=
'application/json'
,
)
)
assert
request
.
content_type
==
'application/json'
assert
request
.
META
[
'CONTENT_TYPE'
]
==
'application/json'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment