Skip to content

Commit da9459c

Browse files
committed
✅ [#229] Test new error behaviour
1 parent 6feef83 commit da9459c

File tree

3 files changed

+44
-50
lines changed

3 files changed

+44
-50
lines changed

backend/src/openarchiefbeheer/destruction/tests/test_models.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def test_process_deletion_zaak_not_found(self):
8484
zaak="http://zaken.nl/api/v1/zaken/111-111-111",
8585
)
8686

87-
with self.assertRaises(ObjectDoesNotExist):
88-
item.process_deletion()
87+
item.process_deletion()
8988

9089
item.refresh_from_db()
9190

backend/src/openarchiefbeheer/destruction/tests/test_signals.py

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def test_failure_during_deletion_sends_signal(self):
5555
body_error_during_deletion="ERROR AAAh!",
5656
),
5757
),
58-
self.assertRaises(Exception),
5958
):
6059
delete_destruction_list(destruction_list)
6160

backend/src/openarchiefbeheer/destruction/tests/test_tasks.py

+43-47
Original file line numberDiff line numberDiff line change
@@ -241,53 +241,6 @@ def test_process_list(self):
241241
).exists()
242242
)
243243

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-
291244
@log_capture(level=logging.INFO)
292245
def test_item_skipped_if_already_succeeded(self, logs):
293246
item = DestructionListItemFactory.create(
@@ -369,3 +322,46 @@ def test_complete_and_notify(self):
369322

370323
self.assertEqual(list.status, ListStatus.deleted)
371324
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

Comments
 (0)