Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
7fcf4e3d
Commit
7fcf4e3d
authored
Jun 19, 2015
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! Enforce MAX_COMMENT_DEPTH in discussion_api
Add more extensive testing
parent
f47ab2bb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
13 deletions
+31
-13
lms/djangoapps/discussion_api/serializers.py
+1
-1
lms/djangoapps/discussion_api/tests/test_serializers.py
+30
-12
No files found.
lms/djangoapps/discussion_api/serializers.py
View file @
7fcf4e3d
...
@@ -303,7 +303,7 @@ class CommentSerializer(_ContentSerializer):
...
@@ -303,7 +303,7 @@ class CommentSerializer(_ContentSerializer):
"parent_id does not identify a comment in the thread identified by thread_id."
"parent_id does not identify a comment in the thread identified by thread_id."
)
)
if
is_comment_too_deep
(
parent
):
if
is_comment_too_deep
(
parent
):
raise
ValidationError
({
"parent_id"
:
[
"
Parent
is too deep."
]})
raise
ValidationError
({
"parent_id"
:
[
"
Comment level
is too deep."
]})
return
attrs
return
attrs
def
restore_object
(
self
,
attrs
,
instance
=
None
):
def
restore_object
(
self
,
attrs
,
instance
=
None
):
...
...
lms/djangoapps/discussion_api/tests/test_serializers.py
View file @
7fcf4e3d
...
@@ -644,18 +644,36 @@ class CommentSerializerDeserializationTest(CommentsServiceMockMixin, ModuleStore
...
@@ -644,18 +644,36 @@ class CommentSerializerDeserializationTest(CommentsServiceMockMixin, ModuleStore
}
}
)
)
def
test_create_parent_id_too_deep
(
self
):
@ddt.data
(
None
,
-
1
,
0
,
2
,
5
)
self
.
register_get_comment_response
({
def
test_create_parent_id_too_deep
(
self
,
max_depth
):
"id"
:
"test_parent"
,
with
mock
.
patch
(
"django_comment_client.utils.MAX_COMMENT_DEPTH"
,
max_depth
):
"thread_id"
:
"test_thread"
,
data
=
self
.
minimal_data
.
copy
()
"depth"
:
2
context
=
get_context
(
self
.
course
,
self
.
request
,
make_minimal_cs_thread
())
})
if
max_depth
is
None
or
max_depth
>=
0
:
data
=
self
.
minimal_data
.
copy
()
if
max_depth
!=
0
:
data
[
"parent_id"
]
=
"test_parent"
self
.
register_get_comment_response
({
context
=
get_context
(
self
.
course
,
self
.
request
,
make_minimal_cs_thread
())
"id"
:
"not_too_deep"
,
serializer
=
CommentSerializer
(
data
=
data
,
context
=
context
)
"thread_id"
:
"test_thread"
,
self
.
assertFalse
(
serializer
.
is_valid
())
"depth"
:
max_depth
-
1
if
max_depth
else
100
self
.
assertEqual
(
serializer
.
errors
,
{
"parent_id"
:
[
"Parent is too deep."
]})
})
data
[
"parent_id"
]
=
"not_too_deep"
else
:
data
[
"parent_id"
]
=
None
serializer
=
CommentSerializer
(
data
=
data
,
context
=
context
)
self
.
assertTrue
(
serializer
.
is_valid
(),
serializer
.
errors
)
if
max_depth
is
not
None
:
if
max_depth
>=
0
:
self
.
register_get_comment_response
({
"id"
:
"too_deep"
,
"thread_id"
:
"test_thread"
,
"depth"
:
max_depth
})
data
[
"parent_id"
]
=
"too_deep"
else
:
data
[
"parent_id"
]
=
None
serializer
=
CommentSerializer
(
data
=
data
,
context
=
context
)
self
.
assertFalse
(
serializer
.
is_valid
())
self
.
assertEqual
(
serializer
.
errors
,
{
"parent_id"
:
[
"Comment level is too deep."
]})
def
test_create_missing_field
(
self
):
def
test_create_missing_field
(
self
):
for
field
in
self
.
minimal_data
:
for
field
in
self
.
minimal_data
:
...
...
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