diff options
| author | Ian Foote | 2014-01-28 14:30:46 +0000 | 
|---|---|---|
| committer | Ian Foote | 2014-01-28 14:30:46 +0000 | 
| commit | 74fec7eeb4e7e2e593ed5e2213020024264681ce (patch) | |
| tree | d26cb749dd95eaea41d03abac755544283335f23 | |
| parent | 0383f11ff747b1236f7ca25e95a3652a1bbebb14 (diff) | |
| download | django-rest-framework-74fec7eeb4e7e2e593ed5e2213020024264681ce.tar.bz2 | |
Import force_bytes on django >= 1.5
| -rw-r--r-- | rest_framework/compat.py | 2 | ||||
| -rw-r--r-- | rest_framework/tests/test_compat.py | 13 | 
2 files changed, 14 insertions, 1 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py index b69749fe..d283e2f5 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -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 diff --git a/rest_framework/tests/test_compat.py b/rest_framework/tests/test_compat.py new file mode 100644 index 00000000..4916d19b --- /dev/null +++ b/rest_framework/tests/test_compat.py @@ -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)  | 
