Skip to content

Commit

Permalink
[#2966] Add django-setup-configuration step for KlantenSysteemConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schilling committed Jan 21, 2025
1 parent 390ba0a commit 913b67a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
27 changes: 22 additions & 5 deletions src/open_inwoner/configurations/bootstrap/openklant.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Meta:
}


class KlantSysteemConfigurationModel(ConfigurationModel):
class KlantenSysteemConfigurationModel(ConfigurationModel):
class Meta:
django_model_refs = {
KlantenSysteemConfig: (
Expand Down Expand Up @@ -154,8 +154,25 @@ def execute(self, model: OpenKlant2Configuration):
config.save()


# TODO: complete config step
class KlantSysteemConfigurationStep(
BaseConfigurationStep[KlantSysteemConfigurationModel]
class KlantenSysteemConfigurationStep(
BaseConfigurationStep[KlantenSysteemConfigurationModel]
):
pass
"""
Configure the KlantenSysteem settings
"""

verbose_name = "KlantenSysteem configuration"
enable_setting = "klantensysteem_config_enable"
namespace = "klantensysteem_config"
config_model = KlantenSysteemConfigurationModel

def execute(self, model: KlantenApiConfigurationModel):
create_or_update_kwargs = model.model_dump()

config = KlantenSysteemConfig.get_solo()

for key, val in create_or_update_kwargs.items():
setattr(config, key, val)

config.full_clean()
config.save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
klantensysteem_config_enable: true
klantensysteem_config:
primary_backend: esuite
register_contact_via_api: true
register_contact_email: "[email protected]"
send_email_confirmation: true
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from pathlib import Path

from django.core.exceptions import ValidationError
from django.test import TestCase

from django_setup_configuration.exceptions import ConfigurationRunFailed
from django_setup_configuration.test_utils import execute_single_step
from zgw_consumers.constants import APITypes

from open_inwoner.openklant.models import ESuiteKlantConfig, OpenKlant2Config
from open_inwoner.openklant.constants import KlantenServiceType
from open_inwoner.openklant.models import (
ESuiteKlantConfig,
KlantenSysteemConfig,
OpenKlant2Config,
)
from open_inwoner.openzaak.tests.factories import ServiceFactory

from ...bootstrap.openklant import (
ESuiteKlantConfigurationStep,
KlantenSysteemConfigurationStep,
OpenKlant2ConfigurationStep,
)

Expand All @@ -19,6 +26,9 @@

BASE_DIR = Path(__file__).parent / "files"
ESUITEKLANT_CONFIG_STEP_FULL_YAML = str(BASE_DIR / "esuiteklant_config_step_full.yaml")
KLANTENSYSTEEM_CONFIG_STEP_FULL_YAML = str(
BASE_DIR / "klantensysteem_config_step_full.yaml"
)
OPENKLANT2_CONFIG_STEP_FULL_YAML = str(BASE_DIR / "openklant2_config_step_full.yaml")


Expand Down Expand Up @@ -147,8 +157,6 @@ def assert_values():
self.assertEqual(config.klanten_service, kc)
self.assertEqual(config.contactmomenten_service, cmc)

# self.assertEqual(config.register_email, "[email protected]")
# self.assertEqual(config.register_contact_moment, True)
self.assertEqual(config.register_bronorganisatie_rsin, "837194569")
self.assertEqual(config.register_channel, "email")
self.assertEqual(config.register_type, "bericht")
Expand All @@ -162,8 +170,6 @@ def assert_values():
assert_values()

config = ESuiteKlantConfig.get_solo()
# config.register_email = "[email protected]"
# config.register_contact_moment = False
config.register_bronorganisatie_rsin = "800000009"
config.register_channel = "not-email"
config.register_type = "not-bericht"
Expand Down Expand Up @@ -203,3 +209,39 @@ def test_configure(self):
self.assertEqual(
config.interne_taak_toelichting, "Vraag via OIP, graag beantwoorden"
)


class KlantenSysteemConfigurationStepTest(TestCase):
def test_configure_success(self):
kc = ServiceFactory(
slug="klanten-service",
api_root=KLANTEN_SERVICE_API_ROOT,
api_type=APITypes.kc,
)
cmc = ServiceFactory(
slug="contactmomenten-service",
api_root=CONTACTMOMENTEN_SERVICE_API_ROOT,
api_type=APITypes.cmc,
)
esuite_config = ESuiteKlantConfig.get_solo()
esuite_config.klanten_service = kc
esuite_config.contactmomenten_service = cmc
esuite_config.save()

execute_single_step(
KlantenSysteemConfigurationStep,
yaml_source=KLANTENSYSTEEM_CONFIG_STEP_FULL_YAML,
)

config = KlantenSysteemConfig.get_solo()
self.assertEqual(config.primary_backend, KlantenServiceType.ESUITE.value)
self.assertTrue(config.register_contact_via_api)
self.assertEqual(config.register_contact_email, "[email protected]")
self.assertTrue(config.send_email_confirmation)

def test_configure_missing_api_services(self):
with self.assertRaises(ValidationError):
execute_single_step(
KlantenSysteemConfigurationStep,
yaml_source=KLANTENSYSTEEM_CONFIG_STEP_FULL_YAML,
)

0 comments on commit 913b67a

Please sign in to comment.