|
5 | 5 | from ddt import data, ddt, unpack |
6 | 6 | from django.contrib.auth import get_user_model |
7 | 7 |
|
8 | | -from openedx_authz.api.data import ContentLibraryData, RoleAssignmentData, RoleData, UserData |
| 8 | +from openedx_authz.api.data import ( |
| 9 | + ContentLibraryData, |
| 10 | + CourseOverviewData, |
| 11 | + OrgContentLibraryGlobData, |
| 12 | + OrgCourseOverviewGlobData, |
| 13 | + PlatformContentLibraryGlobData, |
| 14 | + PlatformCourseOverviewGlobData, |
| 15 | + RoleAssignmentData, |
| 16 | + RoleData, |
| 17 | + UserData, |
| 18 | +) |
9 | 19 | from openedx_authz.api.users import ( |
10 | 20 | _filter_allowed_assignments, |
11 | 21 | _filter_candidate_assignments_by_params, |
|
17 | 27 | get_user_role_assignments_filtered, |
18 | 28 | get_user_role_assignments_for_role_in_scope, |
19 | 29 | get_user_role_assignments_in_scope, |
| 30 | + get_user_role_assignments_per_scope_type, |
20 | 31 | get_visible_role_assignments_for_user, |
21 | 32 | get_visible_user_role_assignments_filtered_by_current_user, |
22 | 33 | is_user_allowed, |
@@ -57,6 +68,76 @@ def _assign_roles_to_users( |
57 | 68 | ) |
58 | 69 |
|
59 | 70 |
|
| 71 | +@ddt |
| 72 | +class TestUserRoleAssignmentsPerScopeType(UserAssignmentsSetupMixin): |
| 73 | + """Tests for get_user_role_assignments_per_scope_type including glob scope types.""" |
| 74 | + |
| 75 | + GLOB_SCOPE_TEST_ASSIGNMENTS = [ |
| 76 | + { |
| 77 | + "subject_name": "nina", |
| 78 | + "role_name": roles.LIBRARY_ADMIN.external_key, |
| 79 | + "scope_name": OrgContentLibraryGlobData.build_external_key("GlobTest"), |
| 80 | + }, |
| 81 | + { |
| 82 | + "subject_name": "nina", |
| 83 | + "role_name": roles.COURSE_STAFF.external_key, |
| 84 | + "scope_name": OrgCourseOverviewGlobData.build_external_key("GlobTest"), |
| 85 | + }, |
| 86 | + { |
| 87 | + "subject_name": "nina", |
| 88 | + "role_name": roles.LIBRARY_ADMIN.external_key, |
| 89 | + "scope_name": PlatformContentLibraryGlobData.build_external_key(), |
| 90 | + }, |
| 91 | + { |
| 92 | + "subject_name": "nina", |
| 93 | + "role_name": roles.COURSE_STAFF.external_key, |
| 94 | + "scope_name": PlatformCourseOverviewGlobData.build_external_key(), |
| 95 | + }, |
| 96 | + ] |
| 97 | + |
| 98 | + @classmethod |
| 99 | + def setUpClass(cls): |
| 100 | + super().setUpClass() |
| 101 | + cls._assign_roles_to_users(assignments=cls.GLOB_SCOPE_TEST_ASSIGNMENTS) |
| 102 | + |
| 103 | + @data( |
| 104 | + ("eve", (ContentLibraryData,), 3), |
| 105 | + ("eve", (CourseOverviewData,), 0), |
| 106 | + ("carlos", (CourseOverviewData,), 3), |
| 107 | + ("carlos", (ContentLibraryData,), 0), |
| 108 | + ("carlos", (CourseOverviewData, ContentLibraryData), 3), |
| 109 | + ("nina", (OrgContentLibraryGlobData,), 1), |
| 110 | + ("nina", (OrgCourseOverviewGlobData,), 1), |
| 111 | + ("nina", (PlatformContentLibraryGlobData,), 1), |
| 112 | + ("nina", (PlatformCourseOverviewGlobData,), 1), |
| 113 | + ("nina", (OrgContentLibraryGlobData, OrgCourseOverviewGlobData), 2), |
| 114 | + ("nina", (PlatformContentLibraryGlobData, PlatformCourseOverviewGlobData), 2), |
| 115 | + ( |
| 116 | + "nina", |
| 117 | + ( |
| 118 | + OrgContentLibraryGlobData, |
| 119 | + OrgCourseOverviewGlobData, |
| 120 | + PlatformContentLibraryGlobData, |
| 121 | + PlatformCourseOverviewGlobData, |
| 122 | + ), |
| 123 | + 4, |
| 124 | + ), |
| 125 | + ("nina", (ContentLibraryData,), 0), |
| 126 | + ("nina", (CourseOverviewData,), 0), |
| 127 | + ) |
| 128 | + @unpack |
| 129 | + def test_get_user_role_assignments_per_scope_type(self, username, scope_types, expected_count): |
| 130 | + """Test retrieving role assignments for a user filtered by scope type.""" |
| 131 | + role_assignments = get_user_role_assignments_per_scope_type( |
| 132 | + user_external_key=username, |
| 133 | + scope_types=scope_types, |
| 134 | + ) |
| 135 | + |
| 136 | + self.assertEqual(len(role_assignments), expected_count) |
| 137 | + for assignment in role_assignments: |
| 138 | + self.assertIsInstance(assignment.scope, scope_types) |
| 139 | + |
| 140 | + |
60 | 141 | @ddt |
61 | 142 | class TestUserRoleAssignments(UserAssignmentsSetupMixin): |
62 | 143 | """Test suite for user-role assignment API functions.""" |
|
0 commit comments