From 9ad58e18f337741896c5196f48469a49ed0736ce Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 1 Feb 2024 15:22:04 +0100 Subject: [PATCH] :heavy_plus_sign: Replace vng-api-common with commonground-api-common --- requirements/base.in | 2 +- requirements/base.txt | 92 +++++++++++----- requirements/ci.txt | 103 ++++++++++++++---- requirements/dev.txt | 101 +++++++++++++---- src/objects/api/kanalen.py | 2 +- src/objects/api/mixins.py | 10 +- src/objects/conf/base.py | 2 +- src/objects/fixtures/default_admin_index.json | 2 +- src/objects/tests/utils.py | 28 +++++ .../tests/v1/test_notifications_send.py | 60 +++------- .../tests/v2/test_notifications_kanaal.py | 30 ++--- .../tests/v2/test_notifications_send.py | 50 ++++----- src/objects/urls.py | 2 +- 13 files changed, 312 insertions(+), 172 deletions(-) diff --git a/requirements/base.in b/requirements/base.in index 33d6be84..561bdd21 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -27,5 +27,5 @@ sentry-sdk # error monitoring elastic-apm # Elastic APM integration # Common ground libraries -vng-api-common[markdown_docs]>=1.6.4 +commonground-api-common[markdown_docs]>=1.6.4 zgw-consumers # external api auths diff --git a/requirements/base.txt b/requirements/base.txt index 020195dd..f4d9eacf 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -4,16 +4,22 @@ # # pip-compile --no-emit-index-url requirements/base.in # +amqp==5.2.0 + # via kombu asgiref==3.7.2 # via django attrs==20.3.0 # via # glom # jsonschema +billiard==3.6.4.0 + # via celery boltons==21.0.0 # via # face # glom +celery==5.2.2 + # via notifications-api-common certifi==2020.12.5 # via # django-simple-certmanager @@ -24,8 +30,26 @@ cffi==1.16.0 # via cryptography chardet==4.0.0 # via requests +click==8.1.7 + # via + # celery + # click-didyoumean + # click-plugins + # click-repl +click-didyoumean==0.3.0 + # via celery +click-plugins==1.1.1 + # via celery +click-repl==0.3.0 + # via celery +commonground-api-common[markdown-docs]==1.12.1 + # via + # -r requirements/base.in + # commonground-api-common coreapi==2.3.3 - # via drf-yasg + # via + # commonground-api-common + # drf-yasg coreschema==0.0.4 # via # coreapi @@ -39,9 +63,9 @@ cryptography==41.0.7 django==3.2.23 # via # -r requirements/base.in + # commonground-api-common # django-admin-index # django-axes - # django-choices # django-filter # django-formtools # django-jsonform @@ -62,18 +86,16 @@ django==3.2.23 # maykin-django-two-factor-auth # mozilla-django-oidc # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers django-admin-index==3.1.0 # via -r requirements/base.in django-axes==5.41.1 # via -r requirements/base.in -django-choices==2.0.0 - # via vng-api-common django-filter==2.4.0 # via # -r requirements/base.in - # vng-api-common + # commonground-api-common django-formtools==2.3 # via maykin-django-two-factor-auth django-ipware==3.0.2 @@ -81,7 +103,7 @@ django-ipware==3.0.2 django-jsonform==2.21.4 # via mozilla-django-oidc-db django-markup==1.3 - # via vng-api-common + # via commonground-api-common django-ordered-model==3.7.4 # via django-admin-index django-otp==1.0.6 @@ -95,34 +117,38 @@ django-redis==5.2.0 django-relativedelta==2.0.0 # via zgw-consumers django-rest-framework-condition==0.1.1 - # via vng-api-common + # via commonground-api-common django-sendfile2==0.7.0 # via django-privates django-simple-certmanager==1.4.1 # via zgw-consumers django-solo==2.2.0 # via + # commonground-api-common # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers djangorestframework==3.12.4 # via # -r requirements/base.in + # commonground-api-common # djangorestframework-gis # drf-nested-routers # drf-spectacular # drf-yasg - # vng-api-common + # notifications-api-common djangorestframework-camel-case==1.2.0 - # via vng-api-common + # via + # commonground-api-common + # notifications-api-common djangorestframework-gis==1.0 # via -r requirements/base.in drf-nested-routers==0.93.3 - # via vng-api-common + # via commonground-api-common drf-spectacular==0.16.0 # via -r requirements/base.in drf-yasg==1.20.0 - # via vng-api-common + # via commonground-api-common elastic-apm==6.1.1 # via -r requirements/base.in face==20.1.1 @@ -131,7 +157,8 @@ faker==8.1.0 # via zgw-consumers gemma-zds-client==1.0.1 # via - # vng-api-common + # commonground-api-common + # notifications-api-common # zgw-consumers glom==23.5.0 # via @@ -144,9 +171,9 @@ inflection==0.5.1 # drf-spectacular # drf-yasg iso-639==0.4.5 - # via vng-api-common + # via commonground-api-common isodate==0.6.0 - # via vng-api-common + # via commonground-api-common itypes==1.2.0 # via coreapi jinja2==3.1.3 @@ -157,8 +184,10 @@ jsonschema==3.2.0 # via # -r requirements/base.in # drf-spectacular +kombu==5.3.5 + # via celery markdown==3.3.4 - # via vng-api-common + # via commonground-api-common markupsafe==2.1.3 # via jinja2 maykin-django-two-factor-auth[phonenumbers]==2.0.3 @@ -167,20 +196,24 @@ mozilla-django-oidc==4.0.0 # via mozilla-django-oidc-db mozilla-django-oidc-db==0.14.1 # via -r requirements/base.in +notifications-api-common==0.2.2 + # via commonground-api-common oyaml==1.0 - # via vng-api-common + # via commonground-api-common packaging==23.2 # via drf-yasg phonenumbers==8.12.29 # via maykin-django-two-factor-auth +prompt-toolkit==3.0.43 + # via click-repl psycopg2==2.8.6 # via -r requirements/base.in pycparser==2.20 # via cffi pyjwt==2.4.0 # via + # commonground-api-common # gemma-zds-client - # vng-api-common pyopenssl==23.3.0 # via # django-simple-certmanager @@ -197,24 +230,26 @@ python-decouple==3.4 python-dotenv==1.0.0 # via -r requirements/base.in pytz==2021.1 - # via django + # via + # celery + # django pyyaml==6.0.1 # via + # commonground-api-common # drf-spectacular # gemma-zds-client # oyaml - # vng-api-common qrcode==6.1 # via maykin-django-two-factor-auth redis==3.5.3 # via django-redis requests==2.25.1 # via + # commonground-api-common # coreapi # gemma-zds-client # mozilla-django-oidc # requests-mock - # vng-api-common # zgw-consumers requests-mock==1.8.0 # via zgw-consumers @@ -248,12 +283,17 @@ urllib3==1.26.6 # sentry-sdk uwsgi==2.0.21 # via -r requirements/base.in -vng-api-common[markdown-docs]==1.8.0 +vine==5.1.0 # via - # -r requirements/base.in - # vng-api-common + # amqp + # celery + # kombu +wcwidth==0.2.13 + # via prompt-toolkit zgw-consumers==0.27.0 - # via -r requirements/base.in + # via + # -r requirements/base.in + # notifications-api-common # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/requirements/ci.txt b/requirements/ci.txt index c75853ca..3dea63c3 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -4,6 +4,10 @@ # # pip-compile --no-emit-index-url --output-file=requirements/ci.txt requirements/base.txt requirements/test-tools.in # +amqp==5.2.0 + # via + # -r requirements/base.txt + # kombu asgiref==3.7.2 # via # -r requirements/base.txt @@ -15,11 +19,19 @@ attrs==20.3.0 # jsonschema beautifulsoup4==4.9.3 # via webtest +billiard==3.6.4.0 + # via + # -r requirements/base.txt + # celery boltons==21.0.0 # via # -r requirements/base.txt # face # glom +celery==5.2.2 + # via + # -r requirements/base.txt + # notifications-api-common certifi==2020.12.5 # via # -r requirements/base.txt @@ -35,9 +47,33 @@ chardet==4.0.0 # via # -r requirements/base.txt # requests +click==8.1.7 + # via + # -r requirements/base.txt + # celery + # click-didyoumean + # click-plugins + # click-repl +click-didyoumean==0.3.0 + # via + # -r requirements/base.txt + # celery +click-plugins==1.1.1 + # via + # -r requirements/base.txt + # celery +click-repl==0.3.0 + # via + # -r requirements/base.txt + # celery +commonground-api-common[markdown-docs]==1.12.1 + # via + # -r requirements/base.txt + # commonground-api-common coreapi==2.3.3 # via # -r requirements/base.txt + # commonground-api-common # drf-yasg coreschema==0.0.4 # via @@ -58,9 +94,9 @@ cssselect==1.1.0 django==3.2.23 # via # -r requirements/base.txt + # commonground-api-common # django-admin-index # django-axes - # django-choices # django-filter # django-formtools # django-jsonform @@ -81,20 +117,16 @@ django==3.2.23 # maykin-django-two-factor-auth # mozilla-django-oidc # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers django-admin-index==3.1.0 # via -r requirements/base.txt django-axes==5.41.1 # via -r requirements/base.txt -django-choices==2.0.0 - # via - # -r requirements/base.txt - # vng-api-common django-filter==2.4.0 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common django-formtools==2.3 # via # -r requirements/base.txt @@ -134,7 +166,7 @@ django-relativedelta==2.0.0 django-rest-framework-condition==0.1.1 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common django-sendfile2==0.7.0 # via # -r requirements/base.txt @@ -146,35 +178,38 @@ django-simple-certmanager==1.4.1 django-solo==2.2.0 # via # -r requirements/base.txt + # commonground-api-common # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers django-webtest==1.9.7 # via -r requirements/test-tools.in djangorestframework==3.12.4 # via # -r requirements/base.txt + # commonground-api-common # djangorestframework-gis # drf-nested-routers # drf-spectacular # drf-yasg - # vng-api-common + # notifications-api-common djangorestframework-camel-case==1.2.0 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common + # notifications-api-common djangorestframework-gis==1.0 # via -r requirements/base.txt drf-nested-routers==0.93.3 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common drf-spectacular==0.16.0 # via -r requirements/base.txt drf-yasg==1.20.0 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common elastic-apm==6.1.1 # via -r requirements/base.txt face==20.1.1 @@ -193,7 +228,8 @@ freezegun==1.1.0 gemma-zds-client==1.0.1 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common + # notifications-api-common # zgw-consumers glom==23.5.0 # via @@ -211,11 +247,11 @@ inflection==0.5.1 iso-639==0.4.5 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common isodate==0.6.0 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common itypes==1.2.0 # via # -r requirements/base.txt @@ -232,6 +268,10 @@ jsonschema==3.2.0 # via # -r requirements/base.txt # drf-spectacular +kombu==5.3.5 + # via + # -r requirements/base.txt + # celery lxml==4.7.1 # via pyquery markdown==3.3.4 @@ -250,10 +290,14 @@ mozilla-django-oidc==4.0.0 # mozilla-django-oidc-db mozilla-django-oidc-db==0.14.1 # via -r requirements/base.txt +notifications-api-common==0.2.2 + # via + # -r requirements/base.txt + # commonground-api-common oyaml==1.0 # via # -r requirements/base.txt - # vng-api-common + # commonground-api-common packaging==23.2 # via # -r requirements/base.txt @@ -262,6 +306,10 @@ phonenumbers==8.12.29 # via # -r requirements/base.txt # maykin-django-two-factor-auth +prompt-toolkit==3.0.43 + # via + # -r requirements/base.txt + # click-repl psycopg2==2.8.6 # via -r requirements/base.txt pycparser==2.20 @@ -271,8 +319,8 @@ pycparser==2.20 pyjwt==2.4.0 # via # -r requirements/base.txt + # commonground-api-common # gemma-zds-client - # vng-api-common pyopenssl==23.3.0 # via # -r requirements/base.txt @@ -298,14 +346,15 @@ python-dotenv==1.0.0 pytz==2021.1 # via # -r requirements/base.txt + # celery # django pyyaml==6.0.1 # via # -r requirements/base.txt + # commonground-api-common # drf-spectacular # gemma-zds-client # oyaml - # vng-api-common qrcode==6.1 # via # -r requirements/base.txt @@ -317,11 +366,11 @@ redis==3.5.3 requests==2.25.1 # via # -r requirements/base.txt + # commonground-api-common # coreapi # gemma-zds-client # mozilla-django-oidc # requests-mock - # vng-api-common # zgw-consumers requests-mock==1.8.0 # via @@ -374,18 +423,26 @@ urllib3==1.26.6 # sentry-sdk uwsgi==2.0.21 # via -r requirements/base.txt -vng-api-common[markdown-docs]==1.8.0 +vine==5.1.0 # via # -r requirements/base.txt - # vng-api-common + # amqp + # celery + # kombu waitress==2.1.1 # via webtest +wcwidth==0.2.13 + # via + # -r requirements/base.txt + # prompt-toolkit webob==1.8.7 # via webtest webtest==2.0.35 # via django-webtest zgw-consumers==0.27.0 - # via -r requirements/base.txt + # via + # -r requirements/base.txt + # notifications-api-common # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/requirements/dev.txt b/requirements/dev.txt index 33e23f74..4ccb8d7f 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,6 +6,10 @@ # alabaster==0.7.12 # via sphinx +amqp==5.2.0 + # via + # -r requirements/ci.txt + # kombu asgiref==3.7.2 # via # -r requirements/ci.txt @@ -21,6 +25,10 @@ beautifulsoup4==4.9.3 # via # -r requirements/ci.txt # webtest +billiard==3.6.4.0 + # via + # -r requirements/ci.txt + # celery black==23.12.1 # via -r requirements/dev.in boltons==21.0.0 @@ -34,6 +42,10 @@ bump2version==1.0.1 # via bumpversion bumpversion==0.6.0 # via -r requirements/dev.in +celery==5.2.2 + # via + # -r requirements/ci.txt + # notifications-api-common certifi==2020.12.5 # via # -r requirements/ci.txt @@ -51,13 +63,35 @@ chardet==4.0.0 # requests click==8.1.7 # via + # -r requirements/ci.txt # black + # celery + # click-didyoumean + # click-plugins + # click-repl # pip-tools +click-didyoumean==0.3.0 + # via + # -r requirements/ci.txt + # celery +click-plugins==1.1.1 + # via + # -r requirements/ci.txt + # celery +click-repl==0.3.0 + # via + # -r requirements/ci.txt + # celery +commonground-api-common[markdown-docs]==1.12.1 + # via + # -r requirements/ci.txt + # commonground-api-common commonmark==0.9.1 # via recommonmark coreapi==2.3.3 # via # -r requirements/ci.txt + # commonground-api-common # drf-yasg coreschema==0.0.4 # via @@ -80,9 +114,9 @@ cssselect==1.1.0 django==3.2.23 # via # -r requirements/ci.txt + # commonground-api-common # django-admin-index # django-axes - # django-choices # django-debug-toolbar # django-extensions # django-filter @@ -105,16 +139,12 @@ django==3.2.23 # maykin-django-two-factor-auth # mozilla-django-oidc # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers django-admin-index==3.1.0 # via -r requirements/ci.txt django-axes==5.41.1 # via -r requirements/ci.txt -django-choices==2.0.0 - # via - # -r requirements/ci.txt - # vng-api-common django-debug-toolbar==4.2.0 # via -r requirements/dev.in django-extensions==3.2.3 @@ -122,7 +152,7 @@ django-extensions==3.2.3 django-filter==2.4.0 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common django-formtools==2.3 # via # -r requirements/ci.txt @@ -162,7 +192,7 @@ django-relativedelta==2.0.0 django-rest-framework-condition==0.1.1 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common django-sendfile2==0.7.0 # via # -r requirements/ci.txt @@ -174,23 +204,26 @@ django-simple-certmanager==1.4.1 django-solo==2.2.0 # via # -r requirements/ci.txt + # commonground-api-common # mozilla-django-oidc-db - # vng-api-common + # notifications-api-common # zgw-consumers django-webtest==1.9.7 # via -r requirements/ci.txt djangorestframework==3.12.4 # via # -r requirements/ci.txt + # commonground-api-common # djangorestframework-gis # drf-nested-routers # drf-spectacular # drf-yasg - # vng-api-common + # notifications-api-common djangorestframework-camel-case==1.2.0 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common + # notifications-api-common djangorestframework-gis==1.0 # via -r requirements/ci.txt docutils==0.18.1 @@ -202,13 +235,13 @@ docutils==0.18.1 drf-nested-routers==0.93.3 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common drf-spectacular==0.16.0 # via -r requirements/ci.txt drf-yasg==1.20.0 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common elastic-apm==6.1.1 # via -r requirements/ci.txt face==20.1.1 @@ -229,7 +262,8 @@ freezegun==1.1.0 gemma-zds-client==1.0.1 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common + # notifications-api-common # zgw-consumers glom==23.5.0 # via @@ -249,11 +283,11 @@ inflection==0.5.1 iso-639==0.4.5 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common isodate==0.6.0 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common isort==5.13.2 # via -r requirements/dev.in itypes==1.2.0 @@ -273,6 +307,10 @@ jsonschema==3.2.0 # via # -r requirements/ci.txt # drf-spectacular +kombu==5.3.5 + # via + # -r requirements/ci.txt + # celery lxml==4.7.1 # via # -r requirements/ci.txt @@ -297,10 +335,14 @@ mozilla-django-oidc-db==0.14.1 # via -r requirements/ci.txt mypy-extensions==0.4.3 # via black +notifications-api-common==0.2.2 + # via + # -r requirements/ci.txt + # commonground-api-common oyaml==1.0 # via # -r requirements/ci.txt - # vng-api-common + # commonground-api-common packaging==23.2 # via # -r requirements/ci.txt @@ -318,6 +360,10 @@ pip-tools==7.3.0 # via -r requirements/dev.in platformdirs==4.0.0 # via black +prompt-toolkit==3.0.43 + # via + # -r requirements/ci.txt + # click-repl psycopg2==2.8.6 # via -r requirements/ci.txt pycodestyle==2.11.1 @@ -335,8 +381,8 @@ pygments==2.17.2 pyjwt==2.4.0 # via # -r requirements/ci.txt + # commonground-api-common # gemma-zds-client - # vng-api-common pyopenssl==23.3.0 # via # -r requirements/ci.txt @@ -365,14 +411,15 @@ pytz==2021.1 # via # -r requirements/ci.txt # babel + # celery # django pyyaml==6.0.1 # via # -r requirements/ci.txt + # commonground-api-common # drf-spectacular # gemma-zds-client # oyaml - # vng-api-common qrcode==6.1 # via # -r requirements/ci.txt @@ -386,12 +433,12 @@ redis==3.5.3 requests==2.25.1 # via # -r requirements/ci.txt + # commonground-api-common # coreapi # gemma-zds-client # mozilla-django-oidc # requests-mock # sphinx - # vng-api-common # zgw-consumers requests-mock==1.8.0 # via @@ -480,14 +527,20 @@ urllib3==1.26.6 # sentry-sdk uwsgi==2.0.21 # via -r requirements/ci.txt -vng-api-common[markdown-docs]==1.8.0 +vine==5.1.0 # via # -r requirements/ci.txt - # vng-api-common + # amqp + # celery + # kombu waitress==2.1.1 # via # -r requirements/ci.txt # webtest +wcwidth==0.2.13 + # via + # -r requirements/ci.txt + # prompt-toolkit webob==1.8.7 # via # -r requirements/ci.txt @@ -499,7 +552,9 @@ webtest==2.0.35 wheel==0.42.0 # via pip-tools zgw-consumers==0.27.0 - # via -r requirements/ci.txt + # via + # -r requirements/ci.txt + # notifications-api-common # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/src/objects/api/kanalen.py b/src/objects/api/kanalen.py index 2ac56ccf..d2b29bb1 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 vng_api_common.notifications.kanalen import Kanaal +from notifications_api_common.kanalen import Kanaal from objects.core.models import ObjectRecord diff --git a/src/objects/api/mixins.py b/src/objects/api/mixins.py index dad3010d..1731b3bf 100644 --- a/src/objects/api/mixins.py +++ b/src/objects/api/mixins.py @@ -1,5 +1,10 @@ from django.db import models +from notifications_api_common.viewsets import ( + NotificationCreateMixin, + NotificationDestroyMixin, + conditional_atomic, +) from rest_framework.exceptions import NotAcceptable from rest_framework.renderers import BrowsableAPIRenderer from vng_api_common.exceptions import PreconditionFailed @@ -10,11 +15,6 @@ GeoMixin as _GeoMixin, extract_header, ) -from vng_api_common.notifications.viewsets import ( - NotificationCreateMixin, - NotificationDestroyMixin, - conditional_atomic, -) class GeoMixin(_GeoMixin): diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index 5a22c360..8661e827 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -77,7 +77,7 @@ "solo", "django_markup", "vng_api_common", - "vng_api_common.notifications", + "notifications_api_common", "simple_certmanager", "zgw_consumers", # 2fa apps diff --git a/src/objects/fixtures/default_admin_index.json b/src/objects/fixtures/default_admin_index.json index b11e8500..48aa5b94 100644 --- a/src/objects/fixtures/default_admin_index.json +++ b/src/objects/fixtures/default_admin_index.json @@ -29,7 +29,7 @@ "appgroup" ], [ - "notifications", + "notifications_api_common", "notificationsconfig" ], [ diff --git a/src/objects/tests/utils.py b/src/objects/tests/utils.py index 94f96a57..a9e0304a 100644 --- a/src/objects/tests/utils.py +++ b/src/objects/tests/utils.py @@ -2,8 +2,11 @@ import os from unittest.mock import DEFAULT +from notifications_api_common.models import NotificationsConfig from requests_mock import Mocker from zds_client.client import Client +from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.models import Service logger = logging.getLogger(__name__) @@ -98,3 +101,28 @@ def notifications_client_mock(value): if "notificaties" in value: return DEFAULT return original_from_url(value) + + +class NotificationsConfigMixin: + @classmethod + def setUpTestData(cls): + super().setUpTestData() + + cls._configure_notifications() + + @staticmethod + def _configure_notifications(api_root=None): + svc, _ = Service.objects.update_or_create( + api_root=api_root or "https://notificaties-api.vng.cloud/api/v1/", + defaults=dict( + label="Notifications API", + api_type=APITypes.nrc, + client_id="some-client-id", + secret="some-secret", + auth_type=AuthTypes.zgw, + ), + ) + config = NotificationsConfig.get_solo() + config.notifications_api_service = svc + config.notification_delivery_max_retries = 0 + config.save() diff --git a/src/objects/tests/v1/test_notifications_send.py b/src/objects/tests/v1/test_notifications_send.py index 75d4884f..d27252a7 100644 --- a/src/objects/tests/v1/test_notifications_send.py +++ b/src/objects/tests/v1/test_notifications_send.py @@ -6,26 +6,19 @@ from freezegun import freeze_time from rest_framework import status from rest_framework.test import APITestCase -from vng_api_common.notifications.models import NotificationsConfig -from zgw_consumers.constants import APITypes -from zgw_consumers.models import Service from objects.core.tests.factories import ( ObjectFactory, ObjectRecordFactory, ObjectTypeFactory, ) +from objects.tests.utils import NotificationsConfigMixin from objects.token.constants import PermissionModes from objects.token.tests.factories import PermissionFactory from objects.utils.test import TokenAuthMixin from ..constants import GEO_WRITE_KWARGS -from ..utils import ( - mock_objecttype, - mock_objecttype_version, - mock_service_oas_get, - notifications_client_mock, -) +from ..utils import mock_objecttype, mock_objecttype_version, mock_service_oas_get from .utils import reverse OBJECT_TYPES_API = "https://example.com/objecttypes/v1/" @@ -34,7 +27,7 @@ @freeze_time("2018-09-07T00:00:00Z") @override_settings(NOTIFICATIONS_DISABLED=False) @requests_mock.Mocker() -class SendNotifTestCase(TokenAuthMixin, APITestCase): +class SendNotifTestCase(NotificationsConfigMixin, TokenAuthMixin, APITestCase): @classmethod def setUpTestData(cls): super().setUpTestData() @@ -46,27 +39,11 @@ def setUpTestData(cls): token_auth=cls.token_auth, ) - def setUp(self): - super().setUp() - - config = NotificationsConfig.get_solo() - Service.objects.update_or_create( - api_root=config.api_root, - defaults=dict( - api_type=APITypes.nrc, - client_id="test", - secret="test", - user_id="test", - user_representation="Test", - ), - ) - - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_create_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_create_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -95,8 +72,7 @@ def test_send_notif_create_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -110,12 +86,11 @@ def test_send_notif_create_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_update_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_update_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -147,8 +122,7 @@ def test_send_notif_update_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -162,12 +136,11 @@ def test_send_notif_update_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_partial_update_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_partial_update_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -199,8 +172,7 @@ def test_send_notif_partial_update_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -214,12 +186,11 @@ def test_send_notif_partial_update_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_delete_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_delete_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -238,8 +209,7 @@ def test_send_notif_delete_object(self, mocker, mock_client): response.status_code, status.HTTP_204_NO_CONTENT, response.data ) - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": full_url, diff --git a/src/objects/tests/v2/test_notifications_kanaal.py b/src/objects/tests/v2/test_notifications_kanaal.py index 87764024..e754a1c6 100644 --- a/src/objects/tests/v2/test_notifications_kanaal.py +++ b/src/objects/tests/v2/test_notifications_kanaal.py @@ -5,14 +5,15 @@ from django.core.management import call_command from django.test import override_settings +from notifications_api_common.kanalen import KANAAL_REGISTRY, Kanaal from rest_framework.test import APITestCase -from vng_api_common.notifications.kanalen import Kanaal from objects.core.models import Object +from objects.tests.utils import NotificationsConfigMixin @override_settings(IS_HTTPS=True) -class CreateNotifKanaalTestCase(APITestCase): +class CreateNotifKanaalTestCase(NotificationsConfigMixin, APITestCase): @classmethod def setUpTestData(cls): super().setUpTestData() @@ -20,8 +21,13 @@ def setUpTestData(cls): site.domain = "example.com" site.save() + kanaal = Kanaal(label="dummy-kanaal", main_resource=Object) + cls.addClassCleanup(lambda: KANAAL_REGISTRY.remove(kanaal)) + + cls._configure_notifications(api_root="https://open-notificaties.local/api/v1/") + @patch( - "vng_api_common.notifications.management.commands.register_kanaal.get_client" + "notifications_api_common.management.commands.register_kanalen.NotificationsConfig.get_client" ) def test_kanaal_create_with_name(self, mock_get_client): """ @@ -29,28 +35,25 @@ def test_kanaal_create_with_name(self, mock_get_client): """ client = mock_get_client.return_value client.list.return_value = [] - # ensure this is added to the registry - Kanaal(label="kanaal_test", main_resource=Object) stdout = StringIO() call_command( - "register_kanaal", - "kanaal_test", - notificaties_api_root="https://example.com/api/v1", + "register_kanalen", + kanalen=["dummy-kanaal"], stdout=stdout, ) client.create.assert_called_once_with( "kanaal", { - "naam": "kanaal_test", - "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", + "naam": "dummy-kanaal", + "documentatieLink": "https://example.com/ref/kanalen/#dummy-kanaal", "filters": [], }, ) @patch( - "vng_api_common.notifications.management.commands.register_kanaal.get_client" + "notifications_api_common.management.commands.register_kanalen.NotificationsConfig.get_client" ) @override_settings(NOTIFICATIONS_KANAAL="dummy-kanaal") def test_kanaal_create_without_name(self, mock_get_client): @@ -59,13 +62,10 @@ def test_kanaal_create_without_name(self, mock_get_client): """ client = mock_get_client.return_value client.list.return_value = [] - # ensure this is added to the registry - Kanaal(label="dummy-kanaal", main_resource=Object) stdout = StringIO() call_command( - "register_kanaal", - notificaties_api_root="https://example.com/api/v1", + "register_kanalen", stdout=stdout, ) diff --git a/src/objects/tests/v2/test_notifications_send.py b/src/objects/tests/v2/test_notifications_send.py index 75d4884f..0b0ed0b2 100644 --- a/src/objects/tests/v2/test_notifications_send.py +++ b/src/objects/tests/v2/test_notifications_send.py @@ -4,9 +4,9 @@ import requests_mock from freezegun import freeze_time +from notifications_api_common.models import NotificationsConfig from rest_framework import status from rest_framework.test import APITestCase -from vng_api_common.notifications.models import NotificationsConfig from zgw_consumers.constants import APITypes from zgw_consumers.models import Service @@ -15,17 +15,13 @@ ObjectRecordFactory, ObjectTypeFactory, ) +from objects.tests.utils import NotificationsConfigMixin from objects.token.constants import PermissionModes from objects.token.tests.factories import PermissionFactory from objects.utils.test import TokenAuthMixin from ..constants import GEO_WRITE_KWARGS -from ..utils import ( - mock_objecttype, - mock_objecttype_version, - mock_service_oas_get, - notifications_client_mock, -) +from ..utils import mock_objecttype, mock_objecttype_version, mock_service_oas_get from .utils import reverse OBJECT_TYPES_API = "https://example.com/objecttypes/v1/" @@ -34,7 +30,7 @@ @freeze_time("2018-09-07T00:00:00Z") @override_settings(NOTIFICATIONS_DISABLED=False) @requests_mock.Mocker() -class SendNotifTestCase(TokenAuthMixin, APITestCase): +class SendNotifTestCase(NotificationsConfigMixin, TokenAuthMixin, APITestCase): @classmethod def setUpTestData(cls): super().setUpTestData() @@ -50,8 +46,8 @@ def setUp(self): super().setUp() config = NotificationsConfig.get_solo() - Service.objects.update_or_create( - api_root=config.api_root, + service, _ = Service.objects.update_or_create( + api_root="https://notificaties-api.vng.cloud/api/v1/", defaults=dict( api_type=APITypes.nrc, client_id="test", @@ -60,13 +56,14 @@ def setUp(self): user_representation="Test", ), ) + config.notifications_api_service = service + config.save() - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_create_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_create_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -95,8 +92,7 @@ def test_send_notif_create_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -110,12 +106,11 @@ def test_send_notif_create_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_update_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_update_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -147,8 +142,7 @@ def test_send_notif_update_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -162,12 +156,11 @@ def test_send_notif_update_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_partial_update_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_partial_update_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -199,8 +192,7 @@ def test_send_notif_partial_update_object(self, mocker, mock_client): data = response.json() - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": data["url"], @@ -214,12 +206,11 @@ def test_send_notif_partial_update_object(self, mocker, mock_client): }, ) - @patch("zds_client.Client.from_url", side_effect=notifications_client_mock) - def test_send_notif_delete_object(self, mocker, mock_client): + @patch("notifications_api_common.viewsets.send_notification.delay") + def test_send_notif_delete_object(self, mocker, mock_notif): """ Check if notifications will be send when Object is created """ - client = mock_client.return_value mock_service_oas_get(mocker, OBJECT_TYPES_API, "objecttypes") mocker.get( f"{self.object_type.url}/versions/1", @@ -238,8 +229,7 @@ def test_send_notif_delete_object(self, mocker, mock_client): response.status_code, status.HTTP_204_NO_CONTENT, response.data ) - client.create.assert_called_once_with( - "notificaties", + mock_notif.assert_called_once_with( { "kanaal": "objecten", "hoofdObject": full_url, diff --git a/src/objects/urls.py b/src/objects/urls.py index 4413dcb8..42833103 100644 --- a/src/objects/urls.py +++ b/src/objects/urls.py @@ -45,7 +45,7 @@ ), ), path("ref/", include("vng_api_common.urls")), - path("ref/", include("vng_api_common.notifications.urls")), + path("ref/", include("notifications_api_common.urls")), path("oidc/", include("mozilla_django_oidc.urls")), path("api/", include("objects.api.urls")), ]