Import force_bytes on django >= 1.5

This commit is contained in:
Ian Foote 2014-01-28 14:30:46 +00:00
parent 0383f11ff7
commit 74fec7eeb4
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,13 @@
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)