Merge pull request #3908 from kostya0shift/fix_exceptions_force_text

Fixed _force_text_recursive typo
This commit is contained in:
Xavier Ordoquy 2016-02-12 08:24:13 +01:00
commit 3693e938a4
2 changed files with 23 additions and 2 deletions

View File

@ -28,7 +28,7 @@ def _force_text_recursive(data):
]
if isinstance(data, ReturnList):
return ReturnList(ret, serializer=data.serializer)
return data
return ret
elif isinstance(data, dict):
ret = {
key: _force_text_recursive(value)
@ -36,7 +36,7 @@ def _force_text_recursive(data):
}
if isinstance(data, ReturnDict):
return ReturnDict(ret, serializer=data.serializer)
return data
return ret
return force_text(data)

21
tests/test_exceptions.py Normal file
View File

@ -0,0 +1,21 @@
from __future__ import unicode_literals
from django.test import TestCase
from django.utils.translation import ugettext_lazy as _
from rest_framework.exceptions import _force_text_recursive
class ExceptionTestCase(TestCase):
def test_force_text_recursive(self):
s = "sfdsfggiuytraetfdlklj"
self.assertEqual(_force_text_recursive(_(s)), s)
self.assertEqual(type(_force_text_recursive(_(s))), type(s))
self.assertEqual(_force_text_recursive({'a': _(s)})['a'], s)
self.assertEqual(type(_force_text_recursive({'a': _(s)})['a']), type(s))
self.assertEqual(_force_text_recursive([[_(s)]])[0][0], s)
self.assertEqual(type(_force_text_recursive([[_(s)]])[0][0]), type(s))