Skip to content

Commit

Permalink
Add tests for #310
Browse files Browse the repository at this point in the history
  • Loading branch information
axnsan12 committed Mar 2, 2019
1 parent c593b3f commit b4900eb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions testproj/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions testproj/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand All @@ -29,6 +28,7 @@ class Meta:
'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},
}


Expand Down
1 change: 1 addition & 0 deletions testproj/snippets/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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
Expand Down
11 changes: 11 additions & 0 deletions tests/reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b4900eb

Please sign in to comment.