Skip to content

Commit

Permalink
Merge pull request #160 from edx-solutions/cdodge/update-opaque-key
Browse files Browse the repository at this point in the history
cdodge/update-opaque-key: update user social stats to use the legacy cou...
  • Loading branch information
chrisndodge committed Aug 7, 2014
2 parents 00a3bfc + 463d6bc commit eef320a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 6 additions & 7 deletions lms/djangoapps/api_manager/courses/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def __init__(self, *args, **kwargs):
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):
Expand Down Expand Up @@ -1509,13 +1515,6 @@ def test_coursemodulecompletions_get_invalid_course(self):
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)
Expand Down
11 changes: 9 additions & 2 deletions lms/djangoapps/api_manager/courses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion lms/djangoapps/api_manager/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
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")

Expand Down Expand Up @@ -1073,7 +1075,17 @@ def get(self, request, user_id, course_id): # pylint: disable=W0613,W0221
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]
Expand Down

0 comments on commit eef320a

Please sign in to comment.