Commit 2731e59b by Chris Dodge Committed by Jonathan Piacenti

cdodge/update-opaque-key: update user social stats to use the legacy courseId…

cdodge/update-opaque-key: update user social stats to use the legacy courseId format since that is what the comment service expects

fix broken test, make social_stats more robust based on the caller
parent 5364f0c3
......@@ -39,7 +39,13 @@ class SecureClient(Client):
kwargs.update({'SERVER_PORT': 443, 'wsgi.url_scheme': 'https'})
super(SecureClient, self).__init__(*args, **kwargs)
def _fake_get_get_course_social_stats(course_id):
return {
'1': {'foo':'bar'},
'2': {'one': 'two'}
}
@mock.patch("lms.lib.comment_client.user.get_course_social_stats", _fake_get_get_course_social_stats)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
@override_settings(EDX_API_KEY=TEST_API_KEY)
class CoursesApiTests(TestCase):
......@@ -1509,13 +1515,6 @@ class CoursesApiTests(TestCase):
response = self.do_get(completion_uri)
self.assertEqual(response.status_code, 404)
def _fake_get_get_course_social_stats(course_id):
return {
'1': {'foo':'bar'},
'2': {'one': 'two'}
}
@mock.patch("lms.lib.comment_client.user.get_course_social_stats", _fake_get_get_course_social_stats)
def test_social_metrics(self):
test_uri = '{}/{}/metrics/social/'.format(self.base_courses_uri, self.test_course_id)
response = self.do_get(test_uri)
......
......@@ -1669,10 +1669,17 @@ class CoursesSocialMetrics(SecureListAPIView):
def get(self, request, course_id): # pylint: disable=W0613
try:
course_key = CourseKey.from_string(course_id)
# be robust to the try of course_id we get from caller
try:
# assume new style
course_key = CourseKey.from_string(course_id)
slash_course_id = course_key.to_deprecated_string()
except:
# assume course_id passed in is legacy format
slash_course_id = course_id
# the forum service expects the legacy slash separated string format
data = get_course_social_stats(course_key.to_deprecated_string())
data = get_course_social_stats(slash_course_id)
# remove any excluded users from the aggregate
......
......@@ -42,6 +42,8 @@ from api_manager.utils import generate_base_uri
from projects.serializers import BasicWorkgroupSerializer
from .serializers import UserSerializer, UserCountByCitySerializer, UserRolesSerializer
from opaque_keys.edx.keys import CourseKey
log = logging.getLogger(__name__)
AUDIT_LOG = logging.getLogger("audit")
......@@ -1071,7 +1073,17 @@ class UsersSocialMetrics(SecureListAPIView):
return Response({}, status.HTTP_404_NOT_FOUND)
comment_user = CommentUser.from_django_user(user)
comment_user.course_id = course_id
# be robust to the try of course_id we get from caller
try:
# assume new style
course_key = CourseKey.from_string(course_id)
slash_course_id = course_key.to_deprecated_string()
except:
# assume course_id passed in is legacy format
slash_course_id = course_id
comment_user.course_id = slash_course_id
try:
data = (comment_user.social_stats())[user_id]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment