From 4a256d931f62dabce042114b3cc303aab2940ca6 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Wed, 11 Dec 2024 11:31:55 +0100 Subject: [PATCH 1/4] [#467] Update objecttypes configuration step The step now lets you configure an connection with an objecttypes api --- docs/installation/config_cli.rst | 43 +-- src/objects/conf/base.py | 2 +- .../tests/files/objecttypes_connection.yaml | 16 ++ .../files/objecttypes_connection_invalid.yaml | 16 ++ .../files/objecttypes_empty_database.yaml | 10 - .../objecttypes_existing_objecttype.yaml | 10 - .../tests/files/objecttypes_idempotent.yaml | 10 - .../tests/files/objecttypes_invalid_uuid.yaml | 10 - .../files/objecttypes_unknown_service.yaml | 10 - .../core/tests/test_objecttype_config.py | 255 ++++++++---------- .../setup_configuration/models/objecttypes.py | 18 -- .../setup_configuration/steps/objecttypes.py | 92 +++---- 12 files changed, 196 insertions(+), 296 deletions(-) create mode 100644 src/objects/core/tests/files/objecttypes_connection.yaml create mode 100644 src/objects/core/tests/files/objecttypes_connection_invalid.yaml delete mode 100644 src/objects/core/tests/files/objecttypes_empty_database.yaml delete mode 100644 src/objects/core/tests/files/objecttypes_existing_objecttype.yaml delete mode 100644 src/objects/core/tests/files/objecttypes_idempotent.yaml delete mode 100644 src/objects/core/tests/files/objecttypes_invalid_uuid.yaml delete mode 100644 src/objects/core/tests/files/objecttypes_unknown_service.yaml delete mode 100644 src/objects/setup_configuration/models/objecttypes.py diff --git a/docs/installation/config_cli.rst b/docs/installation/config_cli.rst index 46022516..6ec0c940 100644 --- a/docs/installation/config_cli.rst +++ b/docs/installation/config_cli.rst @@ -51,44 +51,23 @@ Create or update a (single) YAML configuration file with your settings: .. note:: The ``domain`` field will be used to lookup existing ``Site``'s. -Objecttypes configuration +Objecttypes connection configuration ------------------------- Create or update a (single) YAML configuration file with your settings: .. code-block:: yaml + objecttypes_connection_config_enable: true + objecttypes_connection: + identifier: objecttypen + label: ObjectTypen API + api_root: http://objecttypen.nl/api/v1/ + api_connection_check_path: objecttypes + api_type: orc + auth_type: api_key + header_key: Authorization + header_value: Token foo ... - zgw_consumers_config_enable: true - zgw_consumers: - services: - - identifier: objecttypen-foo - label: Objecttypen API Foo - api_root: http://objecttypen.foo/api/v1/ - api_type: orc - auth_type: api_key - - identifier: objecttypen-bar - label: Objecttypen API Bar - api_root: http://objecttypen.bar/api/v1/ - api_type: orc - auth_type: api_key - - objecttypes_config_enable: true - objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: objecttypen-foo - - - uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 - name: Object Type 2 - service_identifier: objecttypen-bar - ... - -.. note:: The ``uuid`` field will be used to lookup existing ``ObjectType``'s. - -Objecttypes require a corresponding ``Service`` to work correctly. Creating -these ``Service``'s can be done by defining these in the same yaml file. ``Service`` -instances will be created before the ``ObjectType``'s are created. Execution diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index 201c4f70..09be2714 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -86,5 +86,5 @@ SETUP_CONFIGURATION_STEPS = ( "zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep", "objects.setup_configuration.steps.sites.SitesConfigurationStep", - "objects.setup_configuration.steps.objecttypes.ObjectTypesConfigurationStep", + "objects.setup_configuration.steps.objecttypes.ObjectTypesConnectionConfigurationStep", ) diff --git a/src/objects/core/tests/files/objecttypes_connection.yaml b/src/objects/core/tests/files/objecttypes_connection.yaml new file mode 100644 index 00000000..d52b4ed9 --- /dev/null +++ b/src/objects/core/tests/files/objecttypes_connection.yaml @@ -0,0 +1,16 @@ +objecttypes_connection_config_enable: true +objecttypes_connection: + identifier: objecttypes-api + label: Objecttypen API + api_root: https://objecttypes.nl/api/v1/ + api_connection_check_path: objecttypes + api_type: orc + auth_type: zgw + header_key: Authorization + header_value: Token foo + client_id: client + secret: secret + nlx: http://some-outway-adress.local:8080/ + user_id: objects-api + user_representation: Objects API + timeout: 60 diff --git a/src/objects/core/tests/files/objecttypes_connection_invalid.yaml b/src/objects/core/tests/files/objecttypes_connection_invalid.yaml new file mode 100644 index 00000000..164deaa7 --- /dev/null +++ b/src/objects/core/tests/files/objecttypes_connection_invalid.yaml @@ -0,0 +1,16 @@ +objecttypes_connection_config_enable: true +objecttypes_connection: + identifier: identifier with whitespace in between + label: Objecttypen API + api_root: https://objecttypes.nl/api/v1/ + api_connection_check_path: objectttypes + api_type: orc + auth_type: zgw + header_key: Authorization + header_value: Token foo + client_id: client + secret: super-secret + nlx: http://some-outway-adress.local:8080/ + user_id: objects-api + user_representation: Objects API + timeout: 60 diff --git a/src/objects/core/tests/files/objecttypes_empty_database.yaml b/src/objects/core/tests/files/objecttypes_empty_database.yaml deleted file mode 100644 index b969949e..00000000 --- a/src/objects/core/tests/files/objecttypes_empty_database.yaml +++ /dev/null @@ -1,10 +0,0 @@ -objecttypes_config_enable: true -objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: service-1 - - - uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 - name: Object Type 2 - service_identifier: service-2 diff --git a/src/objects/core/tests/files/objecttypes_existing_objecttype.yaml b/src/objects/core/tests/files/objecttypes_existing_objecttype.yaml deleted file mode 100644 index f93e005f..00000000 --- a/src/objects/core/tests/files/objecttypes_existing_objecttype.yaml +++ /dev/null @@ -1,10 +0,0 @@ -objecttypes_config_enable: true -objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: service-1 - - - uuid: 7229549b-7b41-47d1-8106-414b2a69751b - name: Object Type 3 - service_identifier: service-2 diff --git a/src/objects/core/tests/files/objecttypes_idempotent.yaml b/src/objects/core/tests/files/objecttypes_idempotent.yaml deleted file mode 100644 index b969949e..00000000 --- a/src/objects/core/tests/files/objecttypes_idempotent.yaml +++ /dev/null @@ -1,10 +0,0 @@ -objecttypes_config_enable: true -objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: service-1 - - - uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 - name: Object Type 2 - service_identifier: service-2 diff --git a/src/objects/core/tests/files/objecttypes_invalid_uuid.yaml b/src/objects/core/tests/files/objecttypes_invalid_uuid.yaml deleted file mode 100644 index 2a360c8e..00000000 --- a/src/objects/core/tests/files/objecttypes_invalid_uuid.yaml +++ /dev/null @@ -1,10 +0,0 @@ -objecttypes_config_enable: true -objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: service-1 - - - uuid: foobar - name: Object Type 2 - service_identifier: service-1 diff --git a/src/objects/core/tests/files/objecttypes_unknown_service.yaml b/src/objects/core/tests/files/objecttypes_unknown_service.yaml deleted file mode 100644 index 8348427c..00000000 --- a/src/objects/core/tests/files/objecttypes_unknown_service.yaml +++ /dev/null @@ -1,10 +0,0 @@ -objecttypes_config_enable: true -objecttypes: - items: - - uuid: b427ef84-189d-43aa-9efd-7bb2c459e281 - name: Object Type 1 - service_identifier: unknown - - - uuid: b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2 - name: Object Type 2 - service_identifier: service-1 diff --git a/src/objects/core/tests/test_objecttype_config.py b/src/objects/core/tests/test_objecttype_config.py index 5fb40bb5..706aef9f 100644 --- a/src/objects/core/tests/test_objecttype_config.py +++ b/src/objects/core/tests/test_objecttype_config.py @@ -1,172 +1,135 @@ from pathlib import Path -from django.db.models import QuerySet 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, AuthTypes from zgw_consumers.models import Service from zgw_consumers.test.factories import ServiceFactory -from objects.core.models import ObjectType -from objects.core.tests.factories import ObjectTypeFactory -from objects.setup_configuration.steps.objecttypes import ObjectTypesConfigurationStep +from objects.setup_configuration.steps.objecttypes import ( + ObjectTypesConnectionConfigurationStep, +) TEST_FILES = (Path(__file__).parent / "files").resolve() -class ObjectTypesConfigurationStepTests(TestCase): - def test_empty_database(self): - service_1 = ServiceFactory(slug="service-1") - service_2 = ServiceFactory(slug="service-2") +class ObjectTypesConnectionConfigurationStepTests(TestCase): + def test_create_connection(self): + test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") - test_file_path = str(TEST_FILES / "objecttypes_empty_database.yaml") - - execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) - - objecttypes: QuerySet[ObjectType] = ObjectType.objects.order_by("_name") - - self.assertEqual(objecttypes.count(), 2) - - objecttype_1: ObjectType = objecttypes.first() - - self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype_1._name, "Object Type 1") - self.assertEqual(objecttype_1.service, service_1) - - objecttype_2: ObjectType = objecttypes.last() - - self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") - self.assertEqual(objecttype_2._name, "Object Type 2") - self.assertEqual(objecttype_2.service, service_2) - - def test_existing_objecttype(self): - test_file_path = str(TEST_FILES / "objecttypes_existing_objecttype.yaml") - - service_1: Service = ServiceFactory(slug="service-1") - service_2: Service = ServiceFactory(slug="service-2") - - objecttype_1: ObjectType = ObjectTypeFactory( - service=service_1, - uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", - _name="Object Type 001", - ) - objecttype_2: ObjectType = ObjectTypeFactory( - service=service_2, - uuid="b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2", - _name="Object Type 002", + execute_single_step( + ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path ) - execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) - - self.assertEqual(ObjectType.objects.count(), 3) - - objecttype_1.refresh_from_db() - - self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype_1._name, "Object Type 1") - self.assertEqual(objecttype_1.service, service_1) - - objecttype_2.refresh_from_db() - - self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") - self.assertEqual(objecttype_2._name, "Object Type 002") - self.assertEqual(objecttype_2.service, service_2) - - objecttype_3: ObjectType = ObjectType.objects.get( - uuid="7229549b-7b41-47d1-8106-414b2a69751b" + service = Service.objects.get(slug="objecttypes-api") + + self.assertEqual(service.label, "Objecttypen API") + self.assertEqual(service.api_type, APITypes.orc) + self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") + self.assertEqual(service.api_connection_check_path, "objecttypes") + self.assertEqual(service.auth_type, AuthTypes.zgw) + self.assertEqual(service.client_id, "client") + self.assertEqual(service.secret, "secret") + self.assertEqual(service.header_key, "Authorization") + self.assertEqual(service.header_value, "Token foo") + self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") + self.assertEqual(service.user_id, "objects-api") + self.assertEqual(service.user_representation, "Objects API") + self.assertEqual(service.timeout, 60) + + def test_update_connection(self): + test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") + + service: Service = ServiceFactory( + slug="objecttypes-api", + label="Objecttypen API Test", + api_type=APITypes.zrc, + api_root="https://test.objecttypes.nl/api/v1/", + api_connection_check_path="objecttype", + auth_type=AuthTypes.api_key, + client_id="test-client", + secret="test-secret", + header_key="authorization", + header_value="Token foobar", + nlx="http://test.some-outway-adress.local:8080/", + user_id="test-objects-api", + user_representation="Test Objects API", + timeout=30, ) - self.assertEqual(str(objecttype_3.uuid), "7229549b-7b41-47d1-8106-414b2a69751b") - self.assertEqual(objecttype_3._name, "Object Type 3") - self.assertEqual(objecttype_3.service, service_2) - - def test_unknown_service(self): - service = ServiceFactory(slug="service-1") - - objecttype: ObjectType = ObjectTypeFactory( - uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", - _name="Object Type 001", - service=service, + execute_single_step( + ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path ) - test_file_path = str(TEST_FILES / "objecttypes_unknown_service.yaml") - - with self.assertRaises(ConfigurationRunFailed): - execute_single_step( - ObjectTypesConfigurationStep, yaml_source=test_file_path - ) - - self.assertEqual(ObjectType.objects.count(), 1) - - objecttype.refresh_from_db() - - self.assertEqual(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype._name, "Object Type 001") - self.assertEqual(objecttype.service, service) - - def test_invalid_uuid(self): - test_file_path = str(TEST_FILES / "objecttypes_invalid_uuid.yaml") - - service: Service = ServiceFactory(slug="service-1") - - objecttype: ObjectType = ObjectTypeFactory( - service=service, - uuid="b427ef84-189d-43aa-9efd-7bb2c459e281", - _name="Object Type 001", + self.assertEqual(Service.objects.count(), 1) + + service.refresh_from_db() + + self.assertEqual(service.label, "Objecttypen API") + self.assertEqual(service.api_type, APITypes.orc) + self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") + self.assertEqual(service.api_connection_check_path, "objecttypes") + self.assertEqual(service.auth_type, AuthTypes.zgw) + self.assertEqual(service.client_id, "client") + self.assertEqual(service.secret, "secret") + self.assertEqual(service.header_key, "Authorization") + self.assertEqual(service.header_value, "Token foo") + self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") + self.assertEqual(service.user_id, "objects-api") + self.assertEqual(service.user_representation, "Objects API") + self.assertEqual(service.timeout, 60) + + def test_invalid_identifier(self): + test_file_path = str(TEST_FILES / "objecttypes_connection_invalid.yaml") + + execute_single_step( + ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path ) - with self.assertRaises(ConfigurationRunFailed): - execute_single_step( - ObjectTypesConfigurationStep, yaml_source=test_file_path - ) - - self.assertEqual(ObjectType.objects.count(), 1) - - objecttype.refresh_from_db() - - self.assertEqual(str(objecttype.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype._name, "Object Type 1") - self.assertEqual(objecttype.service, service) + self.assertEqual(Service.objects.count(), 0) def test_idempotent_step(self): - service_1 = ServiceFactory(slug="service-1") - service_2 = ServiceFactory(slug="service-2") - - test_file_path = str(TEST_FILES / "objecttypes_idempotent.yaml") - - execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) + test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") - objecttypes: QuerySet[ObjectType] = ObjectType.objects.order_by("_name") - - self.assertEqual(objecttypes.count(), 2) - - objecttype_1: ObjectType = objecttypes.first() - - self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype_1._name, "Object Type 1") - self.assertEqual(objecttype_1.service, service_1) - - objecttype_2: ObjectType = objecttypes.last() - - self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") - self.assertEqual(objecttype_2._name, "Object Type 2") - self.assertEqual(objecttype_2.service, service_2) - - # Rerun - execute_single_step(ObjectTypesConfigurationStep, yaml_source=test_file_path) - - objecttype_1.refresh_from_db() - objecttype_2.refresh_from_db() - - self.assertEqual(ObjectType.objects.count(), 2) + execute_single_step( + ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path + ) - # objecttype 1 - self.assertEqual(str(objecttype_1.uuid), "b427ef84-189d-43aa-9efd-7bb2c459e281") - self.assertEqual(objecttype_1._name, "Object Type 1") - self.assertEqual(objecttype_1.service, service_1) + service = Service.objects.get(slug="objecttypes-api") + + self.assertEqual(service.label, "Objecttypen API") + self.assertEqual(service.api_type, APITypes.orc) + self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") + self.assertEqual(service.api_connection_check_path, "objecttypes") + self.assertEqual(service.auth_type, AuthTypes.zgw) + self.assertEqual(service.client_id, "client") + self.assertEqual(service.secret, "secret") + self.assertEqual(service.header_key, "Authorization") + self.assertEqual(service.header_value, "Token foo") + self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") + self.assertEqual(service.user_id, "objects-api") + self.assertEqual(service.user_representation, "Objects API") + self.assertEqual(service.timeout, 60) + + execute_single_step( + ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path + ) - # objecttype 2 - self.assertEqual(str(objecttype_2.uuid), "b0e8553f-8b1a-4d55-ab90-6d02f1bcf2c2") - self.assertEqual(objecttype_2._name, "Object Type 2") - self.assertEqual(objecttype_2.service, service_2) + self.assertEqual(Service.objects.count(), 1) + + service.refresh_from_db() + + self.assertEqual(service.label, "Objecttypen API") + self.assertEqual(service.api_type, APITypes.orc) + self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") + self.assertEqual(service.api_connection_check_path, "objecttypes") + self.assertEqual(service.auth_type, AuthTypes.zgw) + self.assertEqual(service.client_id, "client") + self.assertEqual(service.secret, "secret") + self.assertEqual(service.header_key, "Authorization") + self.assertEqual(service.header_value, "Token foo") + self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") + self.assertEqual(service.user_id, "objects-api") + self.assertEqual(service.user_representation, "Objects API") + self.assertEqual(service.timeout, 60) diff --git a/src/objects/setup_configuration/models/objecttypes.py b/src/objects/setup_configuration/models/objecttypes.py deleted file mode 100644 index 0f440d33..00000000 --- a/src/objects/setup_configuration/models/objecttypes.py +++ /dev/null @@ -1,18 +0,0 @@ -from django_setup_configuration.fields import DjangoModelRef -from django_setup_configuration.models import ConfigurationModel -from pydantic import Field -from zgw_consumers.models import Service - -from objects.core.models import ObjectType - - -class ObjectTypeConfigurationModel(ConfigurationModel): - service_identifier: str = DjangoModelRef(Service, "slug") - name: str = DjangoModelRef(ObjectType, "_name") - - class Meta: - django_model_refs = {ObjectType: ("uuid",)} - - -class ObjectTypesConfigurationModel(ConfigurationModel): - items: list[ObjectTypeConfigurationModel] = Field() diff --git a/src/objects/setup_configuration/steps/objecttypes.py b/src/objects/setup_configuration/steps/objecttypes.py index 91914ac4..2f2a2792 100644 --- a/src/objects/setup_configuration/steps/objecttypes.py +++ b/src/objects/setup_configuration/steps/objecttypes.py @@ -1,57 +1,51 @@ -from django.core.exceptions import ValidationError from django.db import IntegrityError from django_setup_configuration.configuration import BaseConfigurationStep from django_setup_configuration.exceptions import ConfigurationRunFailed +from zgw_consumers.contrib.setup_configuration.models import ( + SingleServiceConfigurationModel, +) from zgw_consumers.models import Service -from objects.core.models import ObjectType -from objects.setup_configuration.models.objecttypes import ObjectTypesConfigurationModel - -class ObjectTypesConfigurationStep(BaseConfigurationStep): - config_model = ObjectTypesConfigurationModel - verbose_name = "Objecttypes Configuration" - - namespace = "objecttypes" - enable_setting = "objecttypes_config_enable" - - def execute(self, model: ObjectTypesConfigurationModel) -> None: - for item in model.items: - try: - service = Service.objects.get(slug=item.service_identifier) - except Service.DoesNotExist: - raise ConfigurationRunFailed( - f"No service found with identifier {item.service_identifier}" - ) - - objecttype_kwargs = dict( - service=service, - uuid=item.uuid, - _name=item.name, +class ObjectTypesConnectionConfigurationStep( + BaseConfigurationStep[SingleServiceConfigurationModel] +): + config_model = SingleServiceConfigurationModel + verbose_name = "Objecttypes connection configuration" + + namespace = "objecttypes_connection" + enable_setting = "objecttypes_connection_config_enable" + + def execute(self, model: SingleServiceConfigurationModel) -> None: + service_kwargs = dict( + slug=model.identifier, + label=model.label, + api_type=model.api_type, + api_root=model.api_root, + api_connection_check_path=model.api_connection_check_path, + auth_type=model.auth_type, + client_id=model.client_id, + secret=model.secret, + header_key=model.header_key, + header_value=model.header_value, + nlx=model.nlx, + user_id=model.user_id, + user_representation=model.user_representation, + timeout=model.timeout, + ) + + service = Service(**service_kwargs) + + try: + Service.objects.update_or_create( + slug=service.slug, + defaults={ + key: value for key, value in service_kwargs.items() if key != "slug" + }, ) - - objecttype_instance = ObjectType(**objecttype_kwargs) - - try: - objecttype_instance.full_clean( - exclude=("id", "service"), validate_unique=False - ) - except ValidationError as exception: - exception_message = ( - f"Validation error(s) occured for objecttype {item.uuid}." - ) - raise ConfigurationRunFailed(exception_message) from exception - - try: - ObjectType.objects.update_or_create( - uuid=item.uuid, - defaults={ - key: value - for key, value in objecttype_kwargs.items() - if key != "uuid" - }, - ) - except IntegrityError as exception: - exception_message = f"Failed configuring ObjectType {item.uuid}." - raise ConfigurationRunFailed(exception_message) from exception + except IntegrityError as exception: + exception_message = ( + f"Failed configuring ObjectType connection {service.slug}." + ) + raise ConfigurationRunFailed(exception_message) from exception From fc99137f1e4041de9bf5136b6d3576186612d971 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Wed, 11 Dec 2024 11:36:15 +0100 Subject: [PATCH 2/4] [#467] update config namespace --- docs/installation/config_cli.rst | 4 ++-- src/objects/core/tests/files/objecttypes_connection.yaml | 4 ++-- .../core/tests/files/objecttypes_connection_invalid.yaml | 4 ++-- src/objects/setup_configuration/steps/objecttypes.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/installation/config_cli.rst b/docs/installation/config_cli.rst index 6ec0c940..68cd9dd4 100644 --- a/docs/installation/config_cli.rst +++ b/docs/installation/config_cli.rst @@ -57,8 +57,8 @@ Objecttypes connection configuration Create or update a (single) YAML configuration file with your settings: .. code-block:: yaml - objecttypes_connection_config_enable: true - objecttypes_connection: + objects_api_objecttypes_connection_config_enable: true + objects_api_objecttypes_connection": identifier: objecttypen label: ObjectTypen API api_root: http://objecttypen.nl/api/v1/ diff --git a/src/objects/core/tests/files/objecttypes_connection.yaml b/src/objects/core/tests/files/objecttypes_connection.yaml index d52b4ed9..0cf3177f 100644 --- a/src/objects/core/tests/files/objecttypes_connection.yaml +++ b/src/objects/core/tests/files/objecttypes_connection.yaml @@ -1,5 +1,5 @@ -objecttypes_connection_config_enable: true -objecttypes_connection: +objects_api_objecttypes_connection_config_enable: true +objects_api_objecttypes_connection: identifier: objecttypes-api label: Objecttypen API api_root: https://objecttypes.nl/api/v1/ diff --git a/src/objects/core/tests/files/objecttypes_connection_invalid.yaml b/src/objects/core/tests/files/objecttypes_connection_invalid.yaml index 164deaa7..c12d0270 100644 --- a/src/objects/core/tests/files/objecttypes_connection_invalid.yaml +++ b/src/objects/core/tests/files/objecttypes_connection_invalid.yaml @@ -1,5 +1,5 @@ -objecttypes_connection_config_enable: true -objecttypes_connection: +objects_api_objecttypes_connection_config_enable: true +objects_api_objecttypes_connection: identifier: identifier with whitespace in between label: Objecttypen API api_root: https://objecttypes.nl/api/v1/ diff --git a/src/objects/setup_configuration/steps/objecttypes.py b/src/objects/setup_configuration/steps/objecttypes.py index 2f2a2792..e99f3061 100644 --- a/src/objects/setup_configuration/steps/objecttypes.py +++ b/src/objects/setup_configuration/steps/objecttypes.py @@ -14,8 +14,8 @@ class ObjectTypesConnectionConfigurationStep( config_model = SingleServiceConfigurationModel verbose_name = "Objecttypes connection configuration" - namespace = "objecttypes_connection" - enable_setting = "objecttypes_connection_config_enable" + namespace = "objects_api_objecttypes_connection" + enable_setting = "objects_api_objecttypes_connection_config_enable" def execute(self, model: SingleServiceConfigurationModel) -> None: service_kwargs = dict( From 951e53ff25f5a9f1aaec7d449d68955e442ee601 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Wed, 11 Dec 2024 11:38:29 +0100 Subject: [PATCH 3/4] [#467] update sites config namespace --- docs/installation/config_cli.rst | 2 +- src/objects/setup_configuration/steps/sites.py | 2 +- .../setup_configuration/tests/files/sites_empty_database.yaml | 2 +- .../setup_configuration/tests/files/sites_existing_sites.yaml | 2 +- .../setup_configuration/tests/files/sites_idempotent_step.yaml | 2 +- .../setup_configuration/tests/files/sites_invalid_domain.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/installation/config_cli.rst b/docs/installation/config_cli.rst index 68cd9dd4..8cf749c1 100644 --- a/docs/installation/config_cli.rst +++ b/docs/installation/config_cli.rst @@ -40,7 +40,7 @@ Create or update a (single) YAML configuration file with your settings: .. code-block:: yaml ... sites_config_enable: true - sites: + sites_config: items: - domain: example.com name: Example site diff --git a/src/objects/setup_configuration/steps/sites.py b/src/objects/setup_configuration/steps/sites.py index 199e38f2..e92c5627 100644 --- a/src/objects/setup_configuration/steps/sites.py +++ b/src/objects/setup_configuration/steps/sites.py @@ -12,7 +12,7 @@ class SitesConfigurationStep(BaseConfigurationStep): config_model = SitesConfigurationModel verbose_name = "Sites configuration" - namespace = "sites" + namespace = "sites_config" enable_setting = "sites_config_enable" def execute(self, model: SitesConfigurationModel) -> None: diff --git a/src/objects/setup_configuration/tests/files/sites_empty_database.yaml b/src/objects/setup_configuration/tests/files/sites_empty_database.yaml index 808bdf57..505a3be3 100644 --- a/src/objects/setup_configuration/tests/files/sites_empty_database.yaml +++ b/src/objects/setup_configuration/tests/files/sites_empty_database.yaml @@ -1,5 +1,5 @@ sites_config_enable: true -sites: +sites_config: items: - domain: example.com name: Example site diff --git a/src/objects/setup_configuration/tests/files/sites_existing_sites.yaml b/src/objects/setup_configuration/tests/files/sites_existing_sites.yaml index d2f00fbb..1a873760 100644 --- a/src/objects/setup_configuration/tests/files/sites_existing_sites.yaml +++ b/src/objects/setup_configuration/tests/files/sites_existing_sites.yaml @@ -1,5 +1,5 @@ sites_config_enable: true -sites: +sites_config: items: - domain: example.com name: Example site (revised) diff --git a/src/objects/setup_configuration/tests/files/sites_idempotent_step.yaml b/src/objects/setup_configuration/tests/files/sites_idempotent_step.yaml index 808bdf57..505a3be3 100644 --- a/src/objects/setup_configuration/tests/files/sites_idempotent_step.yaml +++ b/src/objects/setup_configuration/tests/files/sites_idempotent_step.yaml @@ -1,5 +1,5 @@ sites_config_enable: true -sites: +sites_config: items: - domain: example.com name: Example site diff --git a/src/objects/setup_configuration/tests/files/sites_invalid_domain.yaml b/src/objects/setup_configuration/tests/files/sites_invalid_domain.yaml index e8995718..ac8fa7ca 100644 --- a/src/objects/setup_configuration/tests/files/sites_invalid_domain.yaml +++ b/src/objects/setup_configuration/tests/files/sites_invalid_domain.yaml @@ -1,5 +1,5 @@ sites_config_enable: true -sites: +sites_config: items: - domain: example.com name: Example site From 9615bcf1232896ff762a2f6ffef0ad38dd26ec67 Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Wed, 11 Dec 2024 11:41:35 +0100 Subject: [PATCH 4/4] [#467] remove `Field` call --- src/objects/setup_configuration/models/sites.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/objects/setup_configuration/models/sites.py b/src/objects/setup_configuration/models/sites.py index 347d8e0d..360bdbbc 100644 --- a/src/objects/setup_configuration/models/sites.py +++ b/src/objects/setup_configuration/models/sites.py @@ -1,7 +1,6 @@ from django.contrib.sites.models import Site from django_setup_configuration.models import ConfigurationModel -from pydantic import Field class SiteConfigurationModel(ConfigurationModel): @@ -15,4 +14,4 @@ class Meta: class SitesConfigurationModel(ConfigurationModel): - items: list[SiteConfigurationModel] = Field() + items: list[SiteConfigurationModel]