From 329cc5901e1faf70c13af20c93f8e78c6855ec7a Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 25 Nov 2024 17:51:20 +0100 Subject: [PATCH 1/4] :arrow_up: [https://github.com/maykinmedia/open-api-framework/issues/66] bump zgw-consumers to 0.35.1, commonground-api-common to 2.0.1, OAF to 0.9.0 --- requirements/base.in | 1 + requirements/base.txt | 35 +++++++++++++++++++---------------- requirements/ci.txt | 31 ++++++++++++++----------------- requirements/dev.txt | 31 ++++++++++++++----------------- 4 files changed, 48 insertions(+), 50 deletions(-) diff --git a/requirements/base.in b/requirements/base.in index 1912e5b4..a88abd9e 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,4 +1,5 @@ open-api-framework +git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error # Core python libraries glom # data represenation based on spec diff --git a/requirements/base.txt b/requirements/base.txt index a0982bfc..05caff0c 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -7,7 +7,10 @@ amqp==5.2.0 # via kombu ape-pie==0.2.0 - # via zgw-consumers + # via + # commonground-api-common + # notifications-api-common + # zgw-consumers asgiref==3.7.2 # via # django @@ -56,8 +59,10 @@ click-plugins==1.1.1 # via celery click-repl==0.3.0 # via celery -commonground-api-common==1.13.0 - # via open-api-framework +commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error + # via + # -r requirements/base.in + # open-api-framework coreapi==2.3.3 # via commonground-api-common coreschema==0.0.4 @@ -179,7 +184,7 @@ djangorestframework-gis==1.0 # via open-api-framework djangorestframework-inclusions==1.2.0 # via open-api-framework -drf-nested-routers==0.93.3 +drf-nested-routers==0.94.1 # via commonground-api-common drf-spectacular[sidecar]==0.27.2 # via open-api-framework @@ -199,11 +204,6 @@ furl==2.1.3 # via # -r requirements/base.in # ape-pie -gemma-zds-client==2.0.0 - # via - # commonground-api-common - # notifications-api-common - # zgw-consumers glom==23.5.0 # via # -r requirements/base.in @@ -240,7 +240,7 @@ mozilla-django-oidc==4.0.0 # via mozilla-django-oidc-db mozilla-django-oidc-db==0.19.0 # via open-api-framework -notifications-api-common==0.2.2 +notifications-api-common==0.3.0 # via # -r requirements/base.in # commonground-api-common @@ -265,13 +265,12 @@ pycparser==2.20 pyjwt==2.4.0 # via # commonground-api-common - # gemma-zds-client + # zgw-consumers pyopenssl==24.0.0 # via # django-simple-certmanager # josepy # webauthn - # zgw-consumers pyrsistent==0.17.3 # via jsonschema python-dateutil==2.9.0.post0 @@ -290,7 +289,6 @@ pyyaml==6.0.1 # via # drf-spectacular # drf-yasg - # gemma-zds-client # oyaml qrcode==6.1 # via django-two-factor-auth @@ -302,10 +300,12 @@ requests==2.32.3 # commonground-api-common # coreapi # django-log-outgoing-requests - # gemma-zds-client # mozilla-django-oidc # open-api-framework + # requests-mock # zgw-consumers +requests-mock==1.12.1 + # via commonground-api-common sentry-sdk==2.12.0 # via open-api-framework six==1.16.0 @@ -321,7 +321,9 @@ sqlparse==0.5.0 tornado==6.4.1 # via flower typing-extensions==4.9.0 - # via mozilla-django-oidc-db + # via + # mozilla-django-oidc-db + # zgw-consumers tzdata==2024.1 # via celery uritemplate==3.0.1 @@ -349,8 +351,9 @@ webencodings==0.5.1 # via bleach wrapt==1.14.1 # via elastic-apm -zgw-consumers==0.29.0 +zgw-consumers==0.35.1 # via + # commonground-api-common # notifications-api-common # open-api-framework diff --git a/requirements/ci.txt b/requirements/ci.txt index 136a4c7f..dfaa0cfc 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -11,6 +11,8 @@ amqp==5.2.0 ape-pie==0.2.0 # via # -r requirements/base.txt + # commonground-api-common + # notifications-api-common # zgw-consumers asgiref==3.7.2 # via @@ -91,7 +93,7 @@ click-repl==0.3.0 # celery codecov==2.1.13 # via -r requirements/ci.in -commonground-api-common==1.13.0 +commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error # via # -r requirements/base.txt # open-api-framework @@ -279,7 +281,7 @@ djangorestframework-inclusions==1.2.0 # via # -r requirements/base.txt # open-api-framework -drf-nested-routers==0.93.3 +drf-nested-routers==0.94.1 # via # -r requirements/base.txt # commonground-api-common @@ -323,12 +325,6 @@ furl==2.1.3 # via # -r requirements/base.txt # ape-pie -gemma-zds-client==2.0.0 - # via - # -r requirements/base.txt - # commonground-api-common - # notifications-api-common - # zgw-consumers glom==23.5.0 # via # -r requirements/base.txt @@ -403,7 +399,7 @@ multidict==6.0.5 # via yarl mypy-extensions==1.0.0 # via black -notifications-api-common==0.2.2 +notifications-api-common==0.3.0 # via # -r requirements/base.txt # commonground-api-common @@ -457,14 +453,13 @@ pyjwt==2.4.0 # via # -r requirements/base.txt # commonground-api-common - # gemma-zds-client + # zgw-consumers pyopenssl==24.0.0 # via # -r requirements/base.txt # django-simple-certmanager # josepy # webauthn - # zgw-consumers pyquery==1.4.3 # via -r requirements/test-tools.in pyrsistent==0.17.3 @@ -498,7 +493,6 @@ pyyaml==6.0.1 # -r requirements/base.txt # drf-spectacular # drf-yasg - # gemma-zds-client # oyaml # vcrpy qrcode==6.1 @@ -517,13 +511,15 @@ requests==2.32.3 # commonground-api-common # coreapi # django-log-outgoing-requests - # gemma-zds-client # mozilla-django-oidc # open-api-framework # requests-mock # zgw-consumers -requests-mock==1.8.0 - # via -r requirements/test-tools.in +requests-mock==1.12.1 + # via + # -r requirements/base.txt + # -r requirements/test-tools.in + # commonground-api-common sentry-sdk==2.12.0 # via # -r requirements/base.txt @@ -537,7 +533,6 @@ six==1.16.0 # orderedmultidict # python-dateutil # qrcode - # requests-mock # webtest soupsieve==2.2.1 # via beautifulsoup4 @@ -557,6 +552,7 @@ typing-extensions==4.9.0 # via # -r requirements/base.txt # mozilla-django-oidc-db + # zgw-consumers tzdata==2024.1 # via # -r requirements/base.txt @@ -610,9 +606,10 @@ wrapt==1.14.1 # vcrpy yarl==1.9.4 # via vcrpy -zgw-consumers==0.29.0 +zgw-consumers==0.35.1 # via # -r requirements/base.txt + # commonground-api-common # notifications-api-common # open-api-framework diff --git a/requirements/dev.txt b/requirements/dev.txt index e6871c65..dd6e0554 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -13,6 +13,8 @@ amqp==5.2.0 ape-pie==0.2.0 # via # -r requirements/base.txt + # commonground-api-common + # notifications-api-common # zgw-consumers asgiref==3.7.2 # via @@ -100,7 +102,7 @@ click-repl==0.3.0 # via # -r requirements/base.txt # celery -commonground-api-common==1.13.0 +commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error # via # -r requirements/base.txt # open-api-framework @@ -300,7 +302,7 @@ docutils==0.18.1 # sphinx # sphinx-rtd-theme # sphinx-tabs -drf-nested-routers==0.93.3 +drf-nested-routers==0.94.1 # via # -r requirements/base.txt # commonground-api-common @@ -344,12 +346,6 @@ furl==2.1.3 # via # -r requirements/base.txt # ape-pie -gemma-zds-client==2.0.0 - # via - # -r requirements/base.txt - # commonground-api-common - # notifications-api-common - # zgw-consumers glom==23.5.0 # via # -r requirements/base.txt @@ -425,7 +421,7 @@ multidict==6.0.5 # via yarl mypy-extensions==0.4.3 # via black -notifications-api-common==0.2.2 +notifications-api-common==0.3.0 # via # -r requirements/base.txt # commonground-api-common @@ -484,14 +480,13 @@ pyjwt==2.4.0 # via # -r requirements/base.txt # commonground-api-common - # gemma-zds-client + # zgw-consumers pyopenssl==24.0.0 # via # -r requirements/base.txt # django-simple-certmanager # josepy # webauthn - # zgw-consumers pyproject-hooks==1.0.0 # via # build @@ -528,7 +523,6 @@ pyyaml==6.0.1 # -r requirements/base.txt # drf-spectacular # drf-yasg - # gemma-zds-client # oyaml # vcrpy qrcode==6.1 @@ -548,14 +542,16 @@ requests==2.32.3 # commonground-api-common # coreapi # django-log-outgoing-requests - # gemma-zds-client # mozilla-django-oidc # open-api-framework # requests-mock # sphinx # zgw-consumers -requests-mock==1.8.0 - # via -r requirements/test-tools.in +requests-mock==1.12.1 + # via + # -r requirements/base.txt + # -r requirements/test-tools.in + # commonground-api-common sentry-sdk==2.12.0 # via # -r requirements/base.txt @@ -569,7 +565,6 @@ six==1.16.0 # orderedmultidict # python-dateutil # qrcode - # requests-mock # webtest snowballstemmer==2.1.0 # via sphinx @@ -617,6 +612,7 @@ typing-extensions==4.9.0 # via # -r requirements/base.txt # mozilla-django-oidc-db + # zgw-consumers tzdata==2024.1 # via # -r requirements/base.txt @@ -672,9 +668,10 @@ wrapt==1.14.1 # vcrpy yarl==1.9.4 # via vcrpy -zgw-consumers==0.29.0 +zgw-consumers==0.35.1 # via # -r requirements/base.txt + # commonground-api-common # notifications-api-common # open-api-framework From ad08c3828f2fb334b07a44e2f7e911d5bb0541c3 Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Mon, 25 Nov 2024 18:08:48 +0100 Subject: [PATCH 2/4] :recycle: [https://github.com/maykinmedia/open-api-framework/issues/66] update old tests with new client --- src/objects/conf/base.py | 4 ---- src/objects/core/tests/factories.py | 13 +------------ src/objects/fixtures/demodata.json | 1 + .../tests/commands/test_setup_configuration.py | 8 ++++++-- src/objects/tests/v2/test_notifications_kanaal.py | 14 +++++++------- src/objects/utils/client.py | 7 ------- 6 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 src/objects/utils/client.py diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index 479c6d90..be71aeec 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -66,10 +66,6 @@ # Relying Party name for WebAuthn (hardware tokens) TWO_FACTOR_WEBAUTHN_RP_NAME = "objects api" - -# VNG API Common -CUSTOM_CLIENT_FETCHER = "objects.utils.client.get_client" - # settings for sending notifications NOTIFICATIONS_KANAAL = "objecten" diff --git a/src/objects/core/tests/factories.py b/src/objects/core/tests/factories.py index 88c55c98..685819be 100644 --- a/src/objects/core/tests/factories.py +++ b/src/objects/core/tests/factories.py @@ -6,22 +6,11 @@ import factory from factory.fuzzy import BaseFuzzyAttribute -from zgw_consumers.constants import APITypes, AuthTypes -from zgw_consumers.models import Service +from zgw_consumers.test.factories import ServiceFactory from ..models import Object, ObjectRecord, ObjectType -class ServiceFactory(factory.django.DjangoModelFactory): - label = factory.Faker("word") - api_root = factory.Faker("url") - api_type = APITypes.orc - auth_type = AuthTypes.no_auth - - class Meta: - model = Service - - class ObjectTypeFactory(factory.django.DjangoModelFactory): service = factory.SubFactory(ServiceFactory) uuid = factory.LazyFunction(uuid.uuid4) diff --git a/src/objects/fixtures/demodata.json b/src/objects/fixtures/demodata.json index 94250aa8..c832bf5b 100644 --- a/src/objects/fixtures/demodata.json +++ b/src/objects/fixtures/demodata.json @@ -805,6 +805,7 @@ "pk": 1, "fields": { "label": "Objecttypen API", + "slug": "objecttypen-api", "api_type": "orc", "api_root": "http://localhost:8001/api/v1/", "client_id": "", diff --git a/src/objects/tests/commands/test_setup_configuration.py b/src/objects/tests/commands/test_setup_configuration.py index d8554a31..61b0d656 100644 --- a/src/objects/tests/commands/test_setup_configuration.py +++ b/src/objects/tests/commands/test_setup_configuration.py @@ -7,6 +7,7 @@ import requests_mock from rest_framework import status +from zgw_consumers.client import build_client from zgw_consumers.models import Service from objects.config.demo import DemoUserStep @@ -70,10 +71,13 @@ def test_setup_configuration(self, m): self.assertEqual(site.name, "Objects ACME") with self.subTest("Objects can query Objecttypes API"): - client = Service.get_client("https://objecttypes.example.com/api/v2/") + client = build_client( + Service.objects.get(api_root="https://objecttypes.example.com/api/v2/") + ) + self.assertIsNotNone(client) - client.list("objecttype") + client.get("objecttypes") list_call = m.last_request self.assertEqual( diff --git a/src/objects/tests/v2/test_notifications_kanaal.py b/src/objects/tests/v2/test_notifications_kanaal.py index 7f0cda20..35c0e03c 100644 --- a/src/objects/tests/v2/test_notifications_kanaal.py +++ b/src/objects/tests/v2/test_notifications_kanaal.py @@ -47,7 +47,7 @@ def test_kanaal_create_with_name(self, mock_get_client): Test is request to create kanaal is send with specified kanaal name """ client = mock_get_client.return_value - client.list.return_value = [] + client.get.return_value = [] stdout = StringIO() call_command( @@ -56,9 +56,9 @@ def test_kanaal_create_with_name(self, mock_get_client): stdout=stdout, ) - client.create.assert_called_once_with( + client.post.assert_called_once_with( "kanaal", - { + json={ "naam": "kanaal_test", "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", "filters": [], @@ -72,7 +72,7 @@ def test_kanaal_create_without_name(self, mock_get_client): Test is request to create kanaal is send with default kanaal name """ client = mock_get_client.return_value - client.list.return_value = [] + client.get.return_value = [] stdout = StringIO() call_command( @@ -80,11 +80,11 @@ def test_kanaal_create_without_name(self, mock_get_client): stdout=stdout, ) - client.create.assert_has_calls( + client.post.assert_has_calls( [ call( "kanaal", - { + json={ "naam": "kanaal_test", "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", "filters": [], @@ -92,7 +92,7 @@ def test_kanaal_create_without_name(self, mock_get_client): ), call( "kanaal", - { + json={ "naam": "objecten", "documentatieLink": "https://example.com/ref/kanalen/#objecten", "filters": ["object_type"], diff --git a/src/objects/utils/client.py b/src/objects/utils/client.py deleted file mode 100644 index 9e1b8d21..00000000 --- a/src/objects/utils/client.py +++ /dev/null @@ -1,7 +0,0 @@ -from zgw_consumers.client import ZGWClient -from zgw_consumers.models import Service - - -def get_client(url: str) -> ZGWClient | None: - client = Service.get_client(url) - return client From 14137d186da58021c334966601fd150c525e4b5c Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Fri, 29 Nov 2024 16:04:34 +0100 Subject: [PATCH 3/4] :arrow_up: [https://github.com/maykinmedia/open-api-framework/issues/66] bump commonground-api-common to 2.1.0 --- requirements/base.in | 1 - requirements/base.txt | 8 +++----- requirements/ci.txt | 4 ++-- requirements/dev.txt | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/requirements/base.in b/requirements/base.in index a88abd9e..1912e5b4 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,5 +1,4 @@ open-api-framework -git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error # Core python libraries glom # data represenation based on spec diff --git a/requirements/base.txt b/requirements/base.txt index 05caff0c..d4cf6b3e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -59,10 +59,8 @@ click-plugins==1.1.1 # via celery click-repl==0.3.0 # via celery -commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error - # via - # -r requirements/base.in - # open-api-framework +commonground-api-common==2.1.0 + # via open-api-framework coreapi==2.3.3 # via commonground-api-common coreschema==0.0.4 @@ -240,7 +238,7 @@ mozilla-django-oidc==4.0.0 # via mozilla-django-oidc-db mozilla-django-oidc-db==0.19.0 # via open-api-framework -notifications-api-common==0.3.0 +notifications-api-common==0.3.1 # via # -r requirements/base.in # commonground-api-common diff --git a/requirements/ci.txt b/requirements/ci.txt index dfaa0cfc..a9bab76e 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -93,7 +93,7 @@ click-repl==0.3.0 # celery codecov==2.1.13 # via -r requirements/ci.in -commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error +commonground-api-common==2.1.0 # via # -r requirements/base.txt # open-api-framework @@ -399,7 +399,7 @@ multidict==6.0.5 # via yarl mypy-extensions==1.0.0 # via black -notifications-api-common==0.3.0 +notifications-api-common==0.3.1 # via # -r requirements/base.txt # commonground-api-common diff --git a/requirements/dev.txt b/requirements/dev.txt index dd6e0554..8a115576 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -102,7 +102,7 @@ click-repl==0.3.0 # via # -r requirements/base.txt # celery -commonground-api-common @ git+https://github.com/maykinmedia/commonground-api-common.git@issue/44-migration-error +commonground-api-common==2.1.0 # via # -r requirements/base.txt # open-api-framework @@ -421,7 +421,7 @@ multidict==6.0.5 # via yarl mypy-extensions==0.4.3 # via black -notifications-api-common==0.3.0 +notifications-api-common==0.3.1 # via # -r requirements/base.txt # commonground-api-common From e0ff5022512cb2be0c8f74bafd495e5c57b29d78 Mon Sep 17 00:00:00 2001 From: Anna Shamray Date: Fri, 29 Nov 2024 16:05:18 +0100 Subject: [PATCH 4/4] :ok_hand: [https://github.com/maykinmedia/open-api-framework/issues/66] change mocks for 'register_kanalen' tests --- .../tests/v2/test_notifications_kanaal.py | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/objects/tests/v2/test_notifications_kanaal.py b/src/objects/tests/v2/test_notifications_kanaal.py index 35c0e03c..0f61d91b 100644 --- a/src/objects/tests/v2/test_notifications_kanaal.py +++ b/src/objects/tests/v2/test_notifications_kanaal.py @@ -1,10 +1,10 @@ from io import StringIO -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 +import requests_mock from notifications_api_common.kanalen import KANAAL_REGISTRY from notifications_api_common.models import NotificationsConfig from rest_framework.test import APITestCase @@ -14,6 +14,8 @@ from objects.api.kanalen import ObjectKanaal from objects.core.models import Object +NOTIFICATIONS_API_ROOT = "https://notificaties-api.vng.cloud/api/v1/" + @override_settings(IS_HTTPS=True) class CreateNotifKanaalTestCase(APITestCase): @@ -28,7 +30,7 @@ def setUpTestData(cls): cls.addClassCleanup(lambda: KANAAL_REGISTRY.remove(kanaal)) service, _ = Service.objects.update_or_create( - api_root="https://notificaties-api.vng.cloud/api/v1/", + api_root=NOTIFICATIONS_API_ROOT, defaults=dict( api_type=APITypes.nrc, client_id="test", @@ -41,13 +43,13 @@ def setUpTestData(cls): config.notifications_api_service = service config.save() - @patch("notifications_api_common.models.NotificationsConfig.get_client") - def test_kanaal_create_with_name(self, mock_get_client): + @requests_mock.Mocker() + def test_kanaal_create_with_name(self, m): """ Test is request to create kanaal is send with specified kanaal name """ - client = mock_get_client.return_value - client.get.return_value = [] + m.get(f"{NOTIFICATIONS_API_ROOT}kanaal?naam=kanaal_test", json=[]) + m.post(f"{NOTIFICATIONS_API_ROOT}kanaal") stdout = StringIO() call_command( @@ -56,23 +58,25 @@ def test_kanaal_create_with_name(self, mock_get_client): stdout=stdout, ) - client.post.assert_called_once_with( - "kanaal", - json={ + self.assertEqual(m.last_request.url, f"{NOTIFICATIONS_API_ROOT}kanaal") + self.assertEqual(m.last_request.method, "POST") + self.assertEqual( + m.last_request.json(), + { "naam": "kanaal_test", "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", "filters": [], }, ) - @patch("notifications_api_common.models.NotificationsConfig.get_client") @override_settings(NOTIFICATIONS_KANAAL="dummy-kanaal") - def test_kanaal_create_without_name(self, mock_get_client): + @requests_mock.Mocker() + def test_kanaal_create_without_name(self, m): """ Test is request to create kanaal is send with default kanaal name """ - client = mock_get_client.return_value - client.get.return_value = [] + m.get(f"{NOTIFICATIONS_API_ROOT}kanaal", json=[]) + m.post(f"{NOTIFICATIONS_API_ROOT}kanaal") stdout = StringIO() call_command( @@ -80,23 +84,24 @@ def test_kanaal_create_without_name(self, mock_get_client): stdout=stdout, ) - client.post.assert_has_calls( - [ - call( - "kanaal", - json={ - "naam": "kanaal_test", - "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", - "filters": [], - }, - ), - call( - "kanaal", - json={ - "naam": "objecten", - "documentatieLink": "https://example.com/ref/kanalen/#objecten", - "filters": ["object_type"], - }, - ), - ] + post_req1, post_req2 = [ + req + for req in m.request_history + if req.method == "POST" and req.url == f"{NOTIFICATIONS_API_ROOT}kanaal" + ] + self.assertEqual( + post_req1.json(), + { + "naam": "kanaal_test", + "documentatieLink": "https://example.com/ref/kanalen/#kanaal_test", + "filters": [], + }, + ) + self.assertEqual( + post_req2.json(), + { + "naam": "objecten", + "documentatieLink": "https://example.com/ref/kanalen/#objecten", + "filters": ["object_type"], + }, )