mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-03 19:00:17 +03:00
fixed tests, added docs, renamed helper method
This commit is contained in:
parent
6bbedfd7ae
commit
7a5cd090aa
|
@ -15,8 +15,8 @@ from django.test import TestCase
|
|||
from django.utils.datastructures import SortedDict
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.fields import (humanize_field, humanize_field_type, humanize_form_fields,
|
||||
Field)
|
||||
from rest_framework.fields import (humanize_field, humanize_field_type,
|
||||
humanize_form_fields, Field)
|
||||
from rest_framework.serializers import Serializer
|
||||
from rest_framework.tests.models import RESTFrameworkModel
|
||||
|
||||
|
@ -882,10 +882,14 @@ class HumanizedSerializer(TestCase):
|
|||
|
||||
def test_humanized(self):
|
||||
humanized = humanize_form_fields(Form())
|
||||
self.assertEqual(humanized, {
|
||||
'field1': {
|
||||
u'help_text': u'', u'required': True,
|
||||
u'type': u'String', u'label': 'field one'},
|
||||
'field2': {
|
||||
u'help_text': u'', u'required': True,
|
||||
u'type': u'String', u'label': 'field two'}})
|
||||
expected = {
|
||||
'field1': {u'help_text': u'',
|
||||
u'label': u'field one',
|
||||
u'max_length': 3,
|
||||
u'required': True,
|
||||
u'type': u'String'},
|
||||
'field2': {u'help_text': u'',
|
||||
u'label': u'field two',
|
||||
u'required': True,
|
||||
u'type': u'String'}}
|
||||
self.assertEqual(humanized, expected)
|
||||
|
|
|
@ -131,6 +131,7 @@ class TestRootView(TestCase):
|
|||
# TODO add help_text and label when they are available
|
||||
#'help_text': '',
|
||||
#'label': None,
|
||||
'max_length': 100,
|
||||
'read_only': False,
|
||||
'required': True,
|
||||
'type': 'String',
|
||||
|
@ -272,6 +273,7 @@ class TestInstanceView(TestCase):
|
|||
# available
|
||||
#'description': '',
|
||||
#'label': None,
|
||||
'max_length': 100,
|
||||
'read_only': False,
|
||||
'required': True,
|
||||
'type': 'String',
|
||||
|
|
|
@ -61,15 +61,16 @@ class APIView(View):
|
|||
'renders': [renderer.media_type for renderer in self.renderer_classes],
|
||||
'parses': [parser.media_type for parser in self.parser_classes],
|
||||
}
|
||||
action_metadata = self._generate_action_metadata(request)
|
||||
if action_metadata is not None:
|
||||
content['actions'] = action_metadata
|
||||
content['actions'] = self.action_metadata(request)
|
||||
|
||||
return content
|
||||
|
||||
def _generate_action_metadata(self, request):
|
||||
"""
|
||||
Helper for generating the fields metadata for allowed and permitted methods.
|
||||
def action_metadata(self, request):
|
||||
"""Return a dictionary with the fields required fo reach allowed method. If no method is allowed,
|
||||
return an empty dictionary.
|
||||
|
||||
:param request: Request for which to return the metadata of the allowed methods.
|
||||
:return: A dictionary of the form {method: {field: {field attribute: value}}}
|
||||
"""
|
||||
actions = {}
|
||||
for method in self.allowed_methods:
|
||||
|
|
Loading…
Reference in New Issue
Block a user