diff --git a/src/open_inwoner/configurations/bootstrap/openklant.py b/src/open_inwoner/configurations/bootstrap/openklant.py index 1c4d16ed0..e2c8c7012 100644 --- a/src/open_inwoner/configurations/bootstrap/openklant.py +++ b/src/open_inwoner/configurations/bootstrap/openklant.py @@ -54,7 +54,7 @@ class Meta: } -class KlantSysteemConfigurationModel(ConfigurationModel): +class KlantenSysteemConfigurationModel(ConfigurationModel): class Meta: django_model_refs = { KlantenSysteemConfig: ( @@ -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() diff --git a/src/open_inwoner/configurations/tests/bootstrap/files/klantensysteem_config_step_full.yaml b/src/open_inwoner/configurations/tests/bootstrap/files/klantensysteem_config_step_full.yaml new file mode 100644 index 000000000..69bf3be6e --- /dev/null +++ b/src/open_inwoner/configurations/tests/bootstrap/files/klantensysteem_config_step_full.yaml @@ -0,0 +1,6 @@ +klantensysteem_config_enable: true +klantensysteem_config: + primary_backend: esuite + register_contact_via_api: true + register_contact_email: "oip-test@test.nl" + send_email_confirmation: true diff --git a/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py b/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py index 18580abe7..d9b363621 100644 --- a/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py +++ b/src/open_inwoner/configurations/tests/bootstrap/test_setup_openklant_config.py @@ -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, ) @@ -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") @@ -147,8 +157,6 @@ def assert_values(): self.assertEqual(config.klanten_service, kc) self.assertEqual(config.contactmomenten_service, cmc) - # self.assertEqual(config.register_email, "admin@oip.org") - # 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") @@ -162,8 +170,6 @@ def assert_values(): assert_values() config = ESuiteKlantConfig.get_solo() - # config.register_email = "not-admin@oip.org" - # config.register_contact_moment = False config.register_bronorganisatie_rsin = "800000009" config.register_channel = "not-email" config.register_type = "not-bericht" @@ -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, "oip-test@test.nl") + 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, + )