1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Added custom field API tests

This commit is contained in:
Jeremy Stretch
2017-04-25 14:53:18 -04:00
parent 10823e1c37
commit 1c86b00b5c
3 changed files with 221 additions and 5 deletions

View File

@@ -32,6 +32,12 @@ class CustomFieldsSerializer(serializers.BaseSerializer):
if parent_content_type not in cf.obj_type.all():
raise ValidationError(u"Invalid custom field for {} objects".format(parent_content_type))
# Validate selected choice
if cf.type == CF_TYPE_SELECT:
valid_choices = [c.pk for c in cf.choices.all()]
if value not in valid_choices:
raise ValidationError(u"Invalid choice ({}) for field {}".format(value, custom_field))
return data