Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Make AC subscription check optional in NRC config check #43

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading