Skip to content

Commit

Permalink
♻️ Make AC subscription check optional in NRC config check
Browse files Browse the repository at this point in the history
to ensure that this utility can be reused in Open Zaak and Open Notificaties
  • Loading branch information
stevenbal committed Nov 22, 2024
1 parent de4e340 commit 391ccb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.translation import gettext as _

import pytest
import requests_mock
from notifications_api_common.models import NotificationsConfig
from requests import Response
from rest_framework import status
from zgw_consumers.test.factories import ServiceFactory

Expand Down Expand Up @@ -120,7 +120,10 @@ def test_config_view_notifications_error_response(api_client):
response_content = response.content.decode("utf-8")

assert response.status_code == status.HTTP_200_OK
assert "Could not connect with NRC" in response_content
assert (
_("Cannot retrieve kanalen: HTTP {status_code}").format(status_code=403)
in response_content
)

assert request_mocker.call_count == 2

Expand Down
12 changes: 10 additions & 2 deletions vng_api_common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _test_ac_config() -> list:
return checks


def _test_nrc_config() -> list:
def _test_nrc_config(check_autorisaties_subscription=True) -> list:
if not apps.is_installed("notifications_api_common"):
return []

Expand Down Expand Up @@ -209,14 +209,22 @@ def _test_nrc_config() -> list:
try:
response: requests.Response = nrc_client.get("kanaal")
response.raise_for_status()
except requests.RequestException:
except requests.ConnectionError:
error = True
message = _("Could not connect with NRC")
except requests.HTTPError as exc:
error = True
message = _("Cannot retrieve kanalen: HTTP {status_code}").format(
status_code=exc.response.status_code
)
else:
message = _("Can retrieve kanalen")

checks.append((_("NRC connection and authorizations"), message, not error))

if not check_autorisaties_subscription:
return checks

# check if there's a subscription for AC notifications
has_sub = (
Subscription.objects.filter(channels__contains=["autorisaties"])
Expand Down

0 comments on commit 391ccb4

Please sign in to comment.