fix: legacy coverage and add missing properties for reported events

This commit is contained in:
SaadYousaf
2022-11-14 13:49:16 +05:00
committed by Saad Yousaf
parent 1638535665
commit c0631c320e
3 changed files with 27 additions and 5 deletions

View File

@@ -138,7 +138,8 @@ class ThreadActionGroupIdTestCase(
"group_id": self.student_cohort.id,
"closed": False,
"type": "thread",
"commentable_id": "non_team_dummy_id"
"commentable_id": "non_team_dummy_id",
"body": "test body"
}
)
request = RequestFactory().post("dummy_url", post_params or {})
@@ -1663,7 +1664,7 @@ class TeamsPermissionsTestCase(ForumsEnableMixin, UrlResetMixin, SharedModuleSto
commentable_id = getattr(self, commentable_id)
self._setup_mock(
user, mock_request,
{"closed": False, "commentable_id": commentable_id, "thread_id": "dummy_thread"},
{"closed": False, "commentable_id": commentable_id, "thread_id": "dummy_thread", "body": 'dummy body'},
)
for action in ["upvote_comment", "downvote_comment", "un_flag_abuse_for_comment", "flag_abuse_for_comment"]:
response = self.client.post(
@@ -1684,7 +1685,7 @@ class TeamsPermissionsTestCase(ForumsEnableMixin, UrlResetMixin, SharedModuleSto
commentable_id = getattr(self, commentable_id)
self._setup_mock(
user, mock_request,
{"closed": False, "commentable_id": commentable_id},
{"closed": False, "commentable_id": commentable_id, "body": "dummy body"},
)
for action in ["upvote_thread", "downvote_thread", "un_flag_abuse_for_thread", "flag_abuse_for_thread",
"follow_thread", "unfollow_thread"]:

View File

@@ -270,8 +270,11 @@ def track_thread_reported_event(request, course, thread):
event_name = _EVENT_NAME_TEMPLATE.format(obj_type='thread', action_name='reported')
event_data = {
'body': thread.body[:TRACKING_MAX_FORUM_BODY],
'truncated': len(thread.body) > TRACKING_MAX_FORUM_BODY,
'content_type': 'Post',
'commentable_id': thread.get('commentable_id', ''),
'thread_type': thread.get('thread_type', ''),
'group_id': thread.get('group_id', ''),
}
if hasattr(thread, 'username'):
event_data['target_username'] = thread.get('username', '')
@@ -287,6 +290,7 @@ def track_comment_reported_event(request, course, comment):
event_name = _EVENT_NAME_TEMPLATE.format(obj_type=obj_type, action_name='reported')
event_data = {
'body': comment.body[:TRACKING_MAX_FORUM_BODY],
'truncated': len(comment.body) > TRACKING_MAX_FORUM_BODY,
'commentable_id': comment.get('commentable_id', ''),
'content_type': obj_type.capitalize(),
}
@@ -302,9 +306,13 @@ def track_thread_unreported_event(request, course, thread):
event_name = _EVENT_NAME_TEMPLATE.format(obj_type='thread', action_name='unreported')
event_data = {
'body': thread.body[:TRACKING_MAX_FORUM_BODY],
'truncated': len(thread.body) > TRACKING_MAX_FORUM_BODY,
'content_type': 'Post',
'commentable_id': thread.get('commentable_id', ''),
'reported_status_cleared': not bool(thread.get('abuse_flaggers', [])),
'thread_type': thread.get('thread_type', ''),
'group_id': thread.get('group_id', ''),
}
if hasattr(thread, 'username'):
event_data['target_username'] = thread.get('username', '')
@@ -320,6 +328,7 @@ def track_comment_unreported_event(request, course, comment):
event_name = _EVENT_NAME_TEMPLATE.format(obj_type=obj_type, action_name='unreported')
event_data = {
'body': comment.body[:TRACKING_MAX_FORUM_BODY],
'truncated': len(comment.body) > TRACKING_MAX_FORUM_BODY,
'commentable_id': comment.get('commentable_id', ''),
'content_type': obj_type.capitalize(),
'reported_status_cleared': not bool(comment.get('abuse_flaggers', [])),
@@ -767,9 +776,10 @@ def flag_abuse_for_thread(request, course_id, thread_id):
"""
course_key = CourseKey.from_string(course_id)
user = cc.User.from_django_user(request.user)
course = get_course_by_id(course_key)
thread = cc.Thread.find(thread_id)
thread.flagAbuse(user, thread)
track_discussion_reported_event(request, course, thread)
return JsonResponse(prepare_content(thread.to_dict(), course_key))
@@ -790,7 +800,7 @@ def un_flag_abuse_for_thread(request, course_id, thread_id):
has_access(request.user, 'staff', course)
)
thread.unFlagAbuse(user, thread, remove_all)
track_discussion_unreported_event(request, course, thread)
return JsonResponse(prepare_content(thread.to_dict(), course_key))
@@ -804,8 +814,10 @@ def flag_abuse_for_comment(request, course_id, comment_id):
"""
course_key = CourseKey.from_string(course_id)
user = cc.User.from_django_user(request.user)
course = get_course_by_id(course_key)
comment = cc.Comment.find(comment_id)
comment.flagAbuse(user, comment)
track_discussion_unreported_event(request, course, comment)
return JsonResponse(prepare_content(comment.to_dict(), course_key))
@@ -826,6 +838,7 @@ def un_flag_abuse_for_comment(request, course_id, comment_id):
)
comment = cc.Comment.find(comment_id)
comment.unFlagAbuse(user, comment, remove_all)
track_discussion_unreported_event(request, course, comment)
return JsonResponse(prepare_content(comment.to_dict(), course_key))

View File

@@ -2871,6 +2871,9 @@ class UpdateThreadTest(
'target_username': self.user.username,
'title_truncated': False,
'title': 'Original Title',
'thread_type': 'discussion',
'group_id': None,
'truncated': False,
}
if not new_flagged:
expected_event_data['reported_status_cleared'] = False
@@ -2919,6 +2922,9 @@ class UpdateThreadTest(
'title_truncated': False,
'title': 'Original Title',
'reported_status_cleared': False,
'thread_type': 'discussion',
'group_id': None,
'truncated': False,
}
actual_event_name, actual_event_data = mock_emit.call_args[0]
@@ -3433,6 +3439,7 @@ class UpdateCommentTest(
'content_type': 'Response',
'commentable_id': 'dummy',
'url': '',
'truncated': False,
'user_course_roles': [],
'user_forums_roles': [FORUM_ROLE_STUDENT],
'target_username': self.user.username,
@@ -3477,6 +3484,7 @@ class UpdateCommentTest(
'id': 'test_comment',
'content_type': 'Response',
'commentable_id': 'dummy',
'truncated': False,
'url': '',
'user_course_roles': [],
'user_forums_roles': [FORUM_ROLE_STUDENT, FORUM_ROLE_ADMINISTRATOR],