Skip to content

Commit

Permalink
👽 [#4788] Changes according to setup-configuration lib changes
Browse files Browse the repository at this point in the history
* setup_configuration now only takes one yaml file as a source
* remove legacy `is_configured` and `validate_result` hooks
* change testing utils
  • Loading branch information
stevenbal committed Dec 2, 2024
1 parent 5c5f754 commit 06cb790
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 71 deletions.
4 changes: 1 addition & 3 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 0 additions & 24 deletions docker/setup_configuration/objects_api.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django_setup_configuration.models import ConfigurationModel, DjangoModelRef
from django_setup_configuration.fields import DjangoModelRef
from django_setup_configuration.models import ConfigurationModel
from pydantic import Field

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig
Expand Down
35 changes: 19 additions & 16 deletions src/openforms/contrib/objects_api/setup_configuration/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig

from .models import ObjectsAPIGroupConfigModel
from .models import ObjectsAPIGroupConfigModel, SingleObjectsAPIGroupConfigModel


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]):
Expand All @@ -16,18 +27,14 @@ class ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigMod
namespace = "objects_api"
enable_setting = "objects_api_config_enable"

def is_configured(self, model: ObjectsAPIGroupConfigModel) -> bool:
return False

def execute(self, model: ObjectsAPIGroupConfigModel):
config: SingleObjectsAPIGroupConfigModel
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,
Expand All @@ -37,17 +44,13 @@ 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(
identifier=config.identifier,
defaults=defaults,
)

def validate_result(self, model: ObjectsAPIGroupConfigModel) -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

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.models import Service
from zgw_consumers.test.factories import ServiceFactory

from openforms.contrib.objects_api.models import ObjectsAPIGroupConfig
Expand All @@ -21,10 +22,6 @@
)


def get_config_model(path):
return load_step_config_from_source(ObjectsAPIConfigurationStep, path)


class ObjectsAPIConfigurationStepTests(TestCase):
maxDiff = None

Expand Down Expand Up @@ -69,10 +66,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, yaml_source=CONFIG_FILE_PATH)

self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 2)

Expand Down Expand Up @@ -107,10 +101,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, yaml_source=CONFIG_FILE_PATH)

self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 2)

Expand Down Expand Up @@ -143,10 +134,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, yaml_source=CONFIG_FILE_PATH_REQUIRED_FIELDS
)

self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 1)

Expand All @@ -167,10 +157,9 @@ 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, yaml_source=CONFIG_FILE_PATH_ALL_FIELDS
)

self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 1)

Expand All @@ -190,9 +179,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)

Expand All @@ -211,10 +197,28 @@ 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, yaml_source=CONFIG_FILE_PATH_ALL_FIELDS
)

make_assertions()

step.execute(step_config_model)
execute_single_step(
ObjectsAPIConfigurationStep, yaml_source=CONFIG_FILE_PATH_ALL_FIELDS
)

make_assertions()

def test_execute_service_not_found_raises_error(self):
self.objecttypes_service.delete()

with self.assertRaisesMessage(
Service.DoesNotExist,
"Service matching query does not exist. (identifier = objecttypen-test)",
):
execute_single_step(
ObjectsAPIConfigurationStep,
yaml_source=CONFIG_FILE_PATH_REQUIRED_FIELDS,
)

self.assertEqual(ObjectsAPIGroupConfig.objects.count(), 0)

0 comments on commit 06cb790

Please sign in to comment.