Skip to content

Commit 95a51b7

Browse files
committed
test: enhance authorization tests for about page access and visibility
1 parent f42c069 commit 95a51b7

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

lms/djangoapps/courseware/tests/test_about.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import ddt
1111
import pytz
12+
from crum import set_current_request
1213
from django.conf import settings
1314
from django.test.utils import override_settings
1415
from django.urls import reverse
@@ -224,7 +225,12 @@ def test_about_page_public_view(self, course_visibility):
224225
self.assertContains(resp, "Enroll Now")
225226

226227

227-
class AuthzAboutPageTestCase(CourseAuthoringAuthzTestMixin, LoginEnrollmentTestCase, SharedModuleStoreTestCase):
228+
class AuthzAboutPageTestCase(
229+
CourseAuthoringAuthzTestMixin,
230+
LoginEnrollmentTestCase,
231+
SharedModuleStoreTestCase,
232+
EventTrackingTestCase,
233+
):
228234
"""
229235
About page HTTP access when AuthZ course authoring is enabled.
230236
"""
@@ -237,11 +243,16 @@ def setUpClass(cls):
237243
CourseDetails.update_about_item(cls.course_without_about, "overview", "WITHOUT ABOUT", None)
238244
CourseDetails.update_about_item(cls.course_with_about, "overview", "WITH ABOUT", None)
239245

246+
def setUp(self):
247+
super().setUp()
248+
self.addCleanup(set_current_request, None)
249+
self.assertTrue( # noqa: PT009
250+
self.client.login(username=self.unauthorized_user.username, password=self.password)
251+
)
252+
240253
@override_settings(COURSE_ABOUT_VISIBILITY_PERMISSION="see_about_page")
241254
def test_about_page_honors_catalog_visibility_without_authz_role(self):
242255
"""A learner without AuthZ roles can view catalog-visible about pages."""
243-
self.client.force_login(self.unauthorized_user)
244-
245256
url = reverse("about_course", args=[str(self.course_with_about.id)])
246257
resp = self.client.get(url)
247258
self.assertContains(resp, "WITH ABOUT")

lms/djangoapps/courseware/tests/test_access.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import lms.djangoapps.courseware.access as access
2828
import lms.djangoapps.courseware.access_response as access_response
29-
from common.djangoapps.student.auth import add_users
3029
from common.djangoapps.student.models import CourseEnrollment
3130
from common.djangoapps.student.roles import CourseCcxCoachRole, CourseLimitedStaffRole, CourseStaffRole
3231
from common.djangoapps.student.tests.factories import (
@@ -1087,9 +1086,8 @@ def test_course_staff_bypass_when_catalog_hidden(self):
10871086

10881087
def test_limited_staff_bypass_when_catalog_hidden(self):
10891088
"""Limited staff inherit staff bypass for about-page access."""
1090-
course_staff = StaffFactory.create(course_key=self.course_hidden.id)
10911089
limited_staff = UserFactory.create()
1092-
add_users(course_staff, CourseLimitedStaffRole(self.course_hidden.id), limited_staff)
1090+
CourseLimitedStaffRole(self.course_hidden.id).add_users(limited_staff)
10931091

10941092
response = self._see_about_page_response(limited_staff, self.course_hidden)
10951093

0 commit comments

Comments
 (0)