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
c5afa44e
Commit
c5afa44e
authored
Oct 21, 2015
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
used recursive to optionally get response comments from comment service
parent
fa285e09
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
7 deletions
+18
-7
lms/djangoapps/discussion_api/api.py
+11
-4
lms/djangoapps/discussion_api/tests/test_api.py
+3
-1
lms/djangoapps/discussion_api/tests/test_views.py
+4
-2
No files found.
lms/djangoapps/discussion_api/api.py
View file @
c5afa44e
...
@@ -8,6 +8,7 @@ from urlparse import urlunparse
...
@@ -8,6 +8,7 @@ from urlparse import urlunparse
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.http
import
Http404
from
django.http
import
Http404
import
itertools
from
rest_framework.exceptions
import
PermissionDenied
from
rest_framework.exceptions
import
PermissionDenied
...
@@ -378,7 +379,7 @@ def get_comment_list(request, thread_id, endorsed, page, page_size, mark_as_read
...
@@ -378,7 +379,7 @@ def get_comment_list(request, thread_id, endorsed, page, page_size, mark_as_read
request
,
request
,
thread_id
,
thread_id
,
retrieve_kwargs
=
{
retrieve_kwargs
=
{
"recursive"
:
Tru
e
,
"recursive"
:
Fals
e
,
"user_id"
:
request
.
user
.
id
,
"user_id"
:
request
.
user
.
id
,
"mark_as_read"
:
mark_as_read
,
"mark_as_read"
:
mark_as_read
,
"response_skip"
:
response_skip
,
"response_skip"
:
response_skip
,
...
@@ -415,7 +416,7 @@ def get_comment_list(request, thread_id, endorsed, page, page_size, mark_as_read
...
@@ -415,7 +416,7 @@ def get_comment_list(request, thread_id, endorsed, page, page_size, mark_as_read
raise
Http404
raise
Http404
num_pages
=
(
resp_total
+
page_size
-
1
)
/
page_size
if
resp_total
else
1
num_pages
=
(
resp_total
+
page_size
-
1
)
/
page_size
if
resp_total
else
1
results
=
[
CommentSerializer
(
response
,
remove_fields
=
[
"children"
],
context
=
context
)
.
data
for
response
in
responses
]
results
=
[
CommentSerializer
(
response
,
context
=
context
)
.
data
for
response
in
responses
]
return
get_paginated_data
(
request
,
results
,
page
,
num_pages
)
return
get_paginated_data
(
request
,
results
,
page
,
num_pages
)
...
@@ -740,9 +741,15 @@ def get_response_comments(request, comment_id, page, page_size):
...
@@ -740,9 +741,15 @@ def get_response_comments(request, comment_id, page, page_size):
"""
"""
try
:
try
:
cc_comment
=
Comment
(
id
=
comment_id
)
.
retrieve
()
cc_comment
=
Comment
(
id
=
comment_id
)
.
retrieve
()
cc_thread
,
context
=
_get_thread_and_context
(
request
,
cc_comment
[
"thread_id"
])
cc_thread
,
context
=
_get_thread_and_context
(
request
,
cc_comment
[
"thread_id"
],
retrieve_kwargs
=
{
"recursive"
:
True
,
}
)
if
cc_thread
[
"thread_type"
]
==
"question"
:
if
cc_thread
[
"thread_type"
]
==
"question"
:
thread_responses
=
cc_thread
[
"endorsed_responses"
]
+
cc_thread
[
"non_endorsed_responses"
]
thread_responses
=
itertools
.
chain
(
cc_thread
[
"endorsed_responses"
],
cc_thread
[
"non_endorsed_responses"
])
else
:
else
:
thread_responses
=
cc_thread
[
"children"
]
thread_responses
=
cc_thread
[
"children"
]
response_comments
=
[]
response_comments
=
[]
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
c5afa44e
...
@@ -1085,7 +1085,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
...
@@ -1085,7 +1085,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
self
.
assert_query_params_equal
(
self
.
assert_query_params_equal
(
httpretty
.
httpretty
.
latest_requests
[
-
2
],
httpretty
.
httpretty
.
latest_requests
[
-
2
],
{
{
"recursive"
:
[
"
Tru
e"
],
"recursive"
:
[
"
Fals
e"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"mark_as_read"
:
[
"False"
],
"mark_as_read"
:
[
"False"
],
"resp_skip"
:
[
"70"
],
"resp_skip"
:
[
"70"
],
...
@@ -1147,6 +1147,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
...
@@ -1147,6 +1147,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"voted"
:
False
,
"voted"
:
False
,
"vote_count"
:
4
,
"vote_count"
:
4
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"children"
:
[],
},
},
{
{
"id"
:
"test_comment_2"
,
"id"
:
"test_comment_2"
,
...
@@ -1166,6 +1167,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
...
@@ -1166,6 +1167,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"voted"
:
False
,
"voted"
:
False
,
"vote_count"
:
7
,
"vote_count"
:
7
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"children"
:
[],
},
},
]
]
actual_comments
=
self
.
get_comment_list
(
actual_comments
=
self
.
get_comment_list
(
...
...
lms/djangoapps/discussion_api/tests/test_views.py
View file @
c5afa44e
...
@@ -681,6 +681,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
...
@@ -681,6 +681,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"voted"
:
True
,
"voted"
:
True
,
"vote_count"
:
4
,
"vote_count"
:
4
,
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"editable_fields"
:
[
"abuse_flagged"
,
"voted"
],
"children"
:
[],
}]
}]
self
.
register_get_thread_response
({
self
.
register_get_thread_response
({
"id"
:
self
.
thread_id
,
"id"
:
self
.
thread_id
,
...
@@ -704,7 +705,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
...
@@ -704,7 +705,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
self
.
assert_query_params_equal
(
self
.
assert_query_params_equal
(
httpretty
.
httpretty
.
latest_requests
[
-
2
],
httpretty
.
httpretty
.
latest_requests
[
-
2
],
{
{
"recursive"
:
[
"
Tru
e"
],
"recursive"
:
[
"
Fals
e"
],
"resp_skip"
:
[
"0"
],
"resp_skip"
:
[
"0"
],
"resp_limit"
:
[
"10"
],
"resp_limit"
:
[
"10"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"user_id"
:
[
str
(
self
.
user
.
id
)],
...
@@ -738,7 +739,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
...
@@ -738,7 +739,7 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
self
.
assert_query_params_equal
(
self
.
assert_query_params_equal
(
httpretty
.
httpretty
.
latest_requests
[
-
2
],
httpretty
.
httpretty
.
latest_requests
[
-
2
],
{
{
"recursive"
:
[
"
Tru
e"
],
"recursive"
:
[
"
Fals
e"
],
"resp_skip"
:
[
"68"
],
"resp_skip"
:
[
"68"
],
"resp_limit"
:
[
"4"
],
"resp_limit"
:
[
"4"
],
"user_id"
:
[
str
(
self
.
user
.
id
)],
"user_id"
:
[
str
(
self
.
user
.
id
)],
...
@@ -1026,6 +1027,7 @@ class ThreadViewSetRetrieveTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase)
...
@@ -1026,6 +1027,7 @@ class ThreadViewSetRetrieveTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase)
@httpretty.activate
@httpretty.activate
@mock.patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
class
CommentViewSetRetrieveTest
(
DiscussionAPIViewTestMixin
,
ModuleStoreTestCase
):
class
CommentViewSetRetrieveTest
(
DiscussionAPIViewTestMixin
,
ModuleStoreTestCase
):
"""Tests for CommentViewSet Retrieve"""
"""Tests for CommentViewSet Retrieve"""
def
setUp
(
self
):
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