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
* change testing utils
  • Loading branch information
stevenbal committed Nov 25, 2024
1 parent faac084 commit ecd28c5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 63 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.

27 changes: 17 additions & 10 deletions src/openforms/contrib/objects_api/setup_configuration/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})")

Check warning on line 17 in src/openforms/contrib/objects_api/setup_configuration/steps.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/contrib/objects_api/setup_configuration/steps.py#L16-L17

Added lines #L16 - L17 were not covered by tests


class ObjectsAPIConfigurationStep(BaseConfigurationStep[ObjectsAPIGroupConfigModel]):
"""
Configure configuration groups for the Objects API backend
Expand All @@ -23,11 +34,9 @@ def execute(self, model: ObjectsAPIGroupConfigModel):
for config in model.groups:
defaults = {
"name": config.name,

Check failure on line 36 in src/openforms/contrib/objects_api/setup_configuration/steps.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Cannot access attribute "name" for class "SingleObjectsAPIGroupConfigModel"   Attribute "name" is unknown (reportAttributeAccessIssue)
"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,

Check failure on line 41 in src/openforms/contrib/objects_api/setup_configuration/steps.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Cannot access attribute "catalogue_domain" for class "SingleObjectsAPIGroupConfigModel"   Attribute "catalogue_domain" is unknown (reportAttributeAccessIssue)
"catalogue_rsin": config.catalogue_rsin,

Check failure on line 42 in src/openforms/contrib/objects_api/setup_configuration/steps.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Cannot access attribute "catalogue_rsin" for class "SingleObjectsAPIGroupConfigModel"   Attribute "catalogue_rsin" is unknown (reportAttributeAccessIssue)
Expand All @@ -37,12 +46,10 @@ def execute(self, model: ObjectsAPIGroupConfigModel):
"iot_attachment": config.iot_attachment,

Check failure on line 46 in src/openforms/contrib/objects_api/setup_configuration/steps.py

View workflow job for this annotation

GitHub Actions / Type checking (Pyright)

Cannot access attribute "iot_attachment" for class "SingleObjectsAPIGroupConfigModel"   Attribute "iot_attachment" is unknown (reportAttributeAccessIssue)
}
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,10 +21,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 +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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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()

0 comments on commit ecd28c5

Please sign in to comment.