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
18956af0
Commit
18956af0
authored
Dec 14, 2015
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jia/MA-1815 retrieve count for child comments
parent
34cecaee
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
22 deletions
+99
-22
lms/djangoapps/discussion_api/serializers.py
+1
-0
lms/djangoapps/discussion_api/tests/test_api.py
+8
-2
lms/djangoapps/discussion_api/tests/test_serializers.py
+2
-0
lms/djangoapps/discussion_api/tests/test_views.py
+86
-20
lms/djangoapps/discussion_api/tests/utils.py
+1
-0
lms/lib/comment_client/comment.py
+1
-0
No files found.
lms/djangoapps/discussion_api/serializers.py
View file @
18956af0
...
...
@@ -290,6 +290,7 @@ class CommentSerializer(_ContentSerializer):
endorsed_by
=
serializers
.
SerializerMethodField
()
endorsed_by_label
=
serializers
.
SerializerMethodField
()
endorsed_at
=
serializers
.
SerializerMethodField
()
child_count
=
serializers
.
IntegerField
(
read_only
=
True
)
children
=
serializers
.
SerializerMethodField
(
required
=
False
)
non_updatable_fields
=
NON_UPDATABLE_COMMENT_FIELDS
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
18956af0
...
...
@@ -1136,6 +1136,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"endorsed"
:
False
,
"abuse_flaggers"
:
[],
"votes"
:
{
"up_count"
:
4
},
"child_count"
:
0
,
"children"
:
[],
},
{
...
...
@@ -1152,6 +1153,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"endorsed"
:
False
,
"abuse_flaggers"
:
[
str
(
self
.
user
.
id
)],
"votes"
:
{
"up_count"
:
7
},
"child_count"
:
0
,
"children"
:
[],
}
]
...
...
@@ -1174,6 +1176,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"voted"
:
False
,
"vote_count"
:
4
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"child_count"
:
0
,
"children"
:
[],
},
{
...
...
@@ -1194,6 +1197,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"voted"
:
False
,
"vote_count"
:
7
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"child_count"
:
0
,
"children"
:
[],
},
]
...
...
@@ -1688,7 +1692,8 @@ class CreateCommentTest(
"voted"
:
False
,
"vote_count"
:
0
,
"children"
:
[],
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
]
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
],
"child_count"
:
0
,
}
self
.
assertEqual
(
actual
,
expected
)
expected_url
=
(
...
...
@@ -2377,7 +2382,8 @@ class UpdateCommentTest(
"voted"
:
False
,
"vote_count"
:
0
,
"children"
:
[],
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
]
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
],
"child_count"
:
0
,
}
self
.
assertEqual
(
actual
,
expected
)
self
.
assertEqual
(
...
...
lms/djangoapps/discussion_api/tests/test_serializers.py
View file @
18956af0
...
...
@@ -312,6 +312,7 @@ class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase):
"abuse_flaggers"
:
[],
"votes"
:
{
"up_count"
:
4
},
"children"
:
[],
"child_count"
:
0
,
}
expected
=
{
"id"
:
"test_comment"
,
...
...
@@ -332,6 +333,7 @@ class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase):
"vote_count"
:
4
,
"children"
:
[],
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"child_count"
:
0
,
}
self
.
assertEqual
(
self
.
serialize
(
comment
),
expected
)
...
...
lms/djangoapps/discussion_api/tests/test_views.py
View file @
18956af0
...
...
@@ -884,6 +884,34 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
overrides
.
setdefault
(
"course_id"
,
unicode
(
self
.
course
.
id
))
return
make_minimal_cs_thread
(
overrides
)
def
expected_response_comment
(
self
,
overrides
=
None
):
"""
create expected response data
"""
response_data
=
{
"id"
:
"test_comment"
,
"thread_id"
:
self
.
thread_id
,
"parent_id"
:
None
,
"author"
:
self
.
author
.
username
,
"author_label"
:
None
,
"created_at"
:
"1970-01-01T00:00:00Z"
,
"updated_at"
:
"1970-01-01T00:00:00Z"
,
"raw_body"
:
"dummy"
,
"rendered_body"
:
"<p>dummy</p>"
,
"endorsed"
:
False
,
"endorsed_by"
:
None
,
"endorsed_by_label"
:
None
,
"endorsed_at"
:
None
,
"abuse_flagged"
:
False
,
"voted"
:
False
,
"vote_count"
:
0
,
"children"
:
[],
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"child_count"
:
0
,
}
response_data
.
update
(
overrides
or
{})
return
response_data
def
test_thread_id_missing
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assert_response_correct
(
...
...
@@ -918,27 +946,17 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"endorsed"
:
False
,
"abuse_flaggers"
:
[],
"votes"
:
{
"up_count"
:
4
},
"child_count"
:
0
,
"children"
:
[],
}]
expected_comments
=
[{
"id"
:
"test_comment"
,
"thread_id"
:
self
.
thread_id
,
"parent_id"
:
None
,
"author"
:
self
.
author
.
username
,
"author_label"
:
None
,
"created_at"
:
"2015-05-11T00:00:00Z"
,
"updated_at"
:
"2015-05-11T11:11:11Z"
,
"raw_body"
:
"Test body"
,
"rendered_body"
:
"<p>Test body</p>"
,
"endorsed"
:
False
,
"endorsed_by"
:
None
,
"endorsed_by_label"
:
None
,
"endorsed_at"
:
None
,
"abuse_flagged"
:
False
,
expected_comments
=
[
self
.
expected_response_comment
(
overrides
=
{
"voted"
:
True
,
"vote_count"
:
4
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"children"
:
[],
}]
"raw_body"
:
"Test body"
,
"rendered_body"
:
"<p>Test body</p>"
,
"created_at"
:
"2015-05-11T00:00:00Z"
,
"updated_at"
:
"2015-05-11T11:11:11Z"
,
})]
self
.
register_get_thread_response
({
"id"
:
self
.
thread_id
,
"course_id"
:
unicode
(
self
.
course
.
id
),
...
...
@@ -979,7 +997,6 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"id"
:
self
.
thread_id
,
"course_id"
:
unicode
(
self
.
course
.
id
),
"thread_type"
:
"discussion"
,
"children"
:
[],
"resp_total"
:
10
,
}))
response
=
self
.
client
.
get
(
...
...
@@ -1060,6 +1077,52 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
}}
)
def
test_child_comments_count
(
self
):
self
.
register_get_user_response
(
self
.
user
)
response_1
=
make_minimal_cs_comment
({
"id"
:
"test_response_1"
,
"thread_id"
:
self
.
thread_id
,
"user_id"
:
str
(
self
.
author
.
id
),
"username"
:
self
.
author
.
username
,
"child_count"
:
2
,
})
response_2
=
make_minimal_cs_comment
({
"id"
:
"test_response_2"
,
"thread_id"
:
self
.
thread_id
,
"user_id"
:
str
(
self
.
author
.
id
),
"username"
:
self
.
author
.
username
,
"child_count"
:
3
,
})
thread
=
self
.
make_minimal_cs_thread
({
"id"
:
self
.
thread_id
,
"course_id"
:
unicode
(
self
.
course
.
id
),
"thread_type"
:
"discussion"
,
"children"
:
[
response_1
,
response_2
],
"resp_total"
:
2
,
"comments_count"
:
8
,
"unread_comments_count"
:
0
,
})
self
.
register_get_thread_response
(
thread
)
response
=
self
.
client
.
get
(
self
.
url
,
{
"thread_id"
:
self
.
thread_id
})
expected_comments
=
[
self
.
expected_response_comment
(
overrides
=
{
"id"
:
"test_response_1"
,
"child_count"
:
2
}),
self
.
expected_response_comment
(
overrides
=
{
"id"
:
"test_response_2"
,
"child_count"
:
3
}),
]
self
.
assert_response_correct
(
response
,
200
,
{
"results"
:
expected_comments
,
"pagination"
:
{
"count"
:
2
,
"next"
:
None
,
"num_pages"
:
1
,
"previous"
:
None
,
}
}
)
@httpretty.activate
@disable_signal
(
api
,
'comment_deleted'
)
...
...
@@ -1139,6 +1202,7 @@ class CommentViewSetCreateTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"vote_count"
:
0
,
"children"
:
[],
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
],
"child_count"
:
0
,
}
response
=
self
.
client
.
post
(
self
.
url
,
...
...
@@ -1227,6 +1291,7 @@ class CommentViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTes
"vote_count"
:
0
,
"children"
:
[],
"editable_fields"
:
[],
"child_count"
:
0
,
}
response_data
.
update
(
overrides
or
{})
return
response_data
...
...
@@ -1429,7 +1494,8 @@ class CommentViewSetRetrieveTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase
"voted"
:
False
,
"vote_count"
:
0
,
"abuse_flagged"
:
False
,
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
]
"editable_fields"
:
[
"abuse_flagged"
,
"raw_body"
,
"voted"
],
"child_count"
:
0
,
}
response
=
self
.
client
.
get
(
self
.
url
)
...
...
lms/djangoapps/discussion_api/tests/utils.py
View file @
18956af0
...
...
@@ -371,6 +371,7 @@ def make_minimal_cs_comment(overrides=None):
"abuse_flaggers"
:
[],
"votes"
:
{
"up_count"
:
0
},
"endorsed"
:
False
,
"child_count"
:
0
,
"children"
:
[],
}
ret
.
update
(
overrides
or
{})
...
...
lms/lib/comment_client/comment.py
View file @
18956af0
...
...
@@ -12,6 +12,7 @@ class Comment(models.Model):
'endorsed'
,
'parent_id'
,
'thread_id'
,
'username'
,
'votes'
,
'user_id'
,
'closed'
,
'created_at'
,
'updated_at'
,
'depth'
,
'at_position_list'
,
'type'
,
'commentable_id'
,
'abuse_flaggers'
,
'endorsement'
,
'child_count'
,
]
updatable_fields
=
[
...
...
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