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
16ffe5e3
Commit
16ffe5e3
authored
Feb 26, 2015
by
Evan Heidtmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for callable attributes raising exceptions
parent
4248a8d3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
tests/test_fields.py
+25
-0
No files found.
tests/test_fields.py
View file @
16ffe5e3
...
...
@@ -93,6 +93,31 @@ class TestSource:
"same as the field name. Remove the `source` keyword argument."
)
def
test_callable_source
(
self
):
class
ExampleSerializer
(
serializers
.
Serializer
):
example_field
=
serializers
.
CharField
(
source
=
'example_callable'
)
class
ExampleInstance
(
object
):
def
example_callable
(
self
):
return
'example callable value'
serializer
=
ExampleSerializer
(
ExampleInstance
())
assert
serializer
.
data
[
'example_field'
]
==
'example callable value'
def
test_callable_source_raises
(
self
):
class
ExampleSerializer
(
serializers
.
Serializer
):
example_field
=
serializers
.
CharField
(
source
=
'example_callable'
,
read_only
=
True
)
class
ExampleInstance
(
object
):
def
example_callable
(
self
):
raise
AttributeError
(
'method call failed'
)
with
pytest
.
raises
(
ValueError
)
as
exc_info
:
serializer
=
ExampleSerializer
(
ExampleInstance
())
serializer
.
data
.
items
()
assert
'method call failed'
in
str
(
exc_info
.
value
)
class
TestReadOnly
:
def
setup
(
self
):
...
...
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