@@ -1100,3 +1100,143 @@ def test_cancel_all_unlikely_thing_to_happen(self):
1100
1100
response = self .client .post (cancel_url )
1101
1101
1102
1102
self .assertEqual (response .status_code , status .HTTP_422_UNPROCESSABLE_ENTITY )
1103
+
1104
+
1105
+ class TestFilteredRemindAllCancelAll (CRUDViewTestMixin , APITest ):
1106
+ """
1107
+ Tests for the remind-all and cancel-all actions when filters are provided in the request query.
1108
+ """
1109
+ def test_cancel_all_filter_multiple_learner_states (self ):
1110
+ """
1111
+ Tests the cancel-all view with a provided filter on multiple learner_states.
1112
+ """
1113
+ self .set_jwt_cookie ([
1114
+ {'system_wide_role' : SYSTEM_ENTERPRISE_ADMIN_ROLE , 'context' : str (TEST_ENTERPRISE_UUID )}
1115
+ ])
1116
+ learner_states_to_query = [
1117
+ AssignmentLearnerStates .WAITING ,
1118
+ AssignmentLearnerStates .FAILED ,
1119
+ AssignmentLearnerStates .NOTIFYING ,
1120
+ ]
1121
+ cancel_kwargs = {
1122
+ 'assignment_configuration_uuid' : str (self .assignment_configuration .uuid ),
1123
+ }
1124
+ cancel_url = reverse ('api:v1:admin-assignments-cancel-all' , kwargs = cancel_kwargs )
1125
+ learner_state_query_param_value = "," .join (learner_states_to_query )
1126
+ cancel_url += f'?learner_state__in={ learner_state_query_param_value } '
1127
+
1128
+ expected_cancelled_assignments = [
1129
+ self .assignment_allocated_pre_link ,
1130
+ self .assignment_allocated_post_link ,
1131
+ self .requester_assignment_errored ,
1132
+ ]
1133
+ with mock .patch (
1134
+ 'enterprise_access.apps.content_assignments.tasks.send_cancel_email_for_pending_assignment'
1135
+ ) as mock_cancel_task :
1136
+ response = self .client .post (cancel_url )
1137
+
1138
+ assert response .status_code == status .HTTP_202_ACCEPTED
1139
+ mock_cancel_task .delay .assert_has_calls (
1140
+ [mock .call (assignment .uuid ) for assignment in expected_cancelled_assignments ],
1141
+ any_order = True ,
1142
+ )
1143
+ for assignment in expected_cancelled_assignments :
1144
+ assignment .refresh_from_db ()
1145
+ self .assertEqual (assignment .state , LearnerContentAssignmentStateChoices .CANCELLED )
1146
+
1147
+ def test_cancel_all_filter_single_learner_state (self ):
1148
+ """
1149
+ Tests the cancel-all view with a provided filter on a single learner_state.
1150
+ """
1151
+ self .set_jwt_cookie ([
1152
+ {'system_wide_role' : SYSTEM_ENTERPRISE_ADMIN_ROLE , 'context' : str (TEST_ENTERPRISE_UUID )}
1153
+ ])
1154
+ cancel_kwargs = {
1155
+ 'assignment_configuration_uuid' : str (self .assignment_configuration .uuid ),
1156
+ }
1157
+ cancel_url = reverse ('api:v1:admin-assignments-cancel-all' , kwargs = cancel_kwargs )
1158
+ cancel_url += f'?learner_state={ AssignmentLearnerStates .WAITING } '
1159
+
1160
+ expected_cancelled_assignments = [
1161
+ self .assignment_allocated_post_link ,
1162
+ ]
1163
+ with mock .patch (
1164
+ 'enterprise_access.apps.content_assignments.tasks.send_cancel_email_for_pending_assignment'
1165
+ ) as mock_cancel_task :
1166
+ response = self .client .post (cancel_url )
1167
+
1168
+ assert response .status_code == status .HTTP_202_ACCEPTED
1169
+ mock_cancel_task .delay .assert_has_calls (
1170
+ [mock .call (assignment .uuid ) for assignment in expected_cancelled_assignments ],
1171
+ any_order = True ,
1172
+ )
1173
+ for assignment in expected_cancelled_assignments :
1174
+ assignment .refresh_from_db ()
1175
+ self .assertEqual (assignment .state , LearnerContentAssignmentStateChoices .CANCELLED )
1176
+
1177
+ def test_remind_all_filter_multiple_learner_states (self ):
1178
+ """
1179
+ Tests the remind-all view with a provided filter on multiple learner_states.
1180
+ """
1181
+ self .set_jwt_cookie ([
1182
+ {'system_wide_role' : SYSTEM_ENTERPRISE_ADMIN_ROLE , 'context' : str (TEST_ENTERPRISE_UUID )}
1183
+ ])
1184
+ learner_states_to_query = [
1185
+ AssignmentLearnerStates .WAITING ,
1186
+ AssignmentLearnerStates .FAILED ,
1187
+ AssignmentLearnerStates .NOTIFYING ,
1188
+ ]
1189
+ remind_kwargs = {
1190
+ 'assignment_configuration_uuid' : str (self .assignment_configuration .uuid ),
1191
+ }
1192
+ remind_url = reverse ('api:v1:admin-assignments-remind-all' , kwargs = remind_kwargs )
1193
+ learner_state_query_param_value = "," .join (learner_states_to_query )
1194
+ remind_url += f'?learner_state__in={ learner_state_query_param_value } '
1195
+
1196
+ expected_reminded_assignments = [
1197
+ self .assignment_allocated_pre_link ,
1198
+ self .assignment_allocated_post_link ,
1199
+ ]
1200
+ with mock .patch (
1201
+ 'enterprise_access.apps.content_assignments.api.send_reminder_email_for_pending_assignment'
1202
+ ) as mock_remind_task :
1203
+ response = self .client .post (remind_url )
1204
+
1205
+ assert response .status_code == status .HTTP_202_ACCEPTED
1206
+ mock_remind_task .delay .assert_has_calls (
1207
+ [mock .call (assignment .uuid ) for assignment in expected_reminded_assignments ],
1208
+ any_order = True ,
1209
+ )
1210
+ for assignment in expected_reminded_assignments :
1211
+ assignment .refresh_from_db ()
1212
+ self .assertEqual (assignment .state , LearnerContentAssignmentStateChoices .ALLOCATED )
1213
+
1214
+ def test_remind_all_filter_single_learner_state (self ):
1215
+ """
1216
+ Tests the remind-all view with a provided filter on a single learner_state.
1217
+ """
1218
+ self .set_jwt_cookie ([
1219
+ {'system_wide_role' : SYSTEM_ENTERPRISE_ADMIN_ROLE , 'context' : str (TEST_ENTERPRISE_UUID )}
1220
+ ])
1221
+ remind_kwargs = {
1222
+ 'assignment_configuration_uuid' : str (self .assignment_configuration .uuid ),
1223
+ }
1224
+ remind_url = reverse ('api:v1:admin-assignments-remind-all' , kwargs = remind_kwargs )
1225
+ remind_url += f'?learner_state={ AssignmentLearnerStates .WAITING } '
1226
+
1227
+ expected_reminded_assignments = [
1228
+ self .assignment_allocated_post_link ,
1229
+ ]
1230
+ with mock .patch (
1231
+ 'enterprise_access.apps.content_assignments.api.send_reminder_email_for_pending_assignment'
1232
+ ) as mock_remind_task :
1233
+ response = self .client .post (remind_url )
1234
+
1235
+ assert response .status_code == status .HTTP_202_ACCEPTED
1236
+ mock_remind_task .delay .assert_has_calls (
1237
+ [mock .call (assignment .uuid ) for assignment in expected_reminded_assignments ],
1238
+ any_order = True ,
1239
+ )
1240
+ for assignment in expected_reminded_assignments :
1241
+ assignment .refresh_from_db ()
1242
+ self .assertEqual (assignment .state , LearnerContentAssignmentStateChoices .ALLOCATED )
0 commit comments