|
2 | 2 | Tests of student.roles |
3 | 3 | """ |
4 | 4 |
|
5 | | - |
6 | 5 | from unittest.mock import patch |
7 | 6 |
|
8 | 7 | import ddt |
|
11 | 10 | from edx_toggles.toggles.testutils import override_waffle_flag |
12 | 11 | from opaque_keys.edx.keys import CourseKey |
13 | 12 | from opaque_keys.edx.locator import LibraryLocator |
14 | | -from openedx_authz.api.data import ContentLibraryData, RoleAssignmentData, RoleData, UserData |
| 13 | +from openedx_authz.api.data import ContentLibraryData, CourseOverviewData, RoleAssignmentData, RoleData, UserData |
| 14 | +from openedx_authz.constants.roles import COURSE_ADMIN, COURSE_STAFF |
15 | 15 | from openedx_authz.engine.enforcer import AuthzEnforcer |
16 | 16 |
|
17 | 17 | from common.djangoapps.student.admin import CourseAccessRoleHistoryAdmin |
@@ -239,9 +239,51 @@ def test_get_orgs_for_user(self): |
239 | 239 | role_second_org.add_users(self.student) |
240 | 240 | assert len(role.get_orgs_for_user(self.student)) == 2 |
241 | 241 |
|
| 242 | + @override_waffle_flag(AUTHZ_COURSE_AUTHORING_FLAG, active=True) |
| 243 | + def test_get_orgs_for_user_authz(self): |
| 244 | + """ |
| 245 | + Test get_orgs_for_user using AuthZ compatibility layer |
| 246 | + """ |
| 247 | + role = CourseStaffRole(self.course_key) |
| 248 | + |
| 249 | + other_org = "MIT" |
| 250 | + other_course_key = CourseKey.from_string(f"course-v1:{other_org}+Javascript+2026_T1") |
| 251 | + another_course_key = CourseKey.from_string(f"course-v1:{other_org}+Python+2026_T1") |
| 252 | + |
| 253 | + staff_authz_role = RoleData(external_key=COURSE_STAFF) |
| 254 | + instructor_authz_role = RoleData(external_key=COURSE_ADMIN) |
| 255 | + |
| 256 | + assignments = [ |
| 257 | + RoleAssignmentData( |
| 258 | + subject=UserData(external_key=self.student.username), |
| 259 | + roles=[staff_authz_role], |
| 260 | + scope=CourseOverviewData(external_key=str(self.course_key)), |
| 261 | + ), |
| 262 | + RoleAssignmentData( |
| 263 | + subject=UserData(external_key=self.student.username), |
| 264 | + roles=[staff_authz_role], |
| 265 | + scope=CourseOverviewData(external_key=str(other_course_key)), |
| 266 | + ), |
| 267 | + RoleAssignmentData( |
| 268 | + subject=UserData(external_key=self.student.username), |
| 269 | + roles=[staff_authz_role], |
| 270 | + scope=CourseOverviewData(external_key=str(another_course_key)), |
| 271 | + ), |
| 272 | + # Non-matching role should be ignored |
| 273 | + RoleAssignmentData( |
| 274 | + subject=UserData(external_key=self.student.username), |
| 275 | + roles=[instructor_authz_role], |
| 276 | + scope=CourseOverviewData(external_key=str(self.course_key)), |
| 277 | + ), |
| 278 | + ] |
| 279 | + |
| 280 | + with patch("openedx_authz.api.users.get_user_role_assignments_filtered", return_value=assignments): |
| 281 | + result = role.get_orgs_for_user(self.student) |
| 282 | + self.assertCountEqual(result, [self.course_key.org, other_org]) |
| 283 | + |
242 | 284 | def test_get_authz_compat_course_access_roles_for_user(self): |
243 | 285 | """ |
244 | | - Thest that get_authz_compat_course_access_roles_for_user doesn't crash when the user |
| 286 | + Test that get_authz_compat_course_access_roles_for_user doesn't crash when the user |
245 | 287 | has Libraries V2 or other non-course roles in their assignments. |
246 | 288 | """ |
247 | 289 | lib_assignment = RoleAssignmentData( |
|
0 commit comments