From 4b3fbccc4c76047fa31a77ce5e703afb4e80fa9b Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 12 Aug 2024 11:36:09 +0200 Subject: [PATCH 1/3] :test_tube: [#426] update test for registering kanalen --- .../tests/v2/test_notifications_kanaal.py | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/objects/tests/v2/test_notifications_kanaal.py b/src/objects/tests/v2/test_notifications_kanaal.py index 4b5937f4..7f0cda20 100644 --- a/src/objects/tests/v2/test_notifications_kanaal.py +++ b/src/objects/tests/v2/test_notifications_kanaal.py @@ -1,16 +1,17 @@ from io import StringIO -from unittest.mock import patch +from unittest.mock import call, patch from django.contrib.sites.models import Site from django.core.management import call_command from django.test import override_settings -from notifications_api_common.kanalen import KANAAL_REGISTRY, Kanaal +from notifications_api_common.kanalen import KANAAL_REGISTRY from notifications_api_common.models import NotificationsConfig from rest_framework.test import APITestCase from zgw_consumers.constants import APITypes from zgw_consumers.models import Service +from objects.api.kanalen import ObjectKanaal from objects.core.models import Object @@ -23,7 +24,7 @@ def setUpTestData(cls): site.domain = "example.com" site.save() - kanaal = Kanaal(label="kanaal_test", main_resource=Object) + kanaal = ObjectKanaal(label="kanaal_test", main_resource=Object) cls.addClassCleanup(lambda: KANAAL_REGISTRY.remove(kanaal)) service, _ = Service.objects.update_or_create( @@ -79,11 +80,23 @@ def test_kanaal_create_without_name(self, mock_get_client): stdout=stdout, ) - client.create.assert_called_once_with( - "kanaal", - { - "naam": "kanaal_test", - "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", - "filters": [], - }, + client.create.assert_has_calls( + [ + call( + "kanaal", + { + "naam": "kanaal_test", + "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", + "filters": [], + }, + ), + call( + "kanaal", + { + "naam": "objecten", + "documentatieLink": "https://example.com/ref/kanalen/#objecten", + "filters": ["object_type"], + }, + ), + ] ) From 0f2f90e43106828b91e9ea94ce08dd717f786665 Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 12 Aug 2024 11:43:22 +0200 Subject: [PATCH 2/3] :bug: [#426] fix ObjectKanaal --- src/objects/api/kanalen.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/objects/api/kanalen.py b/src/objects/api/kanalen.py index d2b29bb1..267bbeee 100644 --- a/src/objects/api/kanalen.py +++ b/src/objects/api/kanalen.py @@ -3,7 +3,7 @@ from django.conf import settings from django.db import models -from notifications_api_common.kanalen import Kanaal +from notifications_api_common.kanalen import KANAAL_REGISTRY, Kanaal from objects.core.models import ObjectRecord @@ -20,6 +20,8 @@ def __init__( # check that we're refering to existing fields self.kenmerken = kenmerken or () + KANAAL_REGISTRY.add(self) + def get_kenmerken(self, obj: models.Model, data: dict = None) -> dict: data = data or {} return { @@ -29,6 +31,28 @@ def get_kenmerken(self, obj: models.Model, data: dict = None) -> dict: for kenmerk in self.kenmerken } + @property + def description(self): + """For Objects endpoint main resource is ObjectRecord, so adjust info here""" + kenmerk_template = "* `{kenmerk}`: {help_text}" + main_resource = self.main_resource.object.field.related_model + kenmerken = [ + kenmerk_template.format( + kenmerk=kenmerk, + help_text=main_resource._meta.get_field(kenmerk).help_text, + ) + for kenmerk in self.kenmerken + ] + + description = ( + "**Main resource**\n\n" + "`{options.model_name}`\n\n\n\n" + "**Kenmerken**\n\n" + "{kenmerken}" + ).format(options=main_resource._meta, kenmerken="\n".join(kenmerken)) + + return description + KANAAL_OBJECTEN = ObjectKanaal( settings.NOTIFICATIONS_KANAAL, From a8615f73fa434735fe07f8a87d48d9a99e95a95e Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 12 Aug 2024 11:48:02 +0200 Subject: [PATCH 3/3] :memo: [#426] add help text for Object.object_type field --- .../0029_alter_object_object_type.py | 22 +++++++++++++++++++ src/objects/core/models.py | 1 + 2 files changed, 23 insertions(+) create mode 100644 src/objects/core/migrations/0029_alter_object_object_type.py diff --git a/src/objects/core/migrations/0029_alter_object_object_type.py b/src/objects/core/migrations/0029_alter_object_object_type.py new file mode 100644 index 00000000..dd1afa64 --- /dev/null +++ b/src/objects/core/migrations/0029_alter_object_object_type.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.11 on 2024-08-12 09:36 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0028_alter_objectrecord_data"), + ] + + operations = [ + migrations.AlterField( + model_name="object", + name="object_type", + field=models.ForeignKey( + help_text="OBJECTTYPE in Objecttypes API", + on_delete=django.db.models.deletion.PROTECT, + to="core.objecttype", + ), + ), + ] diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 8cf1255d..de1103b3 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -58,6 +58,7 @@ class Object(models.Model): object_type = models.ForeignKey( ObjectType, on_delete=models.PROTECT, + help_text=_("OBJECTTYPE in Objecttypes API"), ) objects = ObjectQuerySet.as_manager()