Commit c5afa44e by wajeeha-khalid

used recursive to optionally get response comments from comment service

parent fa285e09
...@@ -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": True, "recursive": False,
"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 = []
......
...@@ -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": ["True"], "recursive": ["False"],
"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(
......
...@@ -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": ["True"], "recursive": ["False"],
"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": ["True"], "recursive": ["False"],
"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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment