Skip to content

Commit

Permalink
Merge pull request encode#3908 from kostya0shift/fix_exceptions_force…
Browse files Browse the repository at this point in the history
…_text

Fixed _force_text_recursive typo
  • Loading branch information
xordoquy committed Feb 12, 2016
2 parents 8c1365e + b6adfab commit 3693e93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rest_framework/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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)
for key, value in data.items()
}
if isinstance(data, ReturnDict):
return ReturnDict(ret, serializer=data.serializer)
return data
return ret
return force_text(data)


Expand Down
21 changes: 21 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 3693e93

Please sign in to comment.