Skip to content

Commit 0a0e2b5

Browse files
SilviaAmAmsvenvandescheur
authored andcommitted
✅ [#397] Test failure during zaak deletion
1 parent ee197c7 commit 0a0e2b5

File tree

2 files changed

+313
-1
lines changed

2 files changed

+313
-1
lines changed

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

+286
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
from freezegun import freeze_time
99
from privates.test import temp_private_root
10+
from requests import HTTPError
11+
from requests_mock import Mocker
12+
from zgw_consumers.constants import APITypes
13+
from zgw_consumers.test.factories import ServiceFactory
1014

1115
from openarchiefbeheer.config.models import ArchiveConfig
16+
from openarchiefbeheer.utils.results_store import ResultStore
1217
from openarchiefbeheer.zaken.models import Zaak
1318
from openarchiefbeheer.zaken.tests.factories import ZaakFactory
1419

@@ -200,6 +205,15 @@ def test_derive_status(self):
200205
)
201206

202207

208+
TEST_DATA_ARCHIVE_CONFIG = {
209+
"bronorganisatie": "000000000",
210+
"zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/ecd08880-5081-4d7a-afc3-ade1d6e6346f",
211+
"statustype": "http://localhost:8003/catalogi/api/v1/statustypen/835a2a13-f52f-4339-83e5-b7250e5ad016",
212+
"resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/5d39b8ac-437a-475c-9a76-0f6ae1540d0e",
213+
"informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/9dee6712-122e-464a-99a3-c16692de5485",
214+
}
215+
216+
203217
@temp_private_root()
204218
class DestructionListTest(TestCase):
205219
def test_has_long_review_process(self):
@@ -347,3 +361,275 @@ def test_generate_destruction_report(self):
347361
lines[3],
348362
b"http://zaken.nl/api/v1/zaken/111-111-333,2022-01-03,http://zaken.nl/api/v1/resultaten/111-111-333,2020-01-03,Test description 3,ZAAK-03,http://catalogi.nl/api/v1/zaaktypen/111-111-222,Tralala zaaktype,2\n",
349363
)
364+
365+
def test_zaak_creation_skipped_if_internal_status_succeeded(self):
366+
destruction_list = DestructionListFactory.create(
367+
processing_status=InternalStatus.succeeded
368+
)
369+
370+
with patch(
371+
"openarchiefbeheer.destruction.utils.create_zaak_for_report"
372+
) as m_zaak:
373+
destruction_list.create_report_zaak()
374+
375+
m_zaak.assert_not_called()
376+
377+
@Mocker()
378+
def test_failure_during_zaak_creation(self, m):
379+
destruction_list = DestructionListFactory.create()
380+
ServiceFactory.create(
381+
api_type=APITypes.zrc,
382+
api_root="http://localhost:8003/zaken/api/v1",
383+
)
384+
385+
m.post("http://localhost:8003/zaken/api/v1/zaken", status_code=500)
386+
387+
with (
388+
patch(
389+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
390+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
391+
),
392+
self.assertRaises(HTTPError),
393+
):
394+
destruction_list.create_report_zaak()
395+
396+
destruction_list.refresh_from_db()
397+
398+
self.assertEqual(destruction_list.zaak_destruction_report_url, "")
399+
400+
@Mocker()
401+
def test_failure_result_creation(self, m):
402+
destruction_list = DestructionListFactory.create()
403+
ServiceFactory.create(
404+
api_type=APITypes.zrc,
405+
api_root="http://localhost:8003/zaken/api/v1",
406+
)
407+
408+
m.post(
409+
"http://localhost:8003/zaken/api/v1/zaken",
410+
json={"url": "http://localhost:8003/zaken/api/v1/zaken/111-111-111"},
411+
)
412+
m.post("http://localhost:8003/zaken/api/v1/resultaten", status_code=500)
413+
414+
with (
415+
patch(
416+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
417+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
418+
),
419+
self.assertRaises(HTTPError),
420+
):
421+
destruction_list.create_report_zaak()
422+
423+
destruction_list.refresh_from_db()
424+
425+
self.assertEqual(
426+
destruction_list.zaak_destruction_report_url,
427+
"http://localhost:8003/zaken/api/v1/zaken/111-111-111",
428+
)
429+
430+
@Mocker()
431+
def test_failure_status_creation(self, m):
432+
destruction_list = DestructionListFactory.create()
433+
ServiceFactory.create(
434+
api_type=APITypes.zrc,
435+
api_root="http://localhost:8003/zaken/api/v1",
436+
)
437+
438+
m.post(
439+
"http://localhost:8003/zaken/api/v1/zaken",
440+
json={"url": "http://localhost:8003/zaken/api/v1/zaken/111-111-111"},
441+
)
442+
m.post(
443+
"http://localhost:8003/zaken/api/v1/resultaten",
444+
json={"url": "http://localhost:8003/zaken/api/v1/resultaten/111-111-111"},
445+
)
446+
m.post("http://localhost:8003/zaken/api/v1/statussen", status_code=500)
447+
448+
with (
449+
patch(
450+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
451+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
452+
),
453+
self.assertRaises(HTTPError),
454+
):
455+
destruction_list.create_report_zaak()
456+
457+
destruction_list.refresh_from_db()
458+
459+
self.assertEqual(
460+
destruction_list.zaak_destruction_report_url,
461+
"http://localhost:8003/zaken/api/v1/zaken/111-111-111",
462+
)
463+
self.assertEqual(
464+
destruction_list.internal_results["created_resources"]["resultaten"],
465+
["http://localhost:8003/zaken/api/v1/resultaten/111-111-111"],
466+
)
467+
468+
@Mocker()
469+
def test_failure_document_creation(self, m):
470+
destruction_list = DestructionListFactory.create(with_report=True)
471+
ServiceFactory.create(
472+
api_type=APITypes.zrc,
473+
api_root="http://localhost:8003/zaken/api/v1",
474+
)
475+
ServiceFactory.create(
476+
api_type=APITypes.drc,
477+
api_root="http://localhost:8003/documenten/api/v1",
478+
)
479+
480+
m.post(
481+
"http://localhost:8003/zaken/api/v1/zaken",
482+
json={"url": "http://localhost:8003/zaken/api/v1/zaken/111-111-111"},
483+
)
484+
m.post(
485+
"http://localhost:8003/zaken/api/v1/resultaten",
486+
json={"url": "http://localhost:8003/zaken/api/v1/resultaten/111-111-111"},
487+
)
488+
m.post(
489+
"http://localhost:8003/zaken/api/v1/statussen",
490+
json={"url": "http://localhost:8003/zaken/api/v1/statussen/111-111-111"},
491+
)
492+
m.post(
493+
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten",
494+
status_code=500,
495+
)
496+
497+
with (
498+
patch(
499+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
500+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
501+
),
502+
self.assertRaises(HTTPError),
503+
):
504+
destruction_list.create_report_zaak()
505+
506+
destruction_list.refresh_from_db()
507+
508+
self.assertEqual(
509+
destruction_list.zaak_destruction_report_url,
510+
"http://localhost:8003/zaken/api/v1/zaken/111-111-111",
511+
)
512+
self.assertEqual(
513+
destruction_list.internal_results["created_resources"]["resultaten"],
514+
["http://localhost:8003/zaken/api/v1/resultaten/111-111-111"],
515+
)
516+
self.assertEqual(
517+
destruction_list.internal_results["created_resources"]["statussen"],
518+
["http://localhost:8003/zaken/api/v1/statussen/111-111-111"],
519+
)
520+
521+
@Mocker()
522+
def test_failure_zio_creation(self, m):
523+
destruction_list = DestructionListFactory.create(with_report=True)
524+
ServiceFactory.create(
525+
api_type=APITypes.zrc,
526+
api_root="http://localhost:8003/zaken/api/v1",
527+
)
528+
ServiceFactory.create(
529+
api_type=APITypes.drc,
530+
api_root="http://localhost:8003/documenten/api/v1",
531+
)
532+
533+
m.post(
534+
"http://localhost:8003/zaken/api/v1/zaken",
535+
json={"url": "http://localhost:8003/zaken/api/v1/zaken/111-111-111"},
536+
)
537+
m.post(
538+
"http://localhost:8003/zaken/api/v1/resultaten",
539+
json={"url": "http://localhost:8003/zaken/api/v1/resultaten/111-111-111"},
540+
)
541+
m.post(
542+
"http://localhost:8003/zaken/api/v1/statussen",
543+
json={"url": "http://localhost:8003/zaken/api/v1/statussen/111-111-111"},
544+
)
545+
m.post(
546+
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten",
547+
json={
548+
"url": "http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/111-111-111"
549+
},
550+
)
551+
m.post(
552+
"http://localhost:8003/zaken/api/v1/zaakinformatieobjecten", status_code=500
553+
)
554+
555+
with (
556+
patch(
557+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
558+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
559+
),
560+
self.assertRaises(HTTPError),
561+
):
562+
destruction_list.create_report_zaak()
563+
564+
destruction_list.refresh_from_db()
565+
566+
self.assertEqual(
567+
destruction_list.zaak_destruction_report_url,
568+
"http://localhost:8003/zaken/api/v1/zaken/111-111-111",
569+
)
570+
self.assertEqual(
571+
destruction_list.internal_results["created_resources"]["resultaten"],
572+
["http://localhost:8003/zaken/api/v1/resultaten/111-111-111"],
573+
)
574+
self.assertEqual(
575+
destruction_list.internal_results["created_resources"]["statussen"],
576+
["http://localhost:8003/zaken/api/v1/statussen/111-111-111"],
577+
)
578+
self.assertEqual(
579+
destruction_list.internal_results["created_resources"][
580+
"enkelvoudiginformatieobjecten"
581+
],
582+
[
583+
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/111-111-111"
584+
],
585+
)
586+
587+
@Mocker()
588+
def test_resume_after_failure(self, m):
589+
destruction_list = DestructionListFactory.create(
590+
zaak_destruction_report_url="http://localhost:8003/zaken/api/v1/zaken/111-111-111"
591+
)
592+
result_store = ResultStore(destruction_list)
593+
internal_results = result_store.get_internal_results()
594+
# Fake intermediate results that are created during failures
595+
internal_results["created_resources"].update(
596+
{
597+
"resultaten": [
598+
"http://localhost:8003/zaken/api/v1/resultaten/111-111-111"
599+
],
600+
"statussen": [
601+
"http://localhost:8003/zaken/api/v1/statussen/111-111-111"
602+
],
603+
"enkelvoudiginformatieobjecten": [
604+
"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/111-111-111"
605+
],
606+
}
607+
)
608+
result_store.save()
609+
ServiceFactory.create(
610+
api_type=APITypes.zrc,
611+
api_root="http://localhost:8003/zaken/api/v1",
612+
)
613+
614+
m.post(
615+
"http://localhost:8003/zaken/api/v1/zaakinformatieobjecten",
616+
json={
617+
"url": "http://localhost:8003/zaken/api/v1/zaakinformatieobjecten/111-111-111"
618+
},
619+
)
620+
621+
# Calling create_report_zaak resumes from where there is no stored intermediate result (i.e. creating the ZIO)
622+
with patch(
623+
"openarchiefbeheer.destruction.utils.ArchiveConfig.get_solo",
624+
return_value=ArchiveConfig(**TEST_DATA_ARCHIVE_CONFIG),
625+
):
626+
destruction_list.create_report_zaak()
627+
628+
destruction_list.refresh_from_db()
629+
630+
self.assertEqual(
631+
destruction_list.internal_results["created_resources"][
632+
"zaakinformatieobjecten"
633+
],
634+
["http://localhost:8003/zaken/api/v1/zaakinformatieobjecten/111-111-111"],
635+
)

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

+27-1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,25 @@ def test_complete_and_notify(self):
409409
processing_status=InternalStatus.processing,
410410
status=ListStatus.ready_to_delete,
411411
)
412+
DestructionListItemFactory.create(
413+
processing_status=InternalStatus.succeeded,
414+
destruction_list=destruction_list,
415+
extra_zaak_data={
416+
"url": "http://zaken.nl/api/v1/zaken/111-111-111",
417+
"omschrijving": "Test description 1",
418+
"identificatie": "ZAAK-01",
419+
"startdatum": "2020-01-01",
420+
"einddatum": "2022-01-01",
421+
"resultaat": "http://zaken.nl/api/v1/resultaten/111-111-111",
422+
"zaaktype": {
423+
"url": "http://catalogi.nl/api/v1/zaaktypen/111-111-111",
424+
"omschrijving": "Tralala zaaktype",
425+
"selectielijst_procestype": {
426+
"nummer": 1,
427+
},
428+
},
429+
},
430+
)
412431
assignees = DestructionListAssigneeFactory.create_batch(
413432
3, destruction_list=destruction_list
414433
)
@@ -423,6 +442,9 @@ def test_complete_and_notify(self):
423442
body_successful_deletion="Wohoo deleted list",
424443
),
425444
),
445+
patch("openarchiefbeheer.destruction.utils.create_zaak_for_report"),
446+
patch("openarchiefbeheer.destruction.utils.create_eio_destruction_report"),
447+
patch("openarchiefbeheer.destruction.utils.attach_report_to_zaak"),
426448
freeze_time("2024-10-09"),
427449
):
428450
complete_and_notify(destruction_list.pk)
@@ -445,11 +467,15 @@ def test_complete_and_notify(self):
445467

446468
lines = [line for line in destruction_list.destruction_report.readlines()]
447469

448-
self.assertEqual(len(lines), 1)
470+
self.assertEqual(len(lines), 2)
449471
self.assertEqual(
450472
lines[0],
451473
b"url,einddatum,resultaat,startdatum,omschrijving,identificatie,zaaktype url,zaaktype omschrijving,selectielijst procestype nummer\n",
452474
)
475+
self.assertEqual(
476+
lines[1],
477+
b"http://zaken.nl/api/v1/zaken/111-111-111,2022-01-01,http://zaken.nl/api/v1/resultaten/111-111-111,2020-01-01,Test description 1,ZAAK-01,http://catalogi.nl/api/v1/zaaktypen/111-111-111,Tralala zaaktype,1\n",
478+
)
453479

454480
@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
455481
def test_other_items_processed_if_one_fails(self):

0 commit comments

Comments
 (0)