diff --git a/backend/src/openarchiefbeheer/config/tests/test_views.py b/backend/src/openarchiefbeheer/config/tests/test_views.py index 35d60c4d..6c1132ce 100644 --- a/backend/src/openarchiefbeheer/config/tests/test_views.py +++ b/backend/src/openarchiefbeheer/config/tests/test_views.py @@ -41,7 +41,14 @@ def test_record_manager_update(self): self.client.force_login(user) response = self.client.put( reverse("api:archive-config"), - data={"zaaktypesShortProcess": ["http://tralala.nl"]}, + data={ + "zaaktypesShortProcess": ["http://tralala.nl"], + "bronorganisatie": "000000000", + "zaaktype": "http://bla.nl", + "statustype": "http://bla.nl", + "resultaattype": "http://bla.nl", + "informatieobjecttype": "http://bla.nl", + }, ) self.assertEqual(response.status_code, status.HTTP_200_OK) diff --git a/backend/src/openarchiefbeheer/zaken/tests/test_views.py b/backend/src/openarchiefbeheer/zaken/tests/test_views.py index c44e9ad7..82770880 100644 --- a/backend/src/openarchiefbeheer/zaken/tests/test_views.py +++ b/backend/src/openarchiefbeheer/zaken/tests/test_views.py @@ -21,6 +21,7 @@ DestructionListItemReviewFactory, DestructionListReviewFactory, ) +from openarchiefbeheer.zaken.utils import retrieve_paginated_type from ..tasks import retrieve_and_cache_zaken_from_openzaak from .factories import ZaakFactory @@ -634,3 +635,291 @@ def test_response_cached(self, m): self.client.get(endpoint.url) self.assertEqual(len(m.request_history), 1) + + +class ResultaattypenChoicesViewTests(APITestCase): + def setUp(self): + super().setUp() + + self.addCleanup(cache.clear) + self.addCleanup(retrieve_paginated_type.cache_clear) + + def test_not_authenticated(self): + endpoint = reverse("api:retrieve-resultaattype-choices") + + response = self.client.get(endpoint) + + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + @Mocker() + def test_retrieve_choices(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/resultaattypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/resultaattypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/resultaattypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-resultaattype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + response.json(), + [ + { + "value": "http://oz.nl/api/v1/resultaattypen/111-111-111", + "label": "Blabla 1", + }, + { + "value": "http://oz.nl/api/v1/resultaattypen/222-222-222", + "label": "http://oz.nl/api/v1/resultaattypen/222-222-222", + }, + ], + ) + + @Mocker() + def test_retrieve_choices_caches_request(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/resultaattypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/resultaattypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/resultaattypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-resultaattype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Repeat request + response = self.client.get(reverse("api:retrieve-resultaattype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Only one call to openzaak + self.assertEqual(len(m.request_history), 1) + + +class InformatieobjecttypenChoicesViewTests(APITestCase): + def setUp(self): + super().setUp() + + self.addCleanup(cache.clear) + self.addCleanup(retrieve_paginated_type.cache_clear) + + def test_not_authenticated(self): + endpoint = reverse("api:retrieve-informatieobjecttype-choices") + + response = self.client.get(endpoint) + + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + @Mocker() + def test_retrieve_choices(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/informatieobjecttypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-informatieobjecttype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + response.json(), + [ + { + "value": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111", + "label": "Blabla 1", + }, + { + "value": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222", + "label": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222", + }, + ], + ) + + @Mocker() + def test_retrieve_choices_caches_request(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/informatieobjecttypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/informatieobjecttypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/informatieobjecttypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-informatieobjecttype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Repeat request + response = self.client.get(reverse("api:retrieve-informatieobjecttype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Only one call to openzaak + self.assertEqual(len(m.request_history), 1) + + +class StatustypenChoicesViewTests(APITestCase): + def setUp(self): + super().setUp() + + self.addCleanup(cache.clear) + self.addCleanup(retrieve_paginated_type.cache_clear) + + def test_not_authenticated(self): + endpoint = reverse("api:retrieve-statustype-choices") + + response = self.client.get(endpoint) + + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + @Mocker() + def test_retrieve_choices(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/statustypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/statustypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/statustypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-statustype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual( + response.json(), + [ + { + "value": "http://oz.nl/api/v1/statustypen/111-111-111", + "label": "Blabla 1", + }, + { + "value": "http://oz.nl/api/v1/statustypen/222-222-222", + "label": "http://oz.nl/api/v1/statustypen/222-222-222", + }, + ], + ) + + @Mocker() + def test_retrieve_choices_caches_request(self, m): + ServiceFactory.create( + api_type=APITypes.ztc, + api_root="http://oz.nl/api/v1", + ) + user = UserFactory.create() + + m.get( + "http://oz.nl/api/v1/statustypen", + json={ + "count": 2, + "results": [ + { + "url": "http://oz.nl/api/v1/statustypen/111-111-111", + "omschrijving": "Blabla 1", + }, + { + "url": "http://oz.nl/api/v1/statustypen/222-222-222", + "omschrijving": "", + }, + ], + }, + ) + + self.client.force_authenticate(user=user) + response = self.client.get(reverse("api:retrieve-statustype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Repeat request + response = self.client.get(reverse("api:retrieve-statustype-choices")) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + # Only one call to openzaak + self.assertEqual(len(m.request_history), 1)