diff --git a/src/openforms/forms/tests/files/vcr_cassettes/ImportZGWAPITests/ImportZGWAPITests.test_import_form_with_zgw_registration_backend_cant_determine_objects_api_group.yaml b/src/openforms/forms/tests/files/vcr_cassettes/ImportZGWAPITests/ImportZGWAPITests.test_import_form_with_zgw_registration_backend_cant_determine_objects_api_group.yaml new file mode 100644 index 0000000000..565e1ba882 --- /dev/null +++ b/src/openforms/forms/tests/files/vcr_cassettes/ImportZGWAPITests/ImportZGWAPITests.test_import_form_with_zgw_registration_backend_cant_determine_objects_api_group.yaml @@ -0,0 +1,176 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTczMTcwMjAzNywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.A8XMplId4rR330Oj1ruGK-9HVMz2m9guLm-G7TNb20s + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: GET + uri: http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc + response: + body: + string: '{"url":"http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","identificatie":"ZT-001","omschrijving":"Test","omschrijvingGeneriek":"","vertrouwelijkheidaanduiding":"intern","doel":"testen","aanleiding":"integratietests","toelichting":"","indicatieInternOfExtern":"intern","handelingInitiator":"Formulier + indienen","onderwerp":"Testformulier","handelingBehandelaar":"Controleren","doorlooptijd":"P1D","servicenorm":null,"opschortingEnAanhoudingMogelijk":false,"verlengingMogelijk":false,"verlengingstermijn":null,"trefwoorden":[],"publicatieIndicatie":false,"publicatietekst":"","verantwoordingsrelatie":[],"productenOfDiensten":[],"selectielijstProcestype":"https://selectielijst.openzaak.nl/api/v1/procestypen/aa8aa2fd-b9c6-4e34-9a6c-58a677f60ea0","referentieproces":{"naam":"Testen","link":""},"concept":false,"verantwoordelijke":"Ontwikkelaar","beginGeldigheid":"2024-03-26","eindeGeldigheid":null,"versiedatum":"2024-03-26","beginObject":"2023-01-01","eindeObject":null,"catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","statustypen":["http://localhost:8003/catalogi/api/v1/statustypen/1de05b57-a938-47e4-b808-f129c6406b60","http://localhost:8003/catalogi/api/v1/statustypen/6443ac1a-04a1-4335-9db2-5f3c998dbb34"],"resultaattypen":["http://localhost:8003/catalogi/api/v1/resultaattypen/65b7cedd-5729-41bd-b9c7-1f51d7583340"],"eigenschappen":["http://localhost:8003/catalogi/api/v1/eigenschappen/b659caed-e39e-47e3-ac51-bc8bd2ad797e"],"informatieobjecttypen":["http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7"],"roltypen":["http://localhost:8003/catalogi/api/v1/roltypen/43e8026c-8abd-4b29-8a4c-ac2a37bc6f5b","http://localhost:8003/catalogi/api/v1/roltypen/7f1887e8-bf22-47e7-ae52-ed6848d7e70e"],"besluittypen":[],"deelzaaktypen":[],"gerelateerdeZaaktypen":[],"zaakobjecttypen":[]}' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '1918' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"4b7814375796d28f29fea94ee27127b8"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTczMTcwMjAzNywiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.A8XMplId4rR330Oj1ruGK-9HVMz2m9guLm-G7TNb20s + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: GET + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7 + response: + body: + string: '{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment + Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test + category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","http://localhost:8003/catalogi/api/v1/zaaktypen/b79d9c2f-5ec4-4e23-bb66-ec6dd959a400"],"beginObject":"2024-03-19","eindeObject":"2024-07-10"}' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '986' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"9b92accfbfdb5c0d2c8d040a5825abfd"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTczMTcwMjAzOCwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.iI2goeNIs-W9S6ITpjRxFlq2trxwCc87bRoynekCz4c + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: GET + uri: http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc + response: + body: + string: '{"url":"http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","identificatie":"ZT-001","omschrijving":"Test","omschrijvingGeneriek":"","vertrouwelijkheidaanduiding":"intern","doel":"testen","aanleiding":"integratietests","toelichting":"","indicatieInternOfExtern":"intern","handelingInitiator":"Formulier + indienen","onderwerp":"Testformulier","handelingBehandelaar":"Controleren","doorlooptijd":"P1D","servicenorm":null,"opschortingEnAanhoudingMogelijk":false,"verlengingMogelijk":false,"verlengingstermijn":null,"trefwoorden":[],"publicatieIndicatie":false,"publicatietekst":"","verantwoordingsrelatie":[],"productenOfDiensten":[],"selectielijstProcestype":"https://selectielijst.openzaak.nl/api/v1/procestypen/aa8aa2fd-b9c6-4e34-9a6c-58a677f60ea0","referentieproces":{"naam":"Testen","link":""},"concept":false,"verantwoordelijke":"Ontwikkelaar","beginGeldigheid":"2024-03-26","eindeGeldigheid":null,"versiedatum":"2024-03-26","beginObject":"2023-01-01","eindeObject":null,"catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","statustypen":["http://localhost:8003/catalogi/api/v1/statustypen/1de05b57-a938-47e4-b808-f129c6406b60","http://localhost:8003/catalogi/api/v1/statustypen/6443ac1a-04a1-4335-9db2-5f3c998dbb34"],"resultaattypen":["http://localhost:8003/catalogi/api/v1/resultaattypen/65b7cedd-5729-41bd-b9c7-1f51d7583340"],"eigenschappen":["http://localhost:8003/catalogi/api/v1/eigenschappen/b659caed-e39e-47e3-ac51-bc8bd2ad797e"],"informatieobjecttypen":["http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7"],"roltypen":["http://localhost:8003/catalogi/api/v1/roltypen/43e8026c-8abd-4b29-8a4c-ac2a37bc6f5b","http://localhost:8003/catalogi/api/v1/roltypen/7f1887e8-bf22-47e7-ae52-ed6848d7e70e"],"besluittypen":[],"deelzaaktypen":[],"gerelateerdeZaaktypen":[],"zaakobjecttypen":[]}' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '1918' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"4b7814375796d28f29fea94ee27127b8"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate, br + Authorization: + - Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTczMTcwMjAzOCwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.iI2goeNIs-W9S6ITpjRxFlq2trxwCc87bRoynekCz4c + Connection: + - keep-alive + User-Agent: + - python-requests/2.32.2 + method: GET + uri: http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7 + response: + body: + string: '{"url":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","catalogus":"http://localhost:8003/catalogi/api/v1/catalogussen/bd58635c-793e-446d-a7e0-460d7b04829d","omschrijving":"Attachment + Informatieobjecttype","vertrouwelijkheidaanduiding":"openbaar","beginGeldigheid":"2024-03-19","eindeGeldigheid":"2024-07-10","concept":false,"besluittypen":[],"informatieobjectcategorie":"Test + category","trefwoord":[],"omschrijvingGeneriek":{"informatieobjecttypeOmschrijvingGeneriek":"","definitieInformatieobjecttypeOmschrijvingGeneriek":"","herkomstInformatieobjecttypeOmschrijvingGeneriek":"","hierarchieInformatieobjecttypeOmschrijvingGeneriek":"","opmerkingInformatieobjecttypeOmschrijvingGeneriek":""},"zaaktypen":["http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc","http://localhost:8003/catalogi/api/v1/zaaktypen/b79d9c2f-5ec4-4e23-bb66-ec6dd959a400"],"beginObject":"2024-03-19","eindeObject":"2024-07-10"}' + headers: + API-version: + - 1.3.1 + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Length: + - '986' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + ETag: + - '"9b92accfbfdb5c0d2c8d040a5825abfd"' + Referrer-Policy: + - same-origin + Vary: + - Accept, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +version: 1 diff --git a/src/openforms/forms/tests/test_import_export.py b/src/openforms/forms/tests/test_import_export.py index 8b655722e7..0722b2578e 100644 --- a/src/openforms/forms/tests/test_import_export.py +++ b/src/openforms/forms/tests/test_import_export.py @@ -1610,35 +1610,39 @@ class ImportZGWAPITests(TempdirMixin, OFVCRMixin, TestCase): VCR_TEST_FILES = PATH / "files" - def test_import_form_with_zgw_registration_backend_no_available_group(self): - + @staticmethod + def _create_export(filepath: Path, *backends: dict): resources = { "forms": [ { "active": True, "name": "Test Form 1", "internal_name": "Test Form Internal 1", - "slug": "zgw-no-group", + "slug": "zgw-group", "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", - "registration_backends": [ - { - "key": "test-backend", - "name": "Test backend", - "backend": "zgw-create-zaak", - "options": { - "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", - "informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1", - }, - } - ], + "registration_backends": list(backends), } ] } - with zipfile.ZipFile(self.filepath, "w") as zip_file: + with zipfile.ZipFile(filepath, "w") as zip_file: for name, data in resources.items(): zip_file.writestr(f"{name}.json", json.dumps(data)) + def test_import_form_with_zgw_registration_backend_no_available_group(self): + self._create_export( + self.filepath, + { + "key": "test-backend", + "name": "Test backend", + "backend": "zgw-create-zaak", + "options": { + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", + "informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1", + }, + }, + ) + with self.assertRaises(CommandError) as exc: call_command("import", import_file=self.filepath) @@ -1648,34 +1652,19 @@ def test_import_form_with_zgw_registration_backend_no_available_group(self): self.assertEqual(error_detail.code, "invalid") def test_import_form_with_zgw_registration_backend_available_group(self): - resources = { - "forms": [ - { - "active": True, - "name": "Test Form 1", - "internal_name": "Test Form Internal 1", - "slug": "zgw-group", - "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", - "registration_backends": [ - { - "key": "test-backend", - "name": "Test backend", - "backend": "zgw-create-zaak", - "options": { - "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", - "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", - }, - } - ], - } - ] - } - zgw_group = ZGWApiGroupConfigFactory.create(for_test_docker_compose=True) - - with zipfile.ZipFile(self.filepath, "w") as zip_file: - for name, data in resources.items(): - zip_file.writestr(f"{name}.json", json.dumps(data)) + self._create_export( + self.filepath, + { + "key": "test-backend", + "name": "Test backend", + "backend": "zgw-create-zaak", + "options": { + "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", + "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", + }, + }, + ) call_command("import", import_file=self.filepath) @@ -1694,40 +1683,24 @@ def test_import_form_with_zgw_registration_backend_with_objects_api_group_apply_ `options.objects_api_group` has now been made required, this should be injected into the import data to make sure the import still works """ - resources = { - "forms": [ - { - "active": True, - "name": "Test Form 1", - "internal_name": "Test Form Internal 1", - "slug": "zgw-group", - "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", - "registration_backends": [ - { - "key": "test-backend", - "name": "Test backend", - "backend": "zgw-create-zaak", - "options": { - "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", - "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", - "version": 2, - "objecttype": "http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", - "objecttype_version": 1, - }, - } - ], - } - ] - } - objects_api_group = ObjectsAPIGroupConfigFactory.create( for_test_docker_compose=True ) ZGWApiGroupConfigFactory.create(for_test_docker_compose=True) - - with zipfile.ZipFile(self.filepath, "w") as zip_file: - for name, data in resources.items(): - zip_file.writestr(f"{name}.json", json.dumps(data)) + self._create_export( + self.filepath, + { + "key": "test-backend", + "name": "Test backend", + "backend": "zgw-create-zaak", + "options": { + "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", + "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", + "objecttype": "http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "objecttype_version": 1, + }, + }, + ) call_command("import", import_file=self.filepath) @@ -1737,6 +1710,67 @@ def test_import_form_with_zgw_registration_backend_with_objects_api_group_apply_ objects_api_group.pk, ) + def test_import_form_with_zgw_registration_backend_cant_determine_objects_api_group( + self, + ): + zgw_group = ZGWApiGroupConfigFactory.create(for_test_docker_compose=True) + + with self.subTest("no default group exists"): + self._create_export( + self.filepath, + { + "key": "test-backend", + "name": "Test backend", + "backend": "zgw-create-zaak", + "options": { + "zgw_api_group": zgw_group.pk, + "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", + "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", + "objecttype": "http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "objecttype_version": 1, + }, + }, + ) + + with self.assertRaises(CommandError) as exc: + call_command("import", import_file=self.filepath) + + error_detail = exc.exception.args[0].detail["registration_backends"][0][ + "options" + ]["objects_api_group"][0] + self.assertEqual(error_detail.code, "required") + + with self.subTest("objects API group present in export"): + objects_api_group = ObjectsAPIGroupConfigFactory.create( + for_test_docker_compose=True + ) + self._create_export( + self.filepath, + { + "key": "test-backend", + "name": "Test backend", + "backend": "zgw-create-zaak", + "options": { + "zgw_api_group": zgw_group.pk, + "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", + "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", + "objects_api_group": objects_api_group.pk, + "objecttype": "http://localhost:8001/api/v2/objecttypes/8e46e0a5-b1b4-449b-b9e9-fa3cea655f48", + "objecttype_version": 1, + }, + }, + ) + + call_command("import", import_file=self.filepath) + + registration_backend = FormRegistrationBackend.objects.get( + key="test-backend" + ) + self.assertEqual( + registration_backend.options["objects_api_group"], + objects_api_group.pk, + ) + class ImportStUFZDSTests(TempdirMixin, TestCase): def test_extension_plugin_id_is_converted(self):