Commit 1f0c1047 by David Adams

Merge pull request #3871 from edx/dcadams/fix_metrics_tab_after_opaque_keys

Fixes some stuff for metrics tab
parents 721732bf 9818cc7c
...@@ -558,7 +558,7 @@ def post_metrics_data_csv(request): ...@@ -558,7 +558,7 @@ def post_metrics_data_csv(request):
header = [_("Section").encode('utf-8'), _("Subsection").encode('utf-8'), _("Opened by this number of students").encode('utf-8')] header = [_("Section").encode('utf-8'), _("Subsection").encode('utf-8'), _("Opened by this number of students").encode('utf-8')]
filename = sanitize_filename(_('subsections') + '_' + course_id) filename = sanitize_filename(_('subsections') + '_' + course_id)
elif data_type == 'problem': elif data_type == 'problem':
header = [_("Section").encode('utf-8'), _("Problem").encode('utf-8'), _("Name").encode('utf-8'), _("Count of Students").encode('utf-8'), _("% of Students").encode('utf-8'), _("Score").encode('utf-8')] header = [_("Section").encode('utf-8'), _("Problem").encode('utf-8'), _("Name").encode('utf-8'), _("Count of Students").encode('utf-8'), _("Percent of Students").encode('utf-8'), _("Score").encode('utf-8')]
filename = sanitize_filename(_('problems') + '_' + course_id) filename = sanitize_filename(_('problems') + '_' + course_id)
for index, section in enumerate(sections): for index, section in enumerate(sections):
......
...@@ -2,15 +2,21 @@ ...@@ -2,15 +2,21 @@
Tests for class dashboard (Metrics tab in instructor dashboard) Tests for class dashboard (Metrics tab in instructor dashboard)
""" """
from mock import patch from mock import patch
from django.test.utils import override_settings
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import AdminFactory
from django.utils import simplejson from django.utils import simplejson
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from class_dashboard import views from class_dashboard import views
class TestViews(TestCase): @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class TestViews(ModuleStoreTestCase):
""" """
Tests related to class_dashboard/views.py Tests related to class_dashboard/views.py
""" """
...@@ -81,3 +87,18 @@ class TestViews(TestCase): ...@@ -81,3 +87,18 @@ class TestViews(TestCase):
response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1') response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1')
self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content) self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content)
def test_sending_deprecated_id(self):
course = CourseFactory.create()
instructor = AdminFactory.create()
self.request.user = instructor
response = views.all_sequential_open_distrib(self.request, course.id.to_deprecated_string())
self.assertEqual('[]', response.content)
response = views.all_problem_grade_distribution(self.request, course.id.to_deprecated_string())
self.assertEqual('[]', response.content)
response = views.section_problem_grade_distrib(self.request, course.id.to_deprecated_string(), 'no section')
self.assertEqual('{"error": "error"}', response.content)
...@@ -10,6 +10,7 @@ from django.http import HttpResponse ...@@ -10,6 +10,7 @@ from django.http import HttpResponse
from courseware.courses import get_course_with_access from courseware.courses import get_course_with_access
from courseware.access import has_access from courseware.access import has_access
from class_dashboard import dashboard_data from class_dashboard import dashboard_data
from xmodule.modulestore.locations import SlashSeparatedCourseKey
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -37,9 +38,10 @@ def all_sequential_open_distrib(request, course_id): ...@@ -37,9 +38,10 @@ def all_sequential_open_distrib(request, course_id):
json = {} json = {}
# Only instructor for this particular course can request this information # Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id): course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
if has_instructor_access_for_class(request.user, course_key):
try: try:
json = dashboard_data.get_d3_sequential_open_distrib(course_id) json = dashboard_data.get_d3_sequential_open_distrib(course_key)
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
log.error('Generating metrics failed with exception: %s', ex) log.error('Generating metrics failed with exception: %s', ex)
json = {'error': "error"} json = {'error': "error"}
...@@ -62,9 +64,10 @@ def all_problem_grade_distribution(request, course_id): ...@@ -62,9 +64,10 @@ def all_problem_grade_distribution(request, course_id):
json = {} json = {}
# Only instructor for this particular course can request this information # Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id): course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
if has_instructor_access_for_class(request.user, course_key):
try: try:
json = dashboard_data.get_d3_problem_grade_distrib(course_id) json = dashboard_data.get_d3_problem_grade_distrib(course_key)
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
log.error('Generating metrics failed with exception: %s', ex) log.error('Generating metrics failed with exception: %s', ex)
json = {'error': "error"} json = {'error': "error"}
...@@ -92,9 +95,10 @@ def section_problem_grade_distrib(request, course_id, section): ...@@ -92,9 +95,10 @@ def section_problem_grade_distrib(request, course_id, section):
json = {} json = {}
# Only instructor for this particular course can request this information # Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id): course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
if has_instructor_access_for_class(request.user, course_key):
try: try:
json = dashboard_data.get_d3_section_grade_distrib(course_id, section) json = dashboard_data.get_d3_section_grade_distrib(course_key, section)
except Exception as ex: # pylint: disable=broad-except except Exception as ex: # pylint: disable=broad-except
log.error('Generating metrics failed with exception: %s', ex) log.error('Generating metrics failed with exception: %s', ex)
json = {'error': "error"} json = {'error': "error"}
......
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