From 57363d4de3439f4367a0125703605d44b157f641 Mon Sep 17 00:00:00 2001 From: Sidney Richards Date: Thu, 12 Dec 2024 09:20:45 +0100 Subject: [PATCH] Make notifications_api_service_identifier required on NotificationConfigurationModel --- docs/setup_config.rst | 4 ++-- .../contrib/setup_configuration/models.py | 3 ++- tests/test_configuration_steps.py | 18 +++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/setup_config.rst b/docs/setup_config.rst index 9e058a1..fafd3d1 100644 --- a/docs/setup_config.rst +++ b/docs/setup_config.rst @@ -50,9 +50,9 @@ Example file: - Foo - Bar -If the ``notifications_api_service_identifier`` is specified, it might also be useful +Because ``notifications_api_service_identifier`` is required, it might also be useful to use the `ServiceConfigurationStep `_ -from ``zgw-consumers``. +from ``zgw-consumers`` to configure the ``Service`` object for the notifications API. Note that the ``uuid`` field in your subscriptions config must point to an existing ``Abonnement`` in the Open Notificaties service configured through ``notifications_config``. diff --git a/notifications_api_common/contrib/setup_configuration/models.py b/notifications_api_common/contrib/setup_configuration/models.py index 308e3d5..0f4f79e 100644 --- a/notifications_api_common/contrib/setup_configuration/models.py +++ b/notifications_api_common/contrib/setup_configuration/models.py @@ -6,7 +6,8 @@ class NotificationConfigurationModel(ConfigurationModel): notifications_api_service_identifier: str = DjangoModelRef( - NotificationsConfig, "notifications_api_service", default="" + NotificationsConfig, + "notifications_api_service", ) class Meta: diff --git a/tests/test_configuration_steps.py b/tests/test_configuration_steps.py index 837e31a..57968f0 100644 --- a/tests/test_configuration_steps.py +++ b/tests/test_configuration_steps.py @@ -1,4 +1,5 @@ import pytest +from django_setup_configuration.exceptions import PrerequisiteFailed from django_setup_configuration.test_utils import execute_single_step from zgw_consumers.test.factories import ServiceFactory @@ -57,17 +58,16 @@ def test_execute_configuration_step_update_existing(): @pytest.mark.django_db def test_execute_configuration_step_without_service_success(): - execute_single_step( - NotificationConfigurationStep, yaml_source=CONFIG_FILE_PATH_NO_SERVICE + with pytest.raises(PrerequisiteFailed) as excinfo: + execute_single_step( + NotificationConfigurationStep, yaml_source=CONFIG_FILE_PATH_NO_SERVICE + ) + + assert ( + "notifications_config.notifications_api_service_identifier\n Input should be a valid string" + in str(excinfo.value) ) - config = NotificationsConfig.get_solo() - - assert config.notifications_api_service is None - assert config.notification_delivery_max_retries == 1 - assert config.notification_delivery_retry_backoff == 2 - assert config.notification_delivery_retry_backoff_max == 3 - @pytest.mark.django_db def test_execute_configuration_step_idempotent():