Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
7fcf4e3d
Commit
7fcf4e3d
authored
9 years ago
by
Greg Price
Browse files
Options
Downloads
Patches
Plain Diff
fixup! Enforce MAX_COMMENT_DEPTH in discussion_api
Add more extensive testing
parent
f47ab2bb
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/discussion_api/serializers.py
+1
-1
1 addition, 1 deletion
lms/djangoapps/discussion_api/serializers.py
lms/djangoapps/discussion_api/tests/test_serializers.py
+30
-12
30 additions, 12 deletions
lms/djangoapps/discussion_api/tests/test_serializers.py
with
31 additions
and
13 deletions
lms/djangoapps/discussion_api/serializers.py
+
1
−
1
View file @
7fcf4e3d
...
...
@@ -303,7 +303,7 @@ class CommentSerializer(_ContentSerializer):
"
parent_id does not identify a comment in the thread identified by thread_id.
"
)
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
def
restore_object
(
self
,
attrs
,
instance
=
None
):
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/discussion_api/tests/test_serializers.py
+
30
−
12
View file @
7fcf4e3d
...
...
@@ -644,18 +644,36 @@ class CommentSerializerDeserializationTest(CommentsServiceMockMixin, ModuleStore
}
)
def
test_create_parent_id_too_deep
(
self
):
self
.
register_get_comment_response
({
"
id
"
:
"
test_parent
"
,
"
thread_id
"
:
"
test_thread
"
,
"
depth
"
:
2
})
data
=
self
.
minimal_data
.
copy
()
data
[
"
parent_id
"
]
=
"
test_parent
"
context
=
get_context
(
self
.
course
,
self
.
request
,
make_minimal_cs_thread
())
serializer
=
CommentSerializer
(
data
=
data
,
context
=
context
)
self
.
assertFalse
(
serializer
.
is_valid
())
self
.
assertEqual
(
serializer
.
errors
,
{
"
parent_id
"
:
[
"
Parent is too deep.
"
]})
@ddt.data
(
None
,
-
1
,
0
,
2
,
5
)
def
test_create_parent_id_too_deep
(
self
,
max_depth
):
with
mock
.
patch
(
"
django_comment_client.utils.MAX_COMMENT_DEPTH
"
,
max_depth
):
data
=
self
.
minimal_data
.
copy
()
context
=
get_context
(
self
.
course
,
self
.
request
,
make_minimal_cs_thread
())
if
max_depth
is
None
or
max_depth
>=
0
:
if
max_depth
!=
0
:
self
.
register_get_comment_response
({
"
id
"
:
"
not_too_deep
"
,
"
thread_id
"
:
"
test_thread
"
,
"
depth
"
:
max_depth
-
1
if
max_depth
else
100
})
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
):
for
field
in
self
.
minimal_data
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment