|
22 | 22 | get_subject_role_assignments, |
23 | 23 | get_subject_role_assignments_for_role_in_scope, |
24 | 24 | get_subject_role_assignments_in_scope, |
| 25 | + get_subjects_for_role_in_scope, |
25 | 26 | unassign_role_from_subject_in_scope, |
26 | 27 | ) |
27 | 28 | from openedx_authz.engine.enforcer import AuthzEnforcer |
@@ -524,6 +525,26 @@ def test_get_scopes_for_role_and_subject(self): |
524 | 525 | scope_names = {scope.external_key for scope in scopes} |
525 | 526 | self.assertEqual(scope_names, expected_scopes) |
526 | 527 |
|
| 528 | + @ddt_data( |
| 529 | + ("library_author", "lib:Org4:art_101", {"liam"}), |
| 530 | + ("library_author", "lib:Org4:art_201", {"liam"}), |
| 531 | + ("library_author", "lib:Org4:art_301", {"liam"}), |
| 532 | + ("non_existent_role", "lib:Org4:art_101", set()), |
| 533 | + ("library_author", "sc:non_existent_scope", set()), |
| 534 | + ("non_existent_role", "sc:non_existent_scope", set()), |
| 535 | + ) |
| 536 | + @unpack |
| 537 | + def test_get_subjects_for_role_in_scope(self, role_name: str, scope_name: str, expected_subjects: set[str]): |
| 538 | + """Test retrieving subjects for a given role in a specific scope. |
| 539 | +
|
| 540 | + Expected result: |
| 541 | + - The subjects associated with the specified role in the given scope are correctly retrieved. |
| 542 | + """ |
| 543 | + subjects = get_subjects_for_role_in_scope(RoleData(external_key=role_name), ScopeData(external_key=scope_name)) |
| 544 | + |
| 545 | + subject_names = {subject.external_key for subject in subjects} |
| 546 | + self.assertEqual(subject_names, expected_subjects) |
| 547 | + |
527 | 548 |
|
528 | 549 | @ddt |
529 | 550 | class TestRoleAssignmentAPI(RolesTestSetupMixin): |
|
0 commit comments