From b4900ebd6a65aec8bdbcc54a23651d43066e165d Mon Sep 17 00:00:00 2001 From: Cristi Vijdea Date: Sat, 2 Mar 2019 05:35:10 +0200 Subject: [PATCH] Add tests for #310 --- testproj/articles/models.py | 1 + testproj/articles/serializers.py | 6 +++--- testproj/snippets/serializers.py | 1 + tests/reference.yaml | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/testproj/articles/models.py b/testproj/articles/models.py index bf1d4c9..c13522a 100644 --- a/testproj/articles/models.py +++ b/testproj/articles/models.py @@ -20,6 +20,7 @@ class Article(models.Model): on_delete=models.PROTECT) original_group = models.ForeignKey('ArticleGroup', related_name='articles_as_original', blank=True, default=None, on_delete=models.PROTECT) + read_only_nullable = models.CharField(max_length=20, null=True, blank=True) class ArticleGroup(models.Model): diff --git a/testproj/articles/serializers.py b/testproj/articles/serializers.py index 6867e16..bc29f6a 100644 --- a/testproj/articles/serializers.py +++ b/testproj/articles/serializers.py @@ -17,10 +17,9 @@ class ArticleSerializer(serializers.ModelSerializer): class Meta: 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', ) - read_only_fields = ('date_created', 'date_modified', - 'references', 'uuid', 'cover_name') + read_only_fields = ('date_created', 'date_modified', 'references', 'uuid', 'cover_name', 'read_only_nullable') lookup_field = 'slug' extra_kwargs = { '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, " "defaults to the currently logged in user.") }, + 'read_only_nullable': {'allow_null': True}, } diff --git a/testproj/snippets/serializers.py b/testproj/snippets/serializers.py index 156bf70..03d18c8 100644 --- a/testproj/snippets/serializers.py +++ b/testproj/snippets/serializers.py @@ -10,6 +10,7 @@ from snippets.models import LANGUAGE_CHOICES, STYLE_CHOICES, Snippet class LanguageSerializer(serializers.Serializer): name = serializers.ChoiceField( 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: ref_name = None diff --git a/tests/reference.yaml b/tests/reference.yaml index 46c31d1..fd6832b 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -902,6 +902,11 @@ definitions: type: string format: date-time readOnly: true + read_only_nullable: + type: string + readOnly: true + minLength: 1 + x-nullable: true references: description: this is a really bad example type: object @@ -1515,6 +1520,12 @@ definitions: - yaml+jinja - zephir default: python + readOnlyNullable: + title: Read only nullable + type: string + readOnly: true + minLength: 1 + x-nullable: true styles: type: array items: