1313 COURSE_DATA_RESEARCHER ,
1414 COURSE_LIMITED_STAFF ,
1515 COURSE_STAFF ,
16+ LEGACY_COURSE_ROLE_EQUIVALENCES ,
1617 LIBRARY_ADMIN ,
1718 LIBRARY_USER ,
1819)
@@ -305,6 +306,16 @@ def tearDown(self):
305306 scope_external_key = self .course_id ,
306307 )
307308
309+ def test_legacy_course_role_equivalences_mapping (self ):
310+ """Test that the LEGACY_COURSE_ROLE_EQUIVALENCES mapping contains no duplicate values."""
311+ legacy_roles = LEGACY_COURSE_ROLE_EQUIVALENCES .keys ()
312+ new_roles = LEGACY_COURSE_ROLE_EQUIVALENCES .values ()
313+
314+ # Check that there are no duplicate values in the mapping
315+ self .assertEqual (
316+ len (legacy_roles ), len (set (new_roles )), "LEGACY_COURSE_ROLE_EQUIVALENCES contains duplicate values"
317+ )
318+
308319 @patch ("openedx_authz.api.data.CourseOverview" , CourseOverview )
309320 def test_migrate_legacy_course_roles_to_authz_and_rollback_no_deletion (self ):
310321 """Test the migration of legacy permissions from CourseAccessRole to the new Casbin-based model
@@ -613,12 +624,12 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
613624 CourseAccessRole .objects .all ().order_by ("id" ).values ("id" , "user_id" , "org" , "course_id" , "role" )
614625 )
615626
616- # Mock the role_to_legacy_role mapping to only include a mapping
627+ # Mock the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping
617628 # for COURSE_ADMIN to simulate the scenario where the staff, limited_staff
618629 # and data_researcher roles do not have a legacy role equivalent and
619630 # therefore cannot be migrated back to legacy roles during the rollback.
620631 with patch (
621- "openedx_authz.engine.utils.role_to_legacy_role " ,
632+ "openedx_authz.engine.utils.COURSE_ROLE_EQUIVALENCES " ,
622633 {COURSE_ADMIN .external_key : "instructor" },
623634 ):
624635 permissions_with_errors = migrate_authz_to_legacy_course_roles (
@@ -636,21 +647,21 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
636647 assignments = get_user_role_assignments_in_scope (
637648 user_external_key = user .username , scope_external_key = self .course_id
638649 )
639- # Since we are mocking the role_to_legacy_role mapping to only include a mapping for COURSE_ADMIN,
650+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
640651 # the staff role will not have a legacy role equivalent and therefore should not be migrated back
641652 self .assertEqual (len (assignments ), 1 )
642653 for user in self .limited_staff :
643654 assignments = get_user_role_assignments_in_scope (
644655 user_external_key = user .username , scope_external_key = self .course_id
645656 )
646- # Since we are mocking the role_to_legacy_role mapping to only include a mapping for COURSE_ADMIN,
657+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
647658 # the limited_staff role will not have a legacy role equivalent and therefore should not be migrated back
648659 self .assertEqual (len (assignments ), 1 )
649660 for user in self .data_researcher :
650661 assignments = get_user_role_assignments_in_scope (
651662 user_external_key = user .username , scope_external_key = self .course_id
652663 )
653- # Since we are mocking the role_to_legacy_role mapping to only include a mapping for COURSE_ADMIN,
664+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
654665 # the data_researcher role will not have a legacy role equivalent and therefore should not be migrated back
655666 self .assertEqual (len (assignments ), 1 )
656667
@@ -680,7 +691,7 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
680691
681692 # After rollback, we should have 9 UserSubjects related to the course permissions
682693 # since the users with staff, limited_staff and data_researcher roles will not be
683- # migrated back to legacy roles due to our mocked role_to_legacy_role mapping.
694+ # migrated back to legacy roles due to our mocked COURSE_ROLE_EQUIVALENCES mapping.
684695 self .assertEqual (len (state_after_migration_user_subjects ), 9 )
685696
686697 @patch ("openedx_authz.management.commands.authz_migrate_course_authoring.CourseAccessRole" , CourseAccessRole )
0 commit comments