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
6d4d4dfd
Commit
6d4d4dfd
authored
Jul 10, 2017
by
Tom Christie
Committed by
GitHub
Jul 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure closables in request.FILES get closed. (#5262)
Ensure closables on `.FILES` get closed.
parent
b905197f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletions
+36
-1
rest_framework/request.py
+4
-0
tests/test_fields.py
+1
-1
tests/test_request.py
+31
-0
No files found.
rest_framework/request.py
View file @
6d4d4dfd
...
...
@@ -250,6 +250,10 @@ class Request(object):
else
:
self
.
_full_data
=
self
.
_data
# copy files refs to the underlying request so that closable
# objects are handled appropriately.
self
.
_request
.
_files
=
self
.
_files
def
_load_stream
(
self
):
"""
Return the content body of the request, as a stream.
...
...
tests/test_fields.py
View file @
6d4d4dfd
...
...
@@ -1144,7 +1144,7 @@ class TestDateTimeField(FieldValues):
valid_inputs
=
{
'2001-01-01 13:00'
:
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
),
'2001-01-01T13:00'
:
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
),
'2001-01-01T13:00Z'
:
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
)
'2001-01-01T13:00Z'
:
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
)
,
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
):
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
),
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
):
datetime
.
datetime
(
2001
,
1
,
1
,
13
,
00
,
tzinfo
=
utc
),
}
...
...
tests/test_request.py
View file @
6d4d4dfd
...
...
@@ -3,6 +3,9 @@ Tests for content parsing, and form-overloaded content parsing.
"""
from
__future__
import
unicode_literals
import
os.path
import
tempfile
from
django.conf.urls
import
url
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.contrib.auth.models
import
User
...
...
@@ -120,11 +123,39 @@ class MockView(APIView):
return
Response
(
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
class
FileUploadView
(
APIView
):
def
post
(
self
,
request
):
filenames
=
[
file
.
temporary_file_path
()
for
file
in
request
.
FILES
.
values
()]
for
filename
in
filenames
:
assert
os
.
path
.
exists
(
filename
)
return
Response
(
status
=
status
.
HTTP_200_OK
,
data
=
filenames
)
urlpatterns
=
[
url
(
r'^$'
,
MockView
.
as_view
()),
url
(
r'^upload/$'
,
FileUploadView
.
as_view
())
]
@override_settings
(
ROOT_URLCONF
=
'tests.test_request'
,
FILE_UPLOAD_HANDLERS
=
[
'django.core.files.uploadhandler.TemporaryFileUploadHandler'
])
class
FileUploadTests
(
TestCase
):
def
test_fileuploads_closed_at_request_end
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
f
:
response
=
self
.
client
.
post
(
'/upload/'
,
{
'file'
:
f
})
# sanity check that file was processed
assert
len
(
response
.
data
)
==
1
for
file
in
response
.
data
:
assert
not
os
.
path
.
exists
(
file
)
@override_settings
(
ROOT_URLCONF
=
'tests.test_request'
)
class
TestContentParsingWithAuthentication
(
TestCase
):
def
setUp
(
self
):
...
...
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