|
7 | 7 |
|
8 | 8 | from freezegun import freeze_time
|
9 | 9 | 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 |
10 | 14 |
|
11 | 15 | from openarchiefbeheer.config.models import ArchiveConfig
|
| 16 | +from openarchiefbeheer.utils.results_store import ResultStore |
12 | 17 | from openarchiefbeheer.zaken.models import Zaak
|
13 | 18 | from openarchiefbeheer.zaken.tests.factories import ZaakFactory
|
14 | 19 |
|
@@ -200,6 +205,15 @@ def test_derive_status(self):
|
200 | 205 | )
|
201 | 206 |
|
202 | 207 |
|
| 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 | + |
203 | 217 | @temp_private_root()
|
204 | 218 | class DestructionListTest(TestCase):
|
205 | 219 | def test_has_long_review_process(self):
|
@@ -347,3 +361,275 @@ def test_generate_destruction_report(self):
|
347 | 361 | lines[3],
|
348 | 362 | 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",
|
349 | 363 | )
|
| 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 | + ) |
0 commit comments