Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
fecadaca
Commit
fecadaca
authored
May 18, 2013
by
Oscar Vilaplana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests for form
parent
4dffcb5d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
4 deletions
+25
-4
rest_framework/fields.py
+3
-3
rest_framework/tests/fields.py
+22
-1
No files found.
rest_framework/fields.py
View file @
fecadaca
...
...
@@ -135,8 +135,7 @@ def humanize_field(field):
"""
humanized
=
{
'type'
:
(
field
.
type_name
if
field
.
type_name
else
humanize_field_type
(
field
.
form_field_class
)),
'type'
:
humanize_field_type
(
field
.
__class__
),
'required'
:
getattr
(
field
,
'required'
,
False
),
'label'
:
field
.
label
,
}
...
...
@@ -154,7 +153,8 @@ def humanize_form_fields(form):
:return: A dictionary of {field_label: humanized description}
"""
fields
=
SortedDict
([(
f
.
name
,
humanize_field
(
f
))
for
f
in
form
.
fields
])
fields
=
SortedDict
([(
name
,
humanize_field
(
field
))
for
name
,
field
in
form
.
fields
.
iteritems
()])
return
fields
...
...
rest_framework/tests/fields.py
View file @
fecadaca
...
...
@@ -4,7 +4,8 @@ General serializer field tests.
from
__future__
import
unicode_literals
from
django.utils.datastructures
import
SortedDict
import
datetime
from
rest_framework.fields
import
humanize_field
,
humanize_field_type
from
rest_framework.fields
import
(
humanize_field
,
humanize_field_type
,
humanize_form_fields
)
from
django
import
forms
from
decimal
import
Decimal
from
django.db
import
models
...
...
@@ -742,3 +743,23 @@ class HumanizedField(TestCase):
def
test_label
(
self
):
for
field
in
(
self
.
required_field
,
self
.
optional_field
):
self
.
assertEqual
(
humanize_field
(
field
)[
'label'
],
field
.
label
)
class
Form
(
forms
.
Form
):
field1
=
forms
.
CharField
(
max_length
=
3
,
label
=
'field one'
)
field2
=
forms
.
CharField
(
label
=
'field two'
)
class
HumanizedSerializer
(
TestCase
):
def
setUp
(
self
):
self
.
serializer
=
TimestampedModelSerializer
()
def
test_humanized
(
self
):
humanized
=
humanize_form_fields
(
Form
())
self
.
assertEqual
(
humanized
,
{
'field1'
:
{
u'help_text'
:
u''
,
u'required'
:
True
,
u'type'
:
u'Single Character'
,
u'label'
:
'field one'
},
'field2'
:
{
u'help_text'
:
u''
,
u'required'
:
True
,
u'type'
:
u'Single Character'
,
u'label'
:
'field two'
}})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment