diff --git a/bin/setup_configuration.sh b/bin/setup_configuration.sh index b47af27e70..4e56378e07 100755 --- a/bin/setup_configuration.sh +++ b/bin/setup_configuration.sh @@ -10,7 +10,5 @@ if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then ${SCRIPTPATH}/wait_for_db.sh src/manage.py migrate - src/manage.py setup_configuration \ - --yaml-file data/services.yaml \ - --yaml-file data/objects_api.yaml + src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml fi diff --git a/docker-compose.yml b/docker-compose.yml index 9026c053fb..2b5c574f1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -90,7 +90,7 @@ services: volumes: &web_volumes - media:/app/media - private_media:/app/private_media - - ./docker/setup_configuration:/app/data + - ./docker/setup_configuration:/app/setup_configuration - log:/app/log - certifi_ca_bundle:/app/certifi_ca_bundle ports: diff --git a/docker/setup_configuration/services.yaml b/docker/setup_configuration/data.yaml similarity index 53% rename from docker/setup_configuration/services.yaml rename to docker/setup_configuration/data.yaml index b0120351f1..7840c13d5e 100644 --- a/docker/setup_configuration/services.yaml +++ b/docker/setup_configuration/data.yaml @@ -29,3 +29,28 @@ zgw_consumers: auth_type: zgw client_id: test_client_id secret: test_secret_key + +objects_api_config_enable: True +objects_api: + groups: + - name: Config 1 + identifier: config-1 + objects_service_identifier: objecten-test + objecttypes_service_identifier: objecttypen-test + drc_service_identifier: documenten-test + catalogi_service_identifier: catalogi-test + catalogue_domain: TEST + catalogue_rsin: "000000000" + organisatie_rsin: "000000000" + iot_submission_report: PDF Informatieobjecttype + iot_submission_csv: CSV Informatieobjecttype + iot_attachment: Attachment Informatieobjecttype + - name: Config 2 + identifier: config-2 + objects_service_identifier: objecten-test + objecttypes_service_identifier: objecttypen-test + drc_service_identifier: documenten-test + catalogi_service_identifier: catalogi-test + catalogue_domain: OTHER + catalogue_rsin: "000000000" + organisatie_rsin: "000000000" diff --git a/docker/setup_configuration/objects_api.yaml b/docker/setup_configuration/objects_api.yaml deleted file mode 100644 index fb7f8cf03e..0000000000 --- a/docker/setup_configuration/objects_api.yaml +++ /dev/null @@ -1,24 +0,0 @@ -objects_api_config_enable: True -objects_api: - groups: - - name: Config 1 - identifier: config-1 - objects_service_identifier: objecten-test - objecttypes_service_identifier: objecttypen-test - drc_service_identifier: documenten-test - catalogi_service_identifier: catalogi-test - catalogue_domain: TEST - catalogue_rsin: "000000000" - organisatie_rsin: "000000000" - iot_submission_report: PDF Informatieobjecttype - iot_submission_csv: CSV Informatieobjecttype - iot_attachment: Attachment Informatieobjecttype - - name: Config 2 - identifier: config-2 - objects_service_identifier: objecten-test - objecttypes_service_identifier: objecttypen-test - drc_service_identifier: documenten-test - catalogi_service_identifier: catalogi-test - catalogue_domain: OTHER - catalogue_rsin: "000000000" - organisatie_rsin: "000000000" diff --git a/src/openforms/contrib/objects_api/setup_configuration/steps.py b/src/openforms/contrib/objects_api/setup_configuration/steps.py index d1dbf9618d..bf99c6aca6 100644 --- a/src/openforms/contrib/objects_api/setup_configuration/steps.py +++ b/src/openforms/contrib/objects_api/setup_configuration/steps.py @@ -6,6 +6,17 @@ from .models import ObjectsAPIGroupConfigModel +def get_service(slug: str) -> Service: + """ + Try to find a Service and re-raise DoesNotExist with the identifier to make debugging + easier + """ + try: + return Service.objects.get(slug=slug) + except Service.DoesNotExist as e: + raise Service.DoesNotExist(f"{str(e)} (identifier = {slug})") + + class ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigModel]): """ Configure configuration groups for the Objects API backend @@ -23,11 +34,9 @@ def execute(self, model: ObjectsAPIGroupConfigModel): for config in model.groups: defaults = { "name": config.name, - "objects_service": Service.objects.get( - slug=config.objects_service_identifier - ), - "objecttypes_service": Service.objects.get( - slug=config.objecttypes_service_identifier + "objects_service": get_service(config.objects_service_identifier), + "objecttypes_service": get_service( + config.objecttypes_service_identifier ), "catalogue_domain": config.catalogue_domain, "catalogue_rsin": config.catalogue_rsin, @@ -37,12 +46,10 @@ def execute(self, model: ObjectsAPIGroupConfigModel): "iot_attachment": config.iot_attachment, } if config.drc_service_identifier: - defaults["drc_service"] = Service.objects.get( - slug=config.drc_service_identifier - ) + defaults["drc_service"] = get_service(config.drc_service_identifier) if config.catalogi_service_identifier: - defaults["catalogi_service"] = Service.objects.get( - slug=config.catalogi_service_identifier + defaults["catalogi_service"] = get_service( + config.catalogi_service_identifier ) ObjectsAPIGroupConfig.objects.update_or_create( diff --git a/src/openforms/contrib/objects_api/setup_configuration/tests/test_objects_api_config.py b/src/openforms/contrib/objects_api/setup_configuration/tests/test_objects_api_config.py index b9b193b132..b5a4fd0885 100644 --- a/src/openforms/contrib/objects_api/setup_configuration/tests/test_objects_api_config.py +++ b/src/openforms/contrib/objects_api/setup_configuration/tests/test_objects_api_config.py @@ -2,7 +2,7 @@ from django.test import TestCase -from django_setup_configuration.test_utils import load_step_config_from_source +from django_setup_configuration.test_utils import execute_single_step from zgw_consumers.constants import APITypes, AuthTypes from zgw_consumers.test.factories import ServiceFactory @@ -21,10 +21,6 @@ ) -def get_config_model(path): - return load_step_config_from_source(ObjectsAPIConfigurationStep, path) - - class ObjectsAPIConfigurationStepTests(TestCase): maxDiff = None @@ -69,10 +65,7 @@ def setUp(self): ) def test_execute_success(self): - step_config_model = get_config_model(CONFIG_FILE_PATH) - step = ObjectsAPIConfigurationStep() - - step.execute(step_config_model) + execute_single_step(ObjectsAPIConfigurationStep, CONFIG_FILE_PATH) self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 2) @@ -107,10 +100,7 @@ def test_execute_success(self): def test_execute_update_existing_config(self): ObjectsAPIGroupConfigFactory.create(name="old name", identifier="config-1") - step_config_model = get_config_model(CONFIG_FILE_PATH) - step = ObjectsAPIConfigurationStep() - - step.execute(step_config_model) + execute_single_step(ObjectsAPIConfigurationStep, CONFIG_FILE_PATH) self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 2) @@ -143,10 +133,9 @@ def test_execute_update_existing_config(self): self.assertEqual(config2.iot_attachment, "") def test_execute_with_required_fields(self): - step_config_model = get_config_model(CONFIG_FILE_PATH_REQUIRED_FIELDS) - step = ObjectsAPIConfigurationStep() - - step.execute(step_config_model) + execute_single_step( + ObjectsAPIConfigurationStep, CONFIG_FILE_PATH_REQUIRED_FIELDS + ) self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 1) @@ -167,10 +156,7 @@ def test_execute_with_required_fields(self): self.assertEqual(config.iot_attachment, "") def test_execute_with_all_fields(self): - step_config_model = get_config_model(CONFIG_FILE_PATH_ALL_FIELDS) - step = ObjectsAPIConfigurationStep() - - step.execute(step_config_model) + execute_single_step(ObjectsAPIConfigurationStep, CONFIG_FILE_PATH_ALL_FIELDS) self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 1) @@ -190,8 +176,6 @@ def test_execute_with_all_fields(self): self.assertEqual(config.iot_attachment, "Attachment Informatieobjecttype") def test_execute_is_idempotent(self): - step_config_model = get_config_model(CONFIG_FILE_PATH_ALL_FIELDS) - step = ObjectsAPIConfigurationStep() def make_assertions(): self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 1) @@ -211,10 +195,10 @@ def make_assertions(): self.assertEqual(config.iot_submission_csv, "CSV Informatieobjecttype") self.assertEqual(config.iot_attachment, "Attachment Informatieobjecttype") - step.execute(step_config_model) + execute_single_step(ObjectsAPIConfigurationStep, CONFIG_FILE_PATH_ALL_FIELDS) make_assertions() - step.execute(step_config_model) + execute_single_step(ObjectsAPIConfigurationStep, CONFIG_FILE_PATH_ALL_FIELDS) make_assertions()