@@ -942,6 +942,51 @@ def test_authz_migrate_course_authoring_command(self, mock_migrate):
942942
943943 self .assertEqual (kwargs ["delete_after_migration" ], True )
944944
945+ @patch ("openedx_authz.management.commands.authz_migrate_course_authoring.CourseAccessRole" , CourseAccessRole )
946+ @patch ("openedx_authz.management.commands.authz_migrate_course_authoring.migrate_legacy_course_roles_to_authz" )
947+ def test_authz_migrate_course_authoring_command_mixed_success (self , mock_migrate ):
948+ """
949+ Verify that the authz_migrate_course_authoring command outputs without errors
950+ for mixed success operations.
951+ """
952+
953+ mock_migrate .return_value = (
954+ ["course-v1:fail" ],
955+ [self .course_id ],
956+ ) # Return one success and one failure
957+
958+ call_command ("authz_migrate_course_authoring" , "--course-id-list" , self .course_id )
959+ mock_migrate .assert_called_once ()
960+
961+ # Return only one success
962+ mock_migrate .reset_mock ()
963+ mock_migrate .return_value = (
964+ [],
965+ [self .course_id ],
966+ )
967+
968+ call_command ("authz_migrate_course_authoring" , "--course-id-list" , self .course_id )
969+ mock_migrate .assert_called_once ()
970+
971+ # Return only one failure
972+ mock_migrate .reset_mock ()
973+ mock_migrate .return_value = (
974+ [self .course_id ],
975+ [],
976+ )
977+
978+ call_command ("authz_migrate_course_authoring" , "--course-id-list" , self .course_id )
979+ mock_migrate .assert_called_once ()
980+
981+ # Return only no successes or failures
982+ mock_migrate .reset_mock ()
983+ mock_migrate .return_value = (
984+ [],
985+ [],
986+ )
987+ call_command ("authz_migrate_course_authoring" , "--course-id-list" , self .course_id )
988+ mock_migrate .assert_called_once ()
989+
945990 @patch ("openedx_authz.management.commands.authz_rollback_course_authoring.CourseAccessRole" , CourseAccessRole )
946991 @patch ("openedx_authz.management.commands.authz_rollback_course_authoring.migrate_authz_to_legacy_course_roles" )
947992 def test_authz_rollback_course_authoring_command (self , mock_rollback ):
@@ -972,6 +1017,52 @@ def test_authz_rollback_course_authoring_command(self, mock_rollback):
9721017
9731018 self .assertEqual (call_kwargs ["delete_after_migration" ], True )
9741019
1020+ @patch ("openedx_authz.management.commands.authz_rollback_course_authoring.CourseAccessRole" , CourseAccessRole )
1021+ @patch ("openedx_authz.management.commands.authz_rollback_course_authoring.migrate_authz_to_legacy_course_roles" )
1022+ def test_authz_rollback_course_authoring_command_mixed_success (self , mock_rollback ):
1023+ """
1024+ Verify that the authz_rollback_course_authoring command does not error in
1025+ mixed success operations.
1026+ """
1027+
1028+ # Return one success and one failure
1029+ mock_rollback .return_value = (
1030+ ["course-v1:fail" ],
1031+ [self .course_id ],
1032+ )
1033+ call_command ("authz_rollback_course_authoring" , "--course-id-list" , self .course_id )
1034+ mock_rollback .assert_called_once ()
1035+
1036+ # Return only one success
1037+ mock_rollback .reset_mock ()
1038+ mock_rollback .return_value = (
1039+ [],
1040+ [self .course_id ],
1041+ )
1042+
1043+ call_command ("authz_rollback_course_authoring" , "--course-id-list" , self .course_id )
1044+ mock_rollback .assert_called_once ()
1045+
1046+ # Return only one failure
1047+ mock_rollback .reset_mock ()
1048+ mock_rollback .return_value = (
1049+ [self .course_id ],
1050+ [],
1051+ )
1052+
1053+ call_command ("authz_rollback_course_authoring" , "--course-id-list" , self .course_id )
1054+ mock_rollback .assert_called_once ()
1055+
1056+ # Return only no successes or failures
1057+ mock_rollback .reset_mock ()
1058+ mock_rollback .return_value = (
1059+ [],
1060+ [],
1061+ )
1062+
1063+ call_command ("authz_rollback_course_authoring" , "--course-id-list" , self .course_id )
1064+ mock_rollback .assert_called_once ()
1065+
9751066 @patch ("openedx_authz.management.commands.authz_migrate_course_authoring.CourseAccessRole" , CourseAccessRole )
9761067 @patch ("openedx_authz.management.commands.authz_migrate_course_authoring.migrate_legacy_course_roles_to_authz" )
9771068 def test_authz_migrate_course_authoring_command_delete_confirmation_no (self , mock_migrate ):
0 commit comments