@@ -241,53 +241,6 @@ def test_process_list(self):
241
241
).exists ()
242
242
)
243
243
244
- @override_settings (CELERY_TASK_ALWAYS_EAGER = True )
245
- def test_process_item_raises_error (self ):
246
- destruction_list = DestructionListFactory .create (
247
- status = ListStatus .ready_to_delete
248
- )
249
- ZaakFactory .create (
250
- url = "http://zaken.nl/api/v1/zaken/111-111-111" ,
251
- )
252
- item1 = DestructionListItemFactory .create (
253
- zaak = "http://zaken.nl/api/v1/zaken/111-111-111" ,
254
- destruction_list = destruction_list ,
255
- )
256
- ZaakFactory .create (
257
- url = "http://zaken.nl/api/v1/zaken/222-222-222" ,
258
- )
259
- item2 = DestructionListItemFactory .create (
260
- zaak = "http://zaken.nl/api/v1/zaken/222-222-222" ,
261
- destruction_list = destruction_list ,
262
- )
263
-
264
- with (
265
- patch (
266
- "openarchiefbeheer.destruction.models.delete_zaak_and_related_objects" ,
267
- side_effect = Exception ,
268
- ),
269
- self .assertRaises (Exception ),
270
- ):
271
- delete_destruction_list (destruction_list )
272
-
273
- destruction_list .refresh_from_db ()
274
- item1 .refresh_from_db ()
275
- item2 .refresh_from_db ()
276
-
277
- self .assertEqual (destruction_list .processing_status , InternalStatus .failed )
278
- self .assertEqual (destruction_list .status , ListStatus .ready_to_delete )
279
-
280
- # We don't know which item is processed first
281
- statuses = [item1 .processing_status , item2 .processing_status ]
282
- self .assertIn (InternalStatus .failed , statuses )
283
- self .assertIn (InternalStatus .new , statuses )
284
- self .assertTrue (
285
- Zaak .objects .filter (url = "http://zaken.nl/api/v1/zaken/111-111-111" ).exists ()
286
- )
287
- self .assertTrue (
288
- Zaak .objects .filter (url = "http://zaken.nl/api/v1/zaken/222-222-222" ).exists ()
289
- )
290
-
291
244
@log_capture (level = logging .INFO )
292
245
def test_item_skipped_if_already_succeeded (self , logs ):
293
246
item = DestructionListItemFactory .create (
@@ -369,3 +322,46 @@ def test_complete_and_notify(self):
369
322
370
323
self .assertEqual (list .status , ListStatus .deleted )
371
324
self .assertEqual (list .processing_status , InternalStatus .succeeded )
325
+
326
+ @override_settings (CELERY_TASK_ALWAYS_EAGER = True )
327
+ def test_other_items_processed_if_one_fails (self ):
328
+ destruction_list = DestructionListFactory .create (
329
+ status = ListStatus .ready_to_delete
330
+ )
331
+ ZaakFactory .create (
332
+ url = "http://zaken.nl/api/v1/zaken/111-111-111" ,
333
+ )
334
+ item1 = DestructionListItemFactory .create (
335
+ zaak = "http://zaken.nl/api/v1/zaken/111-111-111" ,
336
+ destruction_list = destruction_list ,
337
+ )
338
+ ZaakFactory .create (
339
+ url = "http://zaken.nl/api/v1/zaken/222-222-222" ,
340
+ )
341
+ item2 = DestructionListItemFactory .create (
342
+ zaak = "http://zaken.nl/api/v1/zaken/222-222-222" ,
343
+ destruction_list = destruction_list ,
344
+ )
345
+
346
+ def mock_exceptions (zaak , result_store ):
347
+ if zaak .url == item1 .zaak :
348
+ raise Exception ("An errur occurred!" )
349
+
350
+ with (
351
+ patch (
352
+ "openarchiefbeheer.destruction.models.delete_zaak_and_related_objects" ,
353
+ side_effect = mock_exceptions ,
354
+ ),
355
+ ):
356
+ delete_destruction_list (destruction_list )
357
+
358
+ destruction_list .refresh_from_db ()
359
+ item1 .refresh_from_db ()
360
+ item2 .refresh_from_db ()
361
+
362
+ self .assertEqual (destruction_list .processing_status , InternalStatus .failed )
363
+ self .assertEqual (destruction_list .status , ListStatus .ready_to_delete )
364
+ self .assertEqual (item1 .processing_status , InternalStatus .failed )
365
+ self .assertEqual (item2 .processing_status , InternalStatus .succeeded )
366
+ self .assertTrue (Zaak .objects .filter (url = item1 .zaak ).exists ())
367
+ self .assertFalse (Zaak .objects .filter (url = item2 .zaak ).exists ())
0 commit comments