@@ -294,16 +294,16 @@ class MockQuerySet:
294294 def __init__ (self , permissions ):
295295 self .permissions = permissions
296296
297- def filter (self , ** _ ):
297+ def filter (self , ** kwargs ):
298298 return self
299299
300- def select_related (self , * _ , ** __ ):
300+ def select_related (self , * args , ** kwargs ):
301301 return self
302302
303303 def all (self ):
304304 return self .permissions
305305
306- def get_or_create (self , ** _ ):
306+ def get_or_create (self ):
307307 raise Exception ("Unexpected error mock" )
308308
309309 class MockCourseAccessRole :
@@ -443,7 +443,8 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_no_deletion(self):
443443 CourseAccessRole , UserSubject , course_id_list = course_id_list , org_id = None , delete_after_migration = False
444444 )
445445
446- # Casbin assignments are intact since delete_after_migration is False
446+ # Check that each user has the expected legacy role after rollback and that errors
447+ # are logged for any permissions that could not be rolled back
447448 for user in self .admin_users :
448449 assignments = get_user_role_assignments_in_scope (
449450 user_external_key = user .username , scope_external_key = self .course_id
@@ -557,7 +558,8 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_deletion(self):
557558 CourseAccessRole , UserSubject , course_id_list = course_id_list , org_id = None , delete_after_migration = True
558559 )
559560
560- # Casbin assignments are removed since delete_after_migration is True
561+ # Check that each user has the expected legacy role after rollback
562+ # and that errors are logged for any permissions that could not be rolled back
561563 for user in self .admin_users :
562564 assignments = get_user_role_assignments_in_scope (
563565 user_external_key = user .username , scope_external_key = self .course_id
@@ -586,7 +588,8 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_deletion(self):
586588 CourseAccessRole .objects .all ().order_by ("id" ).values ("id" , "user_id" , "org" , "course_id" , "role" )
587589 )
588590
589- # 3 users * 4 roles = 12 recreated entries, plus the original invalid entry = 13 total
591+ # All original entries + 3 users * 4 roles = 12
592+ # plus the original invalid entry = 1 + 12 = 13 total entries
590593 self .assertEqual (len (after_migrate_state_access_roles ), 13 )
591594
592595 @patch ("openedx_authz.api.data.CourseOverview" , CourseOverview )
@@ -616,7 +619,8 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
616619 CourseAccessRole , UserSubject , course_id_list = course_id_list , org_id = None , delete_after_migration = True
617620 )
618621
619- # Admin assignments are removed; the rest remain since they had no legacy equivalent
622+ # Check that each user has the expected legacy role after rollback
623+ # and that errors are logged for any permissions that could not be rolled back
620624 for user in self .admin_users :
621625 assignments = get_user_role_assignments_in_scope (
622626 user_external_key = user .username , scope_external_key = self .course_id
@@ -626,16 +630,22 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
626630 assignments = get_user_role_assignments_in_scope (
627631 user_external_key = user .username , scope_external_key = self .course_id
628632 )
633+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
634+ # the staff role will not have a legacy role equivalent and therefore should not be migrated back
629635 self .assertEqual (len (assignments ), 1 )
630636 for user in self .limited_staff :
631637 assignments = get_user_role_assignments_in_scope (
632638 user_external_key = user .username , scope_external_key = self .course_id
633639 )
640+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
641+ # the limited_staff role will not have a legacy role equivalent and therefore should not be migrated back
634642 self .assertEqual (len (assignments ), 1 )
635643 for user in self .data_researcher :
636644 assignments = get_user_role_assignments_in_scope (
637645 user_external_key = user .username , scope_external_key = self .course_id
638646 )
647+ # Since we are mocking the COURSE_ROLE_EQUIVALENCES mapping to only include a mapping for COURSE_ADMIN,
648+ # the data_researcher role will not have a legacy role equivalent and therefore should not be migrated back
639649 self .assertEqual (len (assignments ), 1 )
640650
641651 # 3 staff + 3 limited_staff + 3 data_researcher = 9 entries with no legacy role equivalent
@@ -645,7 +655,7 @@ def test_migrate_legacy_course_roles_to_authz_and_rollback_with_no_new_role_equi
645655 CourseAccessRole .objects .all ().order_by ("id" ).values ("id" , "user_id" , "org" , "course_id" , "role" )
646656 )
647657
648- # 1 original invalid entry + 3 admin users rolled back = 4 total
658+ # All original entries (1) + 3 users * 1 roles = 4
649659 self .assertEqual (len (after_migrate_state_access_roles ), 1 + 3 )
650660
651661 @patch ("openedx_authz.api.data.CourseOverview" , CourseOverview )
@@ -697,13 +707,16 @@ def test_migrate_legacy_course_roles_to_authz_using_org_id(self):
697707 # Only the invalid role entry should remain since we set delete_after_migration to True
698708 self .assertEqual (len (after_migrate_state_access_roles ), 1 )
699709
710+ # Must be different before and after migration since we set delete_after_migration
711+ # to True and we are deleting all
700712 # Now let's rollback
701713
702714 permissions_with_errors , permissions_with_no_errors = migrate_authz_to_legacy_course_roles (
703715 CourseAccessRole , UserSubject , course_id_list = None , org_id = self .org , delete_after_migration = True
704716 )
705717
706- # Casbin assignments are removed since delete_after_migration is True
718+ # Check that each user has the expected legacy role after rollback
719+ # and that errors are logged for any permissions that could not be rolled back
707720 for user in self .admin_users :
708721 assignments = get_user_role_assignments_in_scope (
709722 user_external_key = user .username , scope_external_key = self .course_id
@@ -732,7 +745,8 @@ def test_migrate_legacy_course_roles_to_authz_using_org_id(self):
732745 CourseAccessRole .objects .all ().order_by ("id" ).values ("id" , "user_id" , "org" , "course_id" , "role" )
733746 )
734747
735- # 3 users * 4 roles = 12 recreated entries, plus the original invalid entry = 13 total
748+ # All original entries + 3 users * 4 roles = 12
749+ # plus the original invalid entry = 1 + 12 = 13 total entries
736750 self .assertEqual (len (after_migrate_state_access_roles ), 1 + 12 )
737751
738752 @patch ("openedx_authz.api.data.CourseOverview" , CourseOverview )
@@ -766,7 +780,7 @@ def test_authz_migrate_course_authoring_command(self, mock_migrate):
766780 call_command ("authz_migrate_course_authoring" , "--course-id-list" , self .course_id )
767781
768782 mock_migrate .assert_called_once ()
769- _ , kwargs = mock_migrate .call_args
783+ args , kwargs = mock_migrate .call_args
770784
771785 self .assertEqual (kwargs ["delete_after_migration" ], False )
772786
@@ -777,7 +791,7 @@ def test_authz_migrate_course_authoring_command(self, mock_migrate):
777791 call_command ("authz_migrate_course_authoring" , "--delete" , "--course-id-list" , self .course_id )
778792
779793 mock_migrate .assert_called_once ()
780- _ , kwargs = mock_migrate .call_args
794+ args , kwargs = mock_migrate .call_args
781795
782796 self .assertEqual (kwargs ["delete_after_migration" ], True )
783797
0 commit comments