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
8f921160
Commit
8f921160
authored
Jan 31, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1377 from Ian-Foote/force_bytes
Import force_bytes on django >= 1.5
parents
18f26ff5
0043f30c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
rest_framework/compat.py
+1
-1
rest_framework/renderers.py
+2
-1
rest_framework/tests/test_testing.py
+9
-0
No files found.
rest_framework/compat.py
View file @
8f921160
...
...
@@ -457,7 +457,7 @@ from django.test.client import RequestFactory as DjangoRequestFactory
from
django.test.client
import
FakePayload
try
:
# In 1.5 the test client uses force_bytes
from
django.utils.encoding
import
force_bytes_or_smart_bytes
from
django.utils.encoding
import
force_bytes
as
force_bytes
_or_smart_bytes
except
ImportError
:
# In 1.3 and 1.4 the test client just uses smart_str
from
django.utils.encoding
import
smart_str
as
force_bytes_or_smart_bytes
...
...
rest_framework/renderers.py
View file @
8f921160
...
...
@@ -10,6 +10,7 @@ from __future__ import unicode_literals
import
copy
import
json
import
django
from
django
import
forms
from
django.core.exceptions
import
ImproperlyConfigured
from
django.http.multipartparser
import
parse_header
...
...
@@ -597,7 +598,7 @@ class MultiPartRenderer(BaseRenderer):
media_type
=
'multipart/form-data; boundary=BoUnDaRyStRiNg'
format
=
'multipart'
charset
=
'utf-8'
BOUNDARY
=
'BoUnDaRyStRiNg'
BOUNDARY
=
'BoUnDaRyStRiNg'
if
django
.
VERSION
>=
(
1
,
5
)
else
b
'BoUnDaRyStRiNg'
def
render
(
self
,
data
,
accepted_media_type
=
None
,
renderer_context
=
None
):
return
encode_multipart
(
self
.
BOUNDARY
,
data
)
...
...
rest_framework/tests/test_testing.py
View file @
8f921160
# -- coding: utf-8 --
from
__future__
import
unicode_literals
from
io
import
BytesIO
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
rest_framework.compat
import
patterns
,
url
...
...
@@ -143,3 +145,10 @@ class TestAPIRequestFactory(TestCase):
force_authenticate
(
request
,
user
=
user
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
data
[
'user'
],
'example'
)
def
test_upload_file
(
self
):
# This is a 1x1 black png
simple_png
=
BytesIO
(
b
'
\x89
PNG
\r\n\x1a\n\x00\x00\x00\r
IHDR
\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\r
IDATx
\x9c
c````
\x00\x00\x00\x05\x00\x01\xa5\xf6
E@
\x00\x00\x00\x00
IEND
\xae
B`
\x82
'
)
simple_png
.
name
=
'test.png'
factory
=
APIRequestFactory
()
factory
.
post
(
'/'
,
data
=
{
'image'
:
simple_png
})
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