mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
Add check for serializers.HiddenField
on fields_for_serializer
function (#1419)
* Add check for `serializers.HiddenField` on fields_for_serializer function * Add pre-commit changes
This commit is contained in:
parent
520ddeabf6
commit
8934393909
|
@ -39,6 +39,9 @@ def fields_for_serializer(
|
|||
field.read_only
|
||||
and is_input
|
||||
and lookup_field != name, # don't show read_only fields in Input
|
||||
isinstance(
|
||||
field, serializers.HiddenField
|
||||
), # don't show hidden fields in Input
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -164,6 +164,21 @@ def test_read_only_fields():
|
|||
), "'cool_name' is read_only field and shouldn't be on arguments"
|
||||
|
||||
|
||||
def test_hidden_fields():
|
||||
class SerializerWithHiddenField(serializers.Serializer):
|
||||
cool_name = serializers.CharField()
|
||||
user = serializers.HiddenField(default=serializers.CurrentUserDefault())
|
||||
|
||||
class MyMutation(SerializerMutation):
|
||||
class Meta:
|
||||
serializer_class = SerializerWithHiddenField
|
||||
|
||||
assert "cool_name" in MyMutation.Input._meta.fields
|
||||
assert (
|
||||
"user" not in MyMutation.Input._meta.fields
|
||||
), "'user' is hidden field and shouldn't be on arguments"
|
||||
|
||||
|
||||
def test_nested_model():
|
||||
class MyFakeModelGrapheneType(DjangoObjectType):
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in New Issue
Block a user