implemented test event data for thread/comment vote

This commit is contained in:
wajeeha-khalid
2016-02-11 21:24:04 +05:00
parent 3312eb2d22
commit 72aeb2c8da
2 changed files with 44 additions and 4 deletions

View File

@@ -9,7 +9,6 @@ from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.http import Http404
import itertools
from lms.djangoapps.django_comment_client.base.views import track_voted_event
from rest_framework.exceptions import PermissionDenied
@@ -26,7 +25,11 @@ from discussion_api.permissions import (
get_initializable_thread_fields,
)
from discussion_api.serializers import CommentSerializer, ThreadSerializer, get_context
from django_comment_client.base.views import track_comment_created_event, track_thread_created_event
from django_comment_client.base.views import (
track_comment_created_event,
track_thread_created_event,
track_voted_event,
)
from django_comment_common.signals import (
thread_created,
thread_edited,
@@ -511,6 +514,8 @@ def _do_extra_actions(api_content, cc_content, request_fields, actions_form, con
_handle_abuse_flagged_field(form_value, context["cc_requester"], cc_content)
elif field == "voted":
_handle_voted_field(form_value, cc_content, api_content, request, context)
else:
raise ValidationError({field: ["Invalid Key"]})
def _handle_following_field(form_value, user, cc_content):

View File

@@ -2107,7 +2107,8 @@ class UpdateThreadTest(
@ddt.data(*itertools.product([True, False], [True, False]))
@ddt.unpack
def test_voted(self, current_vote_status, new_vote_status):
@mock.patch("eventtracking.tracker.emit")
def test_voted(self, current_vote_status, new_vote_status, mock_emit):
"""
Test attempts to edit the "voted" field.
@@ -2144,6 +2145,22 @@ class UpdateThreadTest(
expected_request_data["value"] = ["up"]
self.assertEqual(actual_request_data, expected_request_data)
event_name, event_data = mock_emit.call_args[0]
self.assertEqual(event_name, "edx.forum.thread.voted")
self.assertEqual(
event_data,
{
'undo_vote': not new_vote_status,
'url': '',
'target_username': self.user.username,
'vote_value': 'up',
'user_forums_roles': [FORUM_ROLE_STUDENT],
'user_course_roles': [],
'commentable_id': 'original_topic',
'id': 'test_thread'
}
)
@ddt.data(*itertools.product([True, False], [True, False], [True, False]))
@ddt.unpack
def test_vote_count(self, current_vote_status, first_vote, second_vote):
@@ -2499,7 +2516,8 @@ class UpdateCommentTest(
@ddt.data(*itertools.product([True, False], [True, False]))
@ddt.unpack
def test_voted(self, current_vote_status, new_vote_status):
@mock.patch("eventtracking.tracker.emit")
def test_voted(self, current_vote_status, new_vote_status, mock_emit):
"""
Test attempts to edit the "voted" field.
@@ -2539,6 +2557,23 @@ class UpdateCommentTest(
expected_request_data["value"] = ["up"]
self.assertEqual(actual_request_data, expected_request_data)
event_name, event_data = mock_emit.call_args[0]
self.assertEqual(event_name, "edx.forum.response.voted")
self.assertEqual(
event_data,
{
'undo_vote': not new_vote_status,
'url': '',
'target_username': self.user.username,
'vote_value': 'up',
'user_forums_roles': [FORUM_ROLE_STUDENT],
'user_course_roles': [],
'commentable_id': 'dummy',
'id': 'test_comment'
}
)
@ddt.data(*itertools.product([True, False], [True, False], [True, False]))
@ddt.unpack
def test_vote_count(self, current_vote_status, first_vote, second_vote):