|
21 | 21 | DestructionListReviewFactory,
|
22 | 22 | )
|
23 | 23 | from openarchiefbeheer.utils.tests.mixins import ClearCacheMixin
|
24 |
| -from openarchiefbeheer.zaken.utils import retrieve_paginated_type |
25 | 24 |
|
26 | 25 | from ..tasks import retrieve_and_cache_zaken_from_openzaak
|
| 26 | +from ..utils import retrieve_paginated_type, retrieve_selectielijstklasse_choices |
27 | 27 | from .factories import ZaakFactory
|
28 | 28 |
|
29 | 29 |
|
@@ -655,6 +655,214 @@ def test_response_cached(self, m):
|
655 | 655 | self.assertEqual(len(m.request_history), 1)
|
656 | 656 |
|
657 | 657 |
|
| 658 | +class InternalSelectielijstklasseChoicesViewTests(ClearCacheMixin, APITestCase): |
| 659 | + def setUp(self): |
| 660 | + super().setUp() |
| 661 | + |
| 662 | + retrieve_selectielijstklasse_choices.cache_clear() |
| 663 | + |
| 664 | + self.addCleanup(retrieve_selectielijstklasse_choices.cache_clear) |
| 665 | + |
| 666 | + def test_not_authenticated(self): |
| 667 | + endpoint = reverse("api:retrieve-internal-selectielijstklasse-choices") |
| 668 | + |
| 669 | + response = self.client.get(endpoint) |
| 670 | + |
| 671 | + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) |
| 672 | + |
| 673 | + @Mocker() |
| 674 | + def test_retrieve_internal_choices(self, m): |
| 675 | + """ |
| 676 | + Test that only the selectielijstklassen of the zaken in the database are returned. |
| 677 | +
|
| 678 | + We have: |
| 679 | +
|
| 680 | + - A zaak with selectielijstklasse specified on the zaak |
| 681 | + - A zaak with selectielijstklasse derived from resultaat -> resultaattype -> selectielijstklasse |
| 682 | + - A zaak without selectielijstklasse |
| 683 | +
|
| 684 | + We mock the selectielijstklasse API endpoint to return 3 resultaten, two of which are referenced in the zaken |
| 685 | + in the db. So the internal selectielijstklasse choices endpoint should only return 2 choices. |
| 686 | + """ |
| 687 | + selectielist_service = ServiceFactory.create( |
| 688 | + api_type=APITypes.orc, |
| 689 | + api_root="http://selectielijst.nl/api/v1", |
| 690 | + ) |
| 691 | + user = UserFactory.create(post__can_start_destruction=True) |
| 692 | + ZaakFactory.create( |
| 693 | + selectielijstklasse="http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 694 | + post___expand={ |
| 695 | + "resultaat": { |
| 696 | + "url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3", |
| 697 | + "uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3", |
| 698 | + "_expand": { |
| 699 | + "resultaattype": { |
| 700 | + "url": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111", |
| 701 | + "omschrijving": "Afgehandeld", |
| 702 | + "selectielijstklasse": "http://selectielijst.nl/api/v1/resultaten/2e86a8ca-0269-446c-8da2-6f4d08be422d", |
| 703 | + } |
| 704 | + }, |
| 705 | + "toelichting": "Testing resultaten", |
| 706 | + "resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/111-111-111", |
| 707 | + } |
| 708 | + }, |
| 709 | + ) |
| 710 | + ZaakFactory.create( |
| 711 | + selectielijstklasse="", |
| 712 | + post___expand={ |
| 713 | + "resultaat": { |
| 714 | + "url": "http://localhost:8003/zaken/api/v1/resultaten/821b4d8f-3244-4ece-8d33-791fa6d2a2f3", |
| 715 | + "uuid": "821b4d8f-3244-4ece-8d33-791fa6d2a2f3", |
| 716 | + "_expand": { |
| 717 | + "resultaattype": { |
| 718 | + "url": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222", |
| 719 | + "omschrijving": "Lopend", |
| 720 | + "selectielijstklasse": "http://selectielijst.nl/api/v1/resultaten/5d102cc6-4a74-4262-a14a-538bbfe3f2da", |
| 721 | + } |
| 722 | + }, |
| 723 | + "toelichting": "Testing resultaten", |
| 724 | + "resultaattype": "http://localhost:8003/catalogi/api/v1/resultaattypen/222-222-222", |
| 725 | + } |
| 726 | + }, |
| 727 | + ) |
| 728 | + ZaakFactory.create(selectielijstklasse="", post___expand={}) |
| 729 | + |
| 730 | + m.get( |
| 731 | + "http://selectielijst.nl/api/v1/resultaten", |
| 732 | + json={ |
| 733 | + "count": 3, |
| 734 | + "results": [ |
| 735 | + { |
| 736 | + "url": "http://selectielijst.nl/api/v1/resultaten/2e86a8ca-0269-446c-8da2-6f4d08be422d", |
| 737 | + "nummer": 1, |
| 738 | + "volledigNummer": "11.1", |
| 739 | + "naam": "Verleend", |
| 740 | + "waardering": "vernietigen", |
| 741 | + "bewaartermijn": "P1Y", |
| 742 | + }, |
| 743 | + { |
| 744 | + "url": "http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 745 | + "nummer": 1, |
| 746 | + "naam": "Verleend", |
| 747 | + "waardering": "vernietigen", |
| 748 | + "bewaartermijn": "P2Y", |
| 749 | + }, |
| 750 | + { |
| 751 | + "url": "http://selectielijst.nl/api/v1/resultaten/5d102cc6-4a74-4262-a14a-538bbfe3f2da", |
| 752 | + "nummer": 2, |
| 753 | + "volledigNummer": "11.1.2", |
| 754 | + "naam": "Verleend", |
| 755 | + "waardering": "vernietigen", |
| 756 | + }, |
| 757 | + ], |
| 758 | + }, |
| 759 | + ) |
| 760 | + |
| 761 | + self.client.force_authenticate(user=user) |
| 762 | + endpoint = furl(reverse("api:retrieve-internal-selectielijstklasse-choices")) |
| 763 | + |
| 764 | + with patch( |
| 765 | + "openarchiefbeheer.zaken.utils.APIConfig.get_solo", |
| 766 | + return_value=APIConfig(selectielijst_api_service=selectielist_service), |
| 767 | + ): |
| 768 | + response = self.client.get(endpoint.url) |
| 769 | + |
| 770 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 771 | + self.assertEqual( |
| 772 | + response.json(), |
| 773 | + [ |
| 774 | + { |
| 775 | + "value": "http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 776 | + "label": "1 - Verleend - vernietigen - P2Y", |
| 777 | + "extraData": { |
| 778 | + "bewaartermijn": "P2Y", |
| 779 | + }, |
| 780 | + }, |
| 781 | + { |
| 782 | + "value": "http://selectielijst.nl/api/v1/resultaten/5d102cc6-4a74-4262-a14a-538bbfe3f2da", |
| 783 | + "label": "11.1.2 - Verleend - vernietigen", |
| 784 | + "extraData": { |
| 785 | + "bewaartermijn": None, |
| 786 | + }, |
| 787 | + }, |
| 788 | + ], |
| 789 | + ) |
| 790 | + |
| 791 | + @Mocker() |
| 792 | + def test_retrieve_internal_choices_with_filters(self, m): |
| 793 | + """ |
| 794 | + Test that only the selectielijstklassen of the filtered zaken in the database are returned. |
| 795 | + """ |
| 796 | + selectielist_service = ServiceFactory.create( |
| 797 | + api_type=APITypes.orc, |
| 798 | + api_root="http://selectielijst.nl/api/v1", |
| 799 | + ) |
| 800 | + user = UserFactory.create(post__can_start_destruction=True) |
| 801 | + ZaakFactory.create( |
| 802 | + identificatie="ZAAK-1", |
| 803 | + selectielijstklasse="http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 804 | + ) |
| 805 | + ZaakFactory.create( |
| 806 | + identificatie="ZAAK-2", |
| 807 | + selectielijstklasse="http://selectielijst.nl/api/v1/resultaten/2e86a8ca-0269-446c-8da2-6f4d08be422d", |
| 808 | + ) |
| 809 | + |
| 810 | + m.get( |
| 811 | + "http://selectielijst.nl/api/v1/resultaten", |
| 812 | + json={ |
| 813 | + "count": 3, |
| 814 | + "results": [ |
| 815 | + { |
| 816 | + "url": "http://selectielijst.nl/api/v1/resultaten/2e86a8ca-0269-446c-8da2-6f4d08be422d", |
| 817 | + "nummer": 1, |
| 818 | + "volledigNummer": "11.1", |
| 819 | + "naam": "Verleend", |
| 820 | + "waardering": "vernietigen", |
| 821 | + "bewaartermijn": "P1Y", |
| 822 | + }, |
| 823 | + { |
| 824 | + "url": "http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 825 | + "nummer": 1, |
| 826 | + "naam": "Verleend", |
| 827 | + "waardering": "vernietigen", |
| 828 | + "bewaartermijn": "P2Y", |
| 829 | + }, |
| 830 | + { |
| 831 | + "url": "http://selectielijst.nl/api/v1/resultaten/5d102cc6-4a74-4262-a14a-538bbfe3f2da", |
| 832 | + "nummer": 2, |
| 833 | + "volledigNummer": "11.1.2", |
| 834 | + "naam": "Verleend", |
| 835 | + "waardering": "vernietigen", |
| 836 | + }, |
| 837 | + ], |
| 838 | + }, |
| 839 | + ) |
| 840 | + |
| 841 | + self.client.force_authenticate(user=user) |
| 842 | + endpoint = furl(reverse("api:retrieve-internal-selectielijstklasse-choices")) |
| 843 | + endpoint.args["identificatie"] = "ZAAK-1" |
| 844 | + |
| 845 | + with patch( |
| 846 | + "openarchiefbeheer.zaken.utils.APIConfig.get_solo", |
| 847 | + return_value=APIConfig(selectielijst_api_service=selectielist_service), |
| 848 | + ): |
| 849 | + response = self.client.get(endpoint.url) |
| 850 | + |
| 851 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 852 | + self.assertEqual( |
| 853 | + response.json(), |
| 854 | + [ |
| 855 | + { |
| 856 | + "value": "http://selectielijst.nl/api/v1/resultaten/5038528b-0eb7-4502-a415-a3093987d69b", |
| 857 | + "label": "1 - Verleend - vernietigen - P2Y", |
| 858 | + "extraData": { |
| 859 | + "bewaartermijn": "P2Y", |
| 860 | + }, |
| 861 | + } |
| 862 | + ], |
| 863 | + ) |
| 864 | + |
| 865 | + |
658 | 866 | class ResultaattypenChoicesViewTests(ClearCacheMixin, APITestCase):
|
659 | 867 | def setUp(self):
|
660 | 868 | super().setUp()
|
|
0 commit comments