Skip to content

Commit b8b4455

Browse files
committed
fixup! [WIP] Update the ZGWAPIsConfigurationStep configuration step
1 parent 81e94ac commit b8b4455

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

src/open_inwoner/configurations/bootstrap/utils.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22

3+
from zgw_consumers.models import Service
4+
35
RED = "\033[31m"
46
NORMAL = "\033[0m"
57

@@ -17,3 +19,14 @@ def log_form_errors(config_step, form):
1719
)
1820
for field, errors in form.errors.items():
1921
logger.error("%s : %s" % (field, "; ".join(errors)))
22+
23+
24+
def get_service(slug: str) -> Service:
25+
"""
26+
Try to find a Service and re-raise DoesNotExist with the identifier to make debugging
27+
easier
28+
"""
29+
try:
30+
return Service.objects.get(slug=slug)
31+
except Service.DoesNotExist as e:
32+
raise Service.DoesNotExist(f"{str(e)} (identifier = {slug})")

src/open_inwoner/configurations/bootstrap/zgw.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from django.conf import settings
2-
31
from django_setup_configuration import ConfigurationModel, DjangoModelRef
42
from django_setup_configuration.configuration import BaseConfigurationStep
53
from django_setup_configuration.exceptions import ConfigurationRunFailed
6-
from zgw_consumers.api_models.constants import VertrouwelijkheidsAanduidingen
74
from zgw_consumers.models import Service
85

6+
from open_inwoner.configurations.bootstrap.utils import get_service
97
from open_inwoner.openzaak.models import OpenZaakConfig, ZGWApiGroupConfig
108

119

@@ -51,11 +49,6 @@ class ZGWAPIsConfigurationStep(BaseConfigurationStep):
5149
namespace = "openzaak_config"
5250
config_model = ZGWAPIsConfigurationModel
5351

54-
# def is_configured(self) -> bool:
55-
# """Verify that at least 1 ZGW API set is configured."""
56-
# zgw_config = OpenZaakConfig.get_solo()
57-
# return ZGWApiGroupConfig.objects.filter(open_zaak_config=zgw_config).exists()
58-
5952
def execute(self, model: ZGWAPIsConfigurationModel):
6053
if len(model.api_groups) < 1:
6154
raise ConfigurationRunFailed("Configure at least one `api_groups` item")
@@ -65,19 +58,19 @@ def execute(self, model: ZGWAPIsConfigurationModel):
6558
for api_group in model.api_groups:
6659

6760
try:
68-
zrc_service = Service.objects.get(
69-
slug=api_group.zaken_api_identifier,
61+
zrc_service = get_service(
62+
api_group.zaken_api_identifier,
7063
)
71-
ztc_service = Service.objects.get(
72-
slug=api_group.catalogi_api_identifier,
64+
ztc_service = get_service(
65+
api_group.catalogi_api_identifier,
7366
)
74-
drc_service = Service.objects.get(
75-
slug=api_group.documenten_api_identifier,
67+
drc_service = get_service(
68+
api_group.documenten_api_identifier,
7669
)
7770
# Not required
7871
form_service = (
79-
Service.objects.get(
80-
slug=api_group.form_api_identifier,
72+
get_service(
73+
api_group.form_api_identifier,
8174
)
8275
if api_group.form_api_identifier
8376
else None

src/open_inwoner/configurations/tests/bootstrap/test_setup_zgw_config.py

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
import tempfile
21
from pathlib import Path
32

4-
from django.conf import settings
5-
from django.test import TestCase, override_settings
6-
from django.utils.translation import gettext as _
3+
from django.test import TestCase
74

8-
import requests
9-
import requests_mock
105
from django_setup_configuration.exceptions import (
116
ConfigurationRunFailed,
127
PrerequisiteFailed,
138
)
149
from django_setup_configuration.test_utils import execute_single_step
1510
from privates.test import temp_private_root
16-
from pydantic import ValidationError
17-
from simple_certmanager.constants import CertificateTypes
1811
from zgw_consumers.api_models.constants import VertrouwelijkheidsAanduidingen
1912
from zgw_consumers.constants import APITypes
2013
from zgw_consumers.models import Service
2114

22-
from open_inwoner.openzaak.models import (
23-
OpenZaakConfig,
24-
generate_default_file_extensions,
25-
)
15+
from open_inwoner.configurations.bootstrap.zgw import ZGWAPIsConfigurationStep
16+
from open_inwoner.openzaak.models import OpenZaakConfig
2617
from open_inwoner.openzaak.tests.factories import ServiceFactory
2718

28-
from ...bootstrap.zgw import ZGWAPIsConfigurationStep
29-
3019
ZAAK_SERVICE_API_ROOT = "https://openzaak.local/zaken/api/v1/"
3120
CATALOGI_SERVICE_API_ROOT = "https://openzaak.local/catalogi/api/v1/"
3221
DOCUMENTEN_SERVICE_API_ROOT = "https://openzaak.local/documenten/api/v1/"
3322
FORM_SERVICE_API_ROOT = "https://esuite.local.net/formulieren-provider/api/v1/"
3423

35-
PUBLIC_CERT_FILE = tempfile.NamedTemporaryFile()
36-
PRIVATE_KEY_FILE = tempfile.NamedTemporaryFile()
37-
38-
with open(PUBLIC_CERT_FILE.name, "w") as f:
39-
f.write("cert")
4024

4125
BASE_DIR = Path(__file__).parent / "files"
4226
ZGW_API_STEP_YAML_FULL = str(BASE_DIR / "zgw_api_step_full.yaml")

0 commit comments

Comments
 (0)