diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 4dfbaac28b..3eab8bdc42 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -26,7 +26,7 @@ from django.urls import reverse, reverse_lazy from freezegun import freeze_time from markupsafe import escape from milestones.tests.utils import MilestonesTestCaseMixin -from mock import MagicMock, PropertyMock, create_autospec, patch +from mock import MagicMock, PropertyMock, call, create_autospec, patch from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from pytz import UTC from six import text_type @@ -3162,12 +3162,16 @@ class DatesTabTestCase(ModuleStoreTestCase): deadline=now + timedelta(days=2) ) + self.user = UserFactory() + self.client.login(username=self.user.username, password=TEST_PASSWORD) + def _get_response(self, course): """ Returns the HTML for the progress page """ return self.client.get(reverse('dates', args=[six.text_type(course.id)])) @RELATIVE_DATES_FLAG.override(active=True) - def test_defaults(self): + @patch('edx_django_utils.monitoring.set_custom_metric') + def test_defaults(self, mock_set_custom_metric): enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user, mode=CourseMode.VERIFIED) now = datetime.now(utc) with self.store.bulk_operations(self.course.id): @@ -3210,7 +3214,15 @@ class DatesTabTestCase(ModuleStoreTestCase): 'mode': enrollment.mode } + expected_calls = [ + call('course_id', text_type(self.course.id)), + call('user_id', self.user.id), + call('is_staff', self.user.is_staff), + ] + response = self._get_response(self.course) + + mock_set_custom_metric.assert_has_calls(expected_calls, any_order=True) self.assertContains(response, subsection.display_name) # Show the Verification Deadline for everyone self.assertContains(response, 'Verification Deadline') diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 03961b27e1..0fcbba66c0 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -35,6 +35,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_GET, require_http_methods, require_POST from django.views.generic import View +from edx_django_utils import monitoring as monitoring_utils from edx_django_utils.monitoring import set_custom_metrics_for_course_key from edxnotes.helpers import is_feature_enabled from ipware.ip import get_ip @@ -1060,8 +1061,13 @@ def dates(request, course_id): Display the course's dates.html, or 404 if there is no such course. Assumes the course_id is in a valid format. """ - course_key = CourseKey.from_string(course_id) + + # Enable NR tracing for this view based on course + monitoring_utils.set_custom_metric('course_id', text_type(course_key)) + monitoring_utils.set_custom_metric('user_id', request.user.id) + monitoring_utils.set_custom_metric('is_staff', request.user.is_staff) + course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=False) course_date_blocks = get_course_date_blocks(course, request.user, request, include_access=True, include_past_dates=True)