From 90b3d3d09a9c3f47d1542684139af765314a99bd Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 6 Dec 2024 12:11:14 +0100 Subject: [PATCH] :ok_hand: [open-zaak/open-notificaties#156] Process PR feedback --- notifications_api_common/kanalen.py | 4 ++-- tests/test_kanaal_documentation.py | 17 +++++++++++++++++ tests/test_register_webhook.py | 8 ++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/notifications_api_common/kanalen.py b/notifications_api_common/kanalen.py index f61afc2..051c7dd 100644 --- a/notifications_api_common/kanalen.py +++ b/notifications_api_common/kanalen.py @@ -48,11 +48,11 @@ def __repr__(self): ) @staticmethod - def get_field(model: Model, field: str) -> Field: + def get_field(model: Model, field_name: str) -> Field: """ Function to retrieve a field from a Model """ - return model._meta.get_field(field) + return model._meta.get_field(field_name) def get_help_text(self, field: Field, kenmerk: str) -> str: """ diff --git a/tests/test_kanaal_documentation.py b/tests/test_kanaal_documentation.py index 5baafa7..bf0d960 100644 --- a/tests/test_kanaal_documentation.py +++ b/tests/test_kanaal_documentation.py @@ -24,3 +24,20 @@ def test_generate_docs(): """ assert result == expected + + +def test_kanaal_get_help_text(): + kanaal = Kanaal(label="dummy", main_resource=Person, kenmerken=("name",)) + field = kanaal.get_field(Person, "name") + + assert kanaal.get_help_text(field, "name") == "The name of the person" + + kanaal = Kanaal( + label="dummy", + main_resource=Person, + kenmerken=("name",), + extra_kwargs={"name": {"help_text": "help text 2"}}, + ) + field = kanaal.get_field(Person, "name") + + assert kanaal.get_help_text(field, "name") == "help text 2" diff --git a/tests/test_register_webhook.py b/tests/test_register_webhook.py index c30bf2d..f72f5af 100644 --- a/tests/test_register_webhook.py +++ b/tests/test_register_webhook.py @@ -1,5 +1,3 @@ -from unittest.mock import patch - from django.contrib.messages import get_messages from django.utils.translation import gettext as _ @@ -48,7 +46,8 @@ def test_register_webhook_request_exception( channels=["zaken"], ) - with patch("requests.Session.post", side_effect=RequestException("exception")): + with requests_mock.Mocker() as m: + m.post(f"{NOTIFICATIONS_API_ROOT}abonnement", exc=RequestException("exception")) register_webhook(object, request_with_middleware, Subscription.objects.all()) messages = list(get_messages(request_with_middleware)) @@ -68,7 +67,8 @@ def test_register_webhook_http_error(request_with_middleware, notifications_conf channels=["zaken"], ) - with patch("requests.Session.post", side_effect=HTTPError("400")): + with requests_mock.Mocker() as m: + m.post(f"{NOTIFICATIONS_API_ROOT}abonnement", exc=HTTPError("400")) register_webhook(object, request_with_middleware, Subscription.objects.all()) messages = list(get_messages(request_with_middleware))