|
10 | 10 | import ddt |
11 | 11 | from completion.models import BlockCompletion |
12 | 12 | from django.conf import settings |
| 13 | +from django.contrib.auth.models import AnonymousUser |
13 | 14 | from django.test import override_settings |
14 | 15 | from django.urls import reverse |
15 | 16 | from edx_toggles.toggles.testutils import override_waffle_flag |
|
20 | 21 | from common.djangoapps.student.models import CourseEnrollment |
21 | 22 | from common.djangoapps.student.roles import CourseInstructorRole |
22 | 23 | from common.djangoapps.student.tests.factories import UserFactory |
| 24 | +from lms.djangoapps.course_home_api.outline.views import CourseNavigationBlocksView |
23 | 25 | from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests |
24 | 26 | from lms.djangoapps.course_home_api.toggles import COURSE_HOME_SEND_COURSE_PROGRESS_ANALYTICS_FOR_STUDENT |
25 | 27 | from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory |
@@ -584,6 +586,20 @@ def test_get_unauthenticated_user(self): |
584 | 586 | assert response.status_code == 200 |
585 | 587 | assert response.data.get('blocks') is None |
586 | 588 |
|
| 589 | + def test_anonymous_user_completion_dict_does_not_lookup_completions(self): |
| 590 | + """ |
| 591 | + Test that anonymous users do not query completion data. |
| 592 | + """ |
| 593 | + view = CourseNavigationBlocksView() |
| 594 | + view.request = Mock(user=AnonymousUser()) |
| 595 | + view.kwargs = {'course_key_string': str(self.course.id)} |
| 596 | + |
| 597 | + with patch('lms.djangoapps.course_home_api.outline.views.BlockCompletion.objects.filter') as mock_filter: |
| 598 | + completions = view.completions_dict |
| 599 | + |
| 600 | + assert completions == {} |
| 601 | + mock_filter.assert_not_called() |
| 602 | + |
587 | 603 | def test_course_staff_can_see_non_user_specific_content_in_masquerade(self): |
588 | 604 | """ |
589 | 605 | Test that course staff can see the outline and other non-user-specific content when masquerading as a learner |
|
0 commit comments