Include nested objects in metadata for OPTIONS. Closes #3156. Closes #2915.

This commit is contained in:
Tom Christie 2015-07-16 15:17:18 +01:00
parent 81709a2c73
commit 806b0b34da
3 changed files with 36 additions and 1 deletions

View File

@ -133,6 +133,8 @@ class SimpleMetadata(BaseMetadata):
if getattr(field, 'child', None):
field_info['child'] = self.get_field_info(field.child)
elif getattr(field, 'fields', None):
field_info['children'] = self.get_serializer_info(field)
if not field_info.get('read_only') and hasattr(field, 'choices'):
field_info['choices'] = [

View File

@ -8,7 +8,7 @@ import sys
import pytest
PYTEST_ARGS = {
'default': ['tests', '--tb=short', '-s', '--cov', 'rest_framework'],
'default': ['tests', '--tb=short', '-s'],
'fast': ['tests', '--tb=short', '-q', '-s'],
}
@ -87,6 +87,14 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
pytest_args = sys.argv[1:]
first_arg = pytest_args[0]
try:
pytest_args.remove('--coverage')
except ValueError:
pass
else:
pytest_args = ['--cov', 'rest_framework'] + pytest_args
if first_arg.startswith('-'):
# `runtests.py [flags]`
pytest_args = ['tests'] + pytest_args

View File

@ -59,6 +59,10 @@ class TestMetadata:
On generic views OPTIONS should return an 'actions' key with metadata
on the fields that may be supplied to PUT and POST requests.
"""
class NestedField(serializers.Serializer):
a = serializers.IntegerField()
b = serializers.IntegerField()
class ExampleSerializer(serializers.Serializer):
choice_field = serializers.ChoiceField(['red', 'green', 'blue'])
integer_field = serializers.IntegerField(
@ -72,6 +76,7 @@ class TestMetadata:
child=serializers.IntegerField()
)
)
nested_field = NestedField()
class ExampleView(views.APIView):
"""Example view."""
@ -140,6 +145,26 @@ class TestMetadata:
'read_only': False
}
}
},
'nested_field': {
'type': 'nested object',
'required': True,
'read_only': False,
'label': 'Nested field',
'children': {
'a': {
'type': 'integer',
'required': True,
'read_only': False,
'label': 'A'
},
'b': {
'type': 'integer',
'required': True,
'read_only': False,
'label': 'B'
}
}
}
}
}