Skip to content

Commit

Permalink
implemented test event data for thread/comment vote
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeeha-khalid committed Feb 11, 2016
1 parent 3312eb2 commit 72aeb2c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lms/djangoapps/discussion_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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

Expand All @@ -26,7 +25,11 @@
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,
Expand Down Expand Up @@ -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"]})

This comment has been minimized.

Copy link
@jcdyer

jcdyer Feb 11, 2016

Contributor

This is a better error. Good choice.



def _handle_following_field(form_value, user, cc_content):
Expand Down
39 changes: 37 additions & 2 deletions lms/djangoapps/discussion_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,8 @@ def test_following(self, old_following, new_following):

@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.
Expand Down Expand Up @@ -2144,6 +2145,22 @@ def test_voted(self, current_vote_status, new_vote_status):
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):
Expand Down Expand Up @@ -2499,7 +2516,8 @@ def test_endorsed_access(self, role_name, is_thread_author, thread_type, is_comm

@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.
Expand Down Expand Up @@ -2539,6 +2557,23 @@ def test_voted(self, current_vote_status, new_vote_status):
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):
Expand Down

0 comments on commit 72aeb2c

Please sign in to comment.