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
3cc5349b
Commit
3cc5349b
authored
Nov 20, 2012
by
Jamie Matthews
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up and clarify tests for related serializers
parent
68c39737
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
rest_framework/tests/serializer.py
+13
-16
No files found.
rest_framework/tests/serializer.py
View file @
3cc5349b
...
@@ -479,7 +479,10 @@ class CallableDefaultValueTests(TestCase):
...
@@ -479,7 +479,10 @@ class CallableDefaultValueTests(TestCase):
class
ManyRelatedTests
(
TestCase
):
class
ManyRelatedTests
(
TestCase
):
def
setUp
(
self
):
def
test_reverse_relations
(
self
):
post
=
BlogPost
.
objects
.
create
(
title
=
"Test blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I hate this blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I love this blog post"
)
class
BlogPostCommentSerializer
(
serializers
.
Serializer
):
class
BlogPostCommentSerializer
(
serializers
.
Serializer
):
text
=
serializers
.
CharField
()
text
=
serializers
.
CharField
()
...
@@ -488,15 +491,7 @@ class ManyRelatedTests(TestCase):
...
@@ -488,15 +491,7 @@ class ManyRelatedTests(TestCase):
title
=
serializers
.
CharField
()
title
=
serializers
.
CharField
()
comments
=
BlogPostCommentSerializer
(
source
=
'blogpostcomment_set'
)
comments
=
BlogPostCommentSerializer
(
source
=
'blogpostcomment_set'
)
self
.
comment_serializer_class
=
BlogPostCommentSerializer
serializer
=
BlogPostSerializer
(
instance
=
post
)
self
.
serializer_class
=
BlogPostSerializer
def
test_reverse_relations
(
self
):
post
=
BlogPost
.
objects
.
create
(
title
=
"Test blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I hate this blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I love this blog post"
)
serializer
=
self
.
serializer_class
(
instance
=
post
)
expected
=
{
expected
=
{
'title'
:
'Test blog post'
,
'title'
:
'Test blog post'
,
'comments'
:
[
'comments'
:
[
...
@@ -511,15 +506,17 @@ class ManyRelatedTests(TestCase):
...
@@ -511,15 +506,17 @@ class ManyRelatedTests(TestCase):
post
=
BlogPost
.
objects
.
create
(
title
=
"Test blog post"
)
post
=
BlogPost
.
objects
.
create
(
title
=
"Test blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I love this blog post"
)
post
.
blogpostcomment_set
.
create
(
text
=
"I love this blog post"
)
class
ExtendedBlogPostSerializer
(
self
.
serializer_class
):
class
BlogPostCommentSerializer
(
serializers
.
Serializer
):
first_comment
=
self
.
comment_serializer_class
(
source
=
'get_first_comment'
)
text
=
serializers
.
CharField
()
class
BlogPostSerializer
(
serializers
.
Serializer
):
title
=
serializers
.
CharField
()
first_comment
=
BlogPostCommentSerializer
(
source
=
'get_first_comment'
)
serializer
=
BlogPostSerializer
(
post
)
serializer
=
ExtendedBlogPostSerializer
(
post
)
expected
=
{
expected
=
{
'title'
:
'Test blog post'
,
'title'
:
'Test blog post'
,
'comments'
:
[
{
'text'
:
'I love this blog post'
}
],
'first_comment'
:
{
'text'
:
'I love this blog post'
}
'first_comment'
:
{
'text'
:
'I love this blog post'
}
}
}
self
.
assertEqual
(
serializer
.
data
,
expected
)
self
.
assertEqual
(
serializer
.
data
,
expected
)
...
...
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