Add tests for #310

master
Cristi Vijdea 2019-03-02 05:35:10 +02:00
parent c593b3fcfb
commit b4900ebd6a
4 changed files with 16 additions and 3 deletions

View File

@ -20,6 +20,7 @@ class Article(models.Model):
on_delete=models.PROTECT) on_delete=models.PROTECT)
original_group = models.ForeignKey('ArticleGroup', related_name='articles_as_original', blank=True, default=None, original_group = models.ForeignKey('ArticleGroup', related_name='articles_as_original', blank=True, default=None,
on_delete=models.PROTECT) on_delete=models.PROTECT)
read_only_nullable = models.CharField(max_length=20, null=True, blank=True)
class ArticleGroup(models.Model): class ArticleGroup(models.Model):

View File

@ -17,10 +17,9 @@ class ArticleSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Article model = Article
fields = ('title', 'author', 'body', 'slug', 'date_created', 'date_modified', fields = ('title', 'author', 'body', 'slug', 'date_created', 'date_modified', 'read_only_nullable',
'references', 'uuid', 'cover', 'cover_name', 'article_type', 'group', 'original_group', ) 'references', 'uuid', 'cover', 'cover_name', 'article_type', 'group', 'original_group', )
read_only_fields = ('date_created', 'date_modified', read_only_fields = ('date_created', 'date_modified', 'references', 'uuid', 'cover_name', 'read_only_nullable')
'references', 'uuid', 'cover_name')
lookup_field = 'slug' lookup_field = 'slug'
extra_kwargs = { extra_kwargs = {
'body': {'help_text': 'body serializer help_text'}, 'body': {'help_text': 'body serializer help_text'},
@ -29,6 +28,7 @@ class ArticleSerializer(serializers.ModelSerializer):
'help_text': _("The ID of the user that created this article; if none is provided, " 'help_text': _("The ID of the user that created this article; if none is provided, "
"defaults to the currently logged in user.") "defaults to the currently logged in user.")
}, },
'read_only_nullable': {'allow_null': True},
} }

View File

@ -10,6 +10,7 @@ from snippets.models import LANGUAGE_CHOICES, STYLE_CHOICES, Snippet
class LanguageSerializer(serializers.Serializer): class LanguageSerializer(serializers.Serializer):
name = serializers.ChoiceField( name = serializers.ChoiceField(
choices=LANGUAGE_CHOICES, default='python', help_text='The name of the programming language') choices=LANGUAGE_CHOICES, default='python', help_text='The name of the programming language')
read_only_nullable = serializers.CharField(read_only=True, allow_null=True)
class Meta: class Meta:
ref_name = None ref_name = None

View File

@ -902,6 +902,11 @@ definitions:
type: string type: string
format: date-time format: date-time
readOnly: true readOnly: true
read_only_nullable:
type: string
readOnly: true
minLength: 1
x-nullable: true
references: references:
description: this is a really bad example description: this is a really bad example
type: object type: object
@ -1515,6 +1520,12 @@ definitions:
- yaml+jinja - yaml+jinja
- zephir - zephir
default: python default: python
readOnlyNullable:
title: Read only nullable
type: string
readOnly: true
minLength: 1
x-nullable: true
styles: styles:
type: array type: array
items: items: