def _get_user_social_stats(user_id, slash_course_id, end_date):
    """
    Helper function which basically calls into the cs_comment_service. We wrap this,
    to make it easier to write mock functions for unit testing
    """

    stats = get_user_social_stats(user_id, slash_course_id, end_date=end_date)
    log.debug('raw stats = {}'.format(stats))
    # the comment service returns the user_id as a string
    user_id_str = str(user_id)
    if user_id_str in stats:
        return stats[user_id_str]
    else:
        return None
Example #2
0
def _get_user_social_stats(user_id, slash_course_id, end_date):
    """
    Helper function which basically calls into the cs_comment_service. We wrap this,
    to make it easier to write mock functions for unit testing
    """

    stats = get_user_social_stats(user_id, slash_course_id, end_date=end_date)
    log.info("raw stats = {}".format(stats))
    # the comment service returns the user_id as a string
    user_id_str = str(user_id)
    if user_id_str in stats:
        return stats[user_id_str]
    else:
        return None
Example #3
0
 def test_get_user_social_stats(
     self, user_id, course_id, end_date, thread_type, expected_url, expected_data, expected_result
 ):
     """ Tests get_user_social_stats utility function """
     expected_data["course_id"] = course_id
     with mock.patch(
         "lms.lib.comment_client.user._url_for_user_social_stats"
     ) as patched_url_for_social_stats, mock.patch(
         "lms.lib.comment_client.user.perform_request"
     ) as patched_perform_request:
         patched_perform_request.return_value = expected_result
         patched_url_for_social_stats.return_value = expected_url
         result = get_user_social_stats(user_id, course_id, end_date=end_date, thread_type=thread_type)
         patched_url_for_social_stats.assert_called_with(user_id)
         patched_perform_request.assert_called_with("get", expected_url, expected_data)
         self.assertEqual(result, expected_result)
Example #4
0
 def test_get_user_social_stats(self, user_id, course_id, end_date,
                                thread_type, expected_url, expected_data,
                                expected_result):
     """ Tests get_user_social_stats utility function """
     expected_data['course_id'] = course_id
     with mock.patch("lms.lib.comment_client.user._url_for_user_social_stats") as patched_url_for_social_stats, \
             mock.patch("lms.lib.comment_client.user.perform_request") as patched_perform_request:
         patched_perform_request.return_value = expected_result
         patched_url_for_social_stats.return_value = expected_url
         result = get_user_social_stats(user_id,
                                        course_id,
                                        end_date=end_date,
                                        thread_type=thread_type)
         patched_url_for_social_stats.assert_called_with(user_id)
         patched_perform_request.assert_called_with('get', expected_url,
                                                    expected_data)
         self.assertEqual(result, expected_result)
Example #5
0
 def test_get_user_social_stats_given_none_course_id_raises(self):
     with self.assertRaises(CommentClientRequestError):
         get_user_social_stats('irrelevant', None)
Example #6
0
 def test_get_user_social_stats_given_none_course_id_raises(self):
     with self.assertRaises(CommentClientRequestError):
         get_user_social_stats("irrelevant", None)