'Test attempts to edit the "voted" field.
current_vote_status indicates whether the comment should be upvoted at
the start of the test. new_vote_status indicates the value for the
"voted" field in the update. If current_vote_status and new_vote_status
are the same, no update should be made. Otherwise, a vote should be PUT
or DELETEd according to the new_vote_status value.'

@ddt.data(*itertools.product([True, False], [True, False]))
@ddt.unpack
@mock.patch('eventtracking.tracker.emit')
def test_voted(self, current_vote_status, new_vote_status, mock_emit):

    vote_count = 0
    if current_vote_status:
        self.register_get_user_response(self.user, upvoted_ids=['test_comment'])
        vote_count = 1
    self.register_comment_votes_response('test_comment')
    self.register_comment(overrides={'votes': {'up_count': vote_count}})
    data = {'voted': new_vote_status}
    result = update_comment(self.request, 'test_comment', data)
    self.assertEqual(result['vote_count'], (1 if new_vote_status else 0))
    self.assertEqual(result['voted'], new_vote_status)
    last_request_path = urlparse(httpretty.last_request().path).path
    votes_url = '/api/v1/comments/test_comment/votes'
    if (current_vote_status == new_vote_status):
        self.assertNotEqual(last_request_path, votes_url)
    else:
        self.assertEqual(last_request_path, votes_url)
        self.assertEqual(httpretty.last_request().method, ('PUT' if new_vote_status else 'DELETE'))
        actual_request_data = (httpretty.last_request().parsed_body if new_vote_status else parse_qs(urlparse(httpretty.last_request().path).query))
        actual_request_data.pop('request_id', None)
        expected_request_data = {'user_id': [str(self.user.id)]}
        if 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'})
