mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
First pass at serializer repr bug
This commit is contained in:
parent
a72f812d80
commit
5e7c9687c7
|
@ -2,6 +2,7 @@
|
||||||
Helper functions for creating user-friendly representations
|
Helper functions for creating user-friendly representations
|
||||||
of serializer classes and serializer fields.
|
of serializer classes and serializer fields.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
|
@ -24,7 +25,7 @@ def smart_repr(value):
|
||||||
if isinstance(value, Promise) and value._delegate_text:
|
if isinstance(value, Promise) and value._delegate_text:
|
||||||
value = force_text(value)
|
value = force_text(value)
|
||||||
|
|
||||||
value = repr(value)
|
value = repr(value).decode('utf-8')
|
||||||
|
|
||||||
# Representations like u'help text'
|
# Representations like u'help text'
|
||||||
# should simply be presented as 'help text'
|
# should simply be presented as 'help text'
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -197,3 +198,19 @@ class TestIncorrectlyConfigured:
|
||||||
"The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.\n"
|
"The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.\n"
|
||||||
"Original exception text was:"
|
"Original exception text was:"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUnicodeRepr:
|
||||||
|
def test_unicode_repr(self):
|
||||||
|
class ExampleSerializer(serializers.Serializer):
|
||||||
|
example = serializers.CharField()
|
||||||
|
|
||||||
|
class ExampleObject:
|
||||||
|
def __init__(self):
|
||||||
|
self.example = '한국'
|
||||||
|
def __repr__(self):
|
||||||
|
return self.example.encode('utf8')
|
||||||
|
|
||||||
|
instance = ExampleObject()
|
||||||
|
serializer = ExampleSerializer(instance)
|
||||||
|
repr(serializer)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user