mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-11 09:03:20 +03:00
#467 Added unit test
This commit is contained in:
parent
9ae0ca1cae
commit
ad01fa0eae
|
@ -428,11 +428,11 @@ class ModelSerializer(Serializer):
|
||||||
if max_length:
|
if max_length:
|
||||||
kwargs['max_length'] = max_length
|
kwargs['max_length'] = max_length
|
||||||
|
|
||||||
if model_field.verbose_name:
|
if model_field.verbose_name is not None:
|
||||||
kwargs['label'] = model_field.verbose_name
|
kwargs['label'] = smart_unicode(model_field.verbose_name)
|
||||||
|
|
||||||
if model_field.help_text:
|
if model_field.help_text is not None:
|
||||||
kwargs['help_text'] = model_field.help_text
|
kwargs['help_text'] = smart_unicode(model_field.help_text)
|
||||||
|
|
||||||
field_mapping = {
|
field_mapping = {
|
||||||
models.FloatField: FloatField,
|
models.FloatField: FloatField,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
|
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# from django.contrib.auth.models import Group
|
# from django.contrib.auth.models import Group
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ class Anchor(RESTFrameworkModel):
|
||||||
|
|
||||||
|
|
||||||
class BasicModel(RESTFrameworkModel):
|
class BasicModel(RESTFrameworkModel):
|
||||||
text = models.CharField(max_length=100)
|
text = models.CharField(max_length=100, verbose_name=_("Text"), help_text=_("Text description."))
|
||||||
|
|
||||||
|
|
||||||
class SlugBasedModel(RESTFrameworkModel):
|
class SlugBasedModel(RESTFrameworkModel):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers, fields
|
||||||
from rest_framework.tests.models import (ActionItem, Anchor, BasicModel,
|
from rest_framework.tests.models import (ActionItem, Anchor, BasicModel,
|
||||||
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
BlankFieldModel, BlogPost, Book, CallableDefaultValueModel, DefaultValueModel,
|
||||||
ManyToManyModel, Person, ReadOnlyManyToManyModel)
|
ManyToManyModel, Person, ReadOnlyManyToManyModel)
|
||||||
|
@ -48,7 +48,7 @@ class BookSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class ActionItemSerializer(serializers.ModelSerializer):
|
class ActionItemSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ActionItem
|
model = ActionItem
|
||||||
|
|
||||||
|
@ -641,3 +641,26 @@ class BlankFieldTests(TestCase):
|
||||||
"""
|
"""
|
||||||
serializer = self.not_blank_model_serializer_class(data=self.data)
|
serializer = self.not_blank_model_serializer_class(data=self.data)
|
||||||
self.assertEquals(serializer.is_valid(), False)
|
self.assertEquals(serializer.is_valid(), False)
|
||||||
|
|
||||||
|
|
||||||
|
# Test for issue #467
|
||||||
|
class FieldLabelTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
class LabelModelSerializer(serializers.ModelSerializer):
|
||||||
|
# This is check that ctor supports both fields
|
||||||
|
additional = fields.CharField(label='Label', help_text='Help')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = BasicModel
|
||||||
|
|
||||||
|
self.serializer_class = LabelModelSerializer
|
||||||
|
|
||||||
|
def test_label_from_model(self):
|
||||||
|
"""
|
||||||
|
Validates that label and help_text are correctly copied from the model class.
|
||||||
|
"""
|
||||||
|
serializer = self.serializer_class()
|
||||||
|
text_field = serializer.fields['text']
|
||||||
|
|
||||||
|
self.assertEquals('Text', text_field.label)
|
||||||
|
self.assertEquals('Text description.', text_field.help_text)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user