|
6 | 6 | from textwrap import dedent
|
7 | 7 | from unittest.mock import patch
|
8 | 8 |
|
9 |
| -from django.core.management import call_command |
| 9 | +from django.core.management import CommandError, call_command |
10 | 10 | from django.test import TestCase, override_settings, tag
|
11 | 11 | from django.utils import translation
|
12 | 12 |
|
|
22 | 22 | from openforms.payments.contrib.ogone.tests.factories import OgoneMerchantFactory
|
23 | 23 | from openforms.products.tests.factories import ProductFactory
|
24 | 24 | from openforms.registrations.contrib.objects_api.models import ObjectsAPIGroupConfig
|
| 25 | +from openforms.registrations.contrib.zgw_apis.tests.factories import ( |
| 26 | + ZGWApiGroupConfigFactory, |
| 27 | +) |
25 | 28 | from openforms.translations.tests.utils import make_translated
|
26 | 29 | from openforms.utils.tests.vcr import OFVCRMixin
|
27 | 30 | from openforms.variables.constants import FormVariableSources
|
@@ -1521,3 +1524,106 @@ def test_import_form_with_objecttype_uuid_objects_api_registration_backend(self)
|
1521 | 1524 | registration_backend.options["objecttype"],
|
1522 | 1525 | "8e46e0a5-b1b4-449b-b9e9-fa3cea655f48",
|
1523 | 1526 | )
|
| 1527 | + |
| 1528 | + |
| 1529 | +class ImportZGWAPITests(TempdirMixin, OFVCRMixin, TestCase): |
| 1530 | + """This test case requires the Open Zaak Docker Compose to be running. |
| 1531 | +
|
| 1532 | + See the relevant Docker compose in the ``docker/`` folder. |
| 1533 | + """ |
| 1534 | + |
| 1535 | + VCR_TEST_FILES = PATH / "files" |
| 1536 | + |
| 1537 | + def test_import_form_with_zgw_registration_backend_no_available_group(self): |
| 1538 | + |
| 1539 | + resources = { |
| 1540 | + "forms": [ |
| 1541 | + { |
| 1542 | + "active": True, |
| 1543 | + "name": "Test Form 1", |
| 1544 | + "internal_name": "Test Form Internal 1", |
| 1545 | + "slug": "zgw-no-group", |
| 1546 | + "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", |
| 1547 | + "registration_backends": [ |
| 1548 | + { |
| 1549 | + "key": "test-backend", |
| 1550 | + "name": "Test backend", |
| 1551 | + "backend": "zgw-create-zaak", |
| 1552 | + "options": { |
| 1553 | + "zaaktype": "https://catalogi.nl/api/v1/zaaktypen/1", |
| 1554 | + "informatieobjecttype": "https://catalogi.nl/api/v1/informatieobjecttypen/1", |
| 1555 | + }, |
| 1556 | + } |
| 1557 | + ], |
| 1558 | + } |
| 1559 | + ] |
| 1560 | + } |
| 1561 | + |
| 1562 | + with zipfile.ZipFile(self.filepath, "w") as zip_file: |
| 1563 | + for name, data in resources.items(): |
| 1564 | + zip_file.writestr(f"{name}.json", json.dumps(data)) |
| 1565 | + |
| 1566 | + with self.assertRaises(CommandError): |
| 1567 | + call_command("import", import_file=self.filepath) |
| 1568 | + |
| 1569 | + def test_import_form_with_zgw_registration_backend_available_group(self): |
| 1570 | + resources = { |
| 1571 | + "forms": [ |
| 1572 | + { |
| 1573 | + "active": True, |
| 1574 | + "name": "Test Form 1", |
| 1575 | + "internal_name": "Test Form Internal 1", |
| 1576 | + "slug": "zgw-no-group", |
| 1577 | + "uuid": "324cadce-a627-4e3f-b117-37ca232f16b2", |
| 1578 | + "registration_backends": [ |
| 1579 | + { |
| 1580 | + "key": "test-backend", |
| 1581 | + "name": "Test backend", |
| 1582 | + "backend": "zgw-create-zaak", |
| 1583 | + "options": { |
| 1584 | + "zaaktype": "http://localhost:8003/catalogi/api/v1/zaaktypen/1f41885e-23fc-4462-bbc8-80be4ae484dc", |
| 1585 | + "informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7", |
| 1586 | + }, |
| 1587 | + } |
| 1588 | + ], |
| 1589 | + } |
| 1590 | + ] |
| 1591 | + } |
| 1592 | + |
| 1593 | + _credentials = { |
| 1594 | + "auth_type": AuthTypes.zgw, |
| 1595 | + "client_id": "test_client_id", |
| 1596 | + "secret": "test_secret_key", |
| 1597 | + } |
| 1598 | + zaken_service = ServiceFactory.create( |
| 1599 | + api_root="http://localhost:8003/zaken/api/v1/", |
| 1600 | + api_type=APITypes.zrc, |
| 1601 | + **_credentials, |
| 1602 | + ) |
| 1603 | + documenten_service = ServiceFactory.create( |
| 1604 | + api_root="http://localhost:8003/documenten/api/v1/", |
| 1605 | + api_type=APITypes.drc, |
| 1606 | + **_credentials, |
| 1607 | + ) |
| 1608 | + catalogi_service = ServiceFactory.create( |
| 1609 | + api_root="http://localhost:8003/catalogi/api/v1/", |
| 1610 | + api_type=APITypes.ztc, |
| 1611 | + **_credentials, |
| 1612 | + ) |
| 1613 | + zgw_group = ZGWApiGroupConfigFactory.create( |
| 1614 | + zrc_service=zaken_service, |
| 1615 | + drc_service=documenten_service, |
| 1616 | + ztc_service=catalogi_service, |
| 1617 | + ) |
| 1618 | + |
| 1619 | + with zipfile.ZipFile(self.filepath, "w") as zip_file: |
| 1620 | + for name, data in resources.items(): |
| 1621 | + zip_file.writestr(f"{name}.json", json.dumps(data)) |
| 1622 | + |
| 1623 | + call_command("import", import_file=self.filepath) |
| 1624 | + |
| 1625 | + registration_backend = FormRegistrationBackend.objects.get(key="test-backend") |
| 1626 | + self.assertEqual( |
| 1627 | + registration_backend.options["zgw_api_group"], |
| 1628 | + zgw_group.pk, |
| 1629 | + ) |
0 commit comments