Skip to content

Commit 2168125

Browse files
committed
refactor: update role assignment scope initialization to use ScopeData
1 parent e29c6b8 commit 2168125

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

common/djangoapps/student/tests/test_roles.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
OrgCourseOverviewGlobData,
1717
RoleAssignmentData,
1818
RoleData,
19+
ScopeData,
1920
UserData,
2021
)
2122
from openedx_authz.constants.roles import COURSE_ADMIN, COURSE_STAFF
@@ -310,11 +311,12 @@ def test_get_authz_compat_course_access_roles_for_user_org_scope(self):
310311
"""
311312
Org-wide AuthZ assignments should map to legacy org-level course access roles.
312313
"""
313-
org_scope = OrgCourseOverviewGlobData.build_external_key("OpenedX")
314314
assignment = RoleAssignmentData(
315315
subject=UserData(external_key=self.student.username),
316316
roles=[RoleData(external_key=COURSE_ADMIN.external_key)],
317-
scope=org_scope,
317+
scope=ScopeData(
318+
external_key=OrgCourseOverviewGlobData.build_external_key("OpenedX"),
319+
),
318320
)
319321
with patch("openedx_authz.api.users.get_user_role_assignments", return_value=[assignment]):
320322
result = get_authz_compat_course_access_roles_for_user(self.student)
@@ -338,21 +340,22 @@ def test_org_scope_authz_role_grants_instructor_dashboard_permissions(self):
338340
"""
339341
# pylint: disable=protected-access
340342
course_key = CourseKey.from_string("course-v1:OpenedX+DemoX+DemoCourse")
341-
org_scope = OrgCourseOverviewGlobData.build_external_key("OpenedX")
342343
assignment = RoleAssignmentData(
343344
subject=UserData(external_key=self.student.username),
344345
roles=[RoleData(external_key=COURSE_ADMIN.external_key)],
345-
scope=org_scope,
346+
scope=ScopeData(
347+
external_key=OrgCourseOverviewGlobData.build_external_key("OpenedX"),
348+
),
346349
)
347350
with patch("openedx_authz.api.users.get_user_role_assignments", return_value=[assignment]):
348351
if hasattr(self.student, "_roles"):
349352
del self.student._roles
350353
self.student._roles = RoleCache(self.student)
351354

352355
self.assertTrue(self.student._roles.has_role("instructor", None, "OpenedX")) # noqa: PT009
353-
self.assertTrue(OrgInstructorRole("OpenedX").has_user(self.student)) # noqa: PT009
354-
self.assertTrue(self.student.has_perm(instructor_permissions.VIEW_DASHBOARD, course_key)) # noqa: PT009
355-
self.assertTrue(self.student.has_perm(instructor_permissions.SHOW_TASKS, course_key)) # noqa: PT009
356+
self.assertTrue(OrgInstructorRole("OpenedX").has_user(self.student)) # noqa: PT009
357+
self.assertTrue(self.student.has_perm(instructor_permissions.VIEW_DASHBOARD, course_key)) # noqa: PT009
358+
self.assertTrue(self.student.has_perm(instructor_permissions.SHOW_TASKS, course_key)) # noqa: PT009
356359

357360

358361
@ddt.ddt

0 commit comments

Comments
 (0)