mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Add file upload test for APIRequestFactory
Remove test_compat
This commit is contained in:
parent
74fec7eeb4
commit
78e4468f03
|
@ -1,13 +0,0 @@
|
|||
import django
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class TestCompat(TestCase):
|
||||
def test_force_bytes_or_smart_bytes(self):
|
||||
from rest_framework.compat import force_bytes_or_smart_bytes
|
||||
if django.VERSION >= (1, 5):
|
||||
from django.utils.encoding import force_bytes
|
||||
self.assertEqual(force_bytes_or_smart_bytes, force_bytes)
|
||||
else:
|
||||
from django.utils.encoding import smart_str
|
||||
self.assertEqual(force_bytes_or_smart_bytes, smart_str)
|
|
@ -1,6 +1,8 @@
|
|||
# -- 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'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\rIDATx\x9cc````\x00\x00\x00\x05\x00\x01\xa5\xf6E@\x00\x00\x00\x00IEND\xaeB`\x82')
|
||||
simple_png.name = 'test.png'
|
||||
factory = APIRequestFactory()
|
||||
factory.post('/', data={'image': simple_png})
|
||||
|
|
Loading…
Reference in New Issue
Block a user