|
4 | 4 | from __future__ import unicode_literals
|
5 | 5 | from django.utils.datastructures import SortedDict
|
6 | 6 | import datetime
|
7 |
| -from rest_framework.fields import humanize_field, humanize_field_type |
| 7 | +from rest_framework.fields import (humanize_field, humanize_field_type, |
| 8 | + humanize_form_fields) |
8 | 9 | from django import forms
|
9 | 10 | from decimal import Decimal
|
10 | 11 | from django.db import models
|
@@ -742,3 +743,23 @@ def test_optional(self):
|
742 | 743 | def test_label(self):
|
743 | 744 | for field in (self.required_field, self.optional_field):
|
744 | 745 | self.assertEqual(humanize_field(field)['label'], field.label)
|
| 746 | + |
| 747 | + |
| 748 | +class Form(forms.Form): |
| 749 | + field1 = forms.CharField(max_length=3, label='field one') |
| 750 | + field2 = forms.CharField(label='field two') |
| 751 | + |
| 752 | + |
| 753 | +class HumanizedSerializer(TestCase): |
| 754 | + def setUp(self): |
| 755 | + self.serializer = TimestampedModelSerializer() |
| 756 | + |
| 757 | + def test_humanized(self): |
| 758 | + humanized = humanize_form_fields(Form()) |
| 759 | + self.assertEqual(humanized, { |
| 760 | + 'field1': { |
| 761 | + u'help_text': u'', u'required': True, |
| 762 | + u'type': u'Single Character', u'label': 'field one'}, |
| 763 | + 'field2': { |
| 764 | + u'help_text': u'', u'required': True, |
| 765 | + u'type': u'Single Character', u'label': 'field two'}}) |
0 commit comments