diff --git a/docs/conf.py b/docs/conf.py index 35fc26c01b..d19522cb1e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -74,6 +74,10 @@ "http://docs.djangoproject.com/en/3.2/", "http://docs.djangoproject.com/en/3.2/_objects/", ), + "zgw_consumers": ( + "https://zgw-consumers.readthedocs.io/en/latest/", + None, + ), } # -- Options for HTML output ------------------------------------------------- diff --git a/docs/developers/backend/api-clients.rst b/docs/developers/backend/api-clients.rst index e9daff934b..17729552b8 100644 --- a/docs/developers/backend/api-clients.rst +++ b/docs/developers/backend/api-clients.rst @@ -50,7 +50,7 @@ Such a factory must implemented the :class:`ape_pie.ConfigAdapter` protocol. Some examples that can serve as a reference: -* :class:`zgw_consumers_ext.ape_pie.ServiceClientFactory` +* :class:`zgw_consumers.client.ServiceConfigAdapter` * :class:`soap.client.session_factory.SessionFactory` * :class:`stuf.service_client_factory.ServiceClientFactory` @@ -61,8 +61,9 @@ Reference ZGW-consumers (JSON-based/RESTful services) ------------------------------------------- -.. automodule:: zgw_consumers_ext.api_client - :members: +See the `zgw-consumers`_ documentation. + +.. _zgw-consumers: https://zgw-consumers.readthedocs.io/en/latest/ Zeep (SOAP client) ------------------ diff --git a/requirements/ci.txt b/requirements/ci.txt index a3a5e6a3cf..4da92af82d 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -423,8 +423,11 @@ factory-boy==3.0.1 # via # -r requirements/test-tools.in # django-simple-certmanager + # zgw-consumers faker==7.0.1 - # via factory-boy + # via + # factory-boy + # zgw-consumers flake8==6.0.0 # via -r requirements/test-tools.in flower==1.2.0 @@ -812,7 +815,9 @@ requests-file==1.5.1 # -r requirements/base.txt # zeep requests-mock==1.8.0 - # via -r requirements/test-tools.in + # via + # -r requirements/test-tools.in + # zgw-consumers requests-oauthlib==1.3.0 # via # -c requirements/base.txt @@ -1036,10 +1041,11 @@ zeep==4.2.1 # via # -c requirements/base.txt # -r requirements/base.txt -zgw-consumers==0.28.0 +zgw-consumers[testutils]==0.28.0 # via # -c requirements/base.txt # -r requirements/base.txt + # -r requirements/test-tools.in zopfli==0.2.3 # via # -c requirements/base.txt diff --git a/requirements/dev.txt b/requirements/dev.txt index a2db52443f..b4e7dc84c0 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -469,11 +469,13 @@ factory-boy==3.0.1 # -c requirements/ci.txt # -r requirements/ci.txt # django-simple-certmanager + # zgw-consumers faker==7.0.1 # via # -c requirements/ci.txt # -r requirements/ci.txt # factory-boy + # zgw-consumers flake8==6.0.0 # via # -c requirements/ci.txt @@ -947,6 +949,7 @@ requests-mock==1.8.0 # -c requirements/ci.txt # -r requirements/ci.txt # ddt-api-calls + # zgw-consumers requests-oauthlib==1.3.0 # via # -c requirements/ci.txt @@ -1237,10 +1240,11 @@ zeep==4.2.1 # via # -c requirements/ci.txt # -r requirements/ci.txt -zgw-consumers==0.28.0 +zgw-consumers[testutils]==0.28.0 # via # -c requirements/ci.txt # -r requirements/ci.txt + # zgw-consumers zopfli==0.2.3 # via # -c requirements/ci.txt diff --git a/requirements/extensions.txt b/requirements/extensions.txt index dc44d8e803..c2fbe22c2e 100644 --- a/requirements/extensions.txt +++ b/requirements/extensions.txt @@ -488,7 +488,7 @@ oauthlib==3.2.2 # via # -r requirements/base.txt # requests-oauthlib -open-forms-ext-haalcentraal-hr==0.2.0 +open-forms-ext-haalcentraal-hr==0.3.0 # via -r requirements/extensions.in open-forms-ext-token-exchange==0.4.0 # via -r requirements/extensions.in diff --git a/requirements/test-tools.in b/requirements/test-tools.in index 7d9275605d..6ec54360fe 100644 --- a/requirements/test-tools.in +++ b/requirements/test-tools.in @@ -16,6 +16,7 @@ pep8 pytest # documentation tests hypothesis # property-based testing vcrpy # record HTTP fixtures +zgw-consumers[testutils] # Code formatting black diff --git a/src/openforms/appointments/contrib/qmatic/client.py b/src/openforms/appointments/contrib/qmatic/client.py index 94ea378ab3..744132ba5a 100644 --- a/src/openforms/appointments/contrib/qmatic/client.py +++ b/src/openforms/appointments/contrib/qmatic/client.py @@ -4,10 +4,9 @@ import pytz from ape_pie.client import APIClient from dateutil.parser import isoparse +from zgw_consumers.client import build_client from zgw_consumers.models import Service -from zgw_consumers_ext.api_client import ServiceClientFactory - from .exceptions import QmaticException from .models import QmaticConfig @@ -79,8 +78,7 @@ def QmaticClient() -> "Client": if (service := config.service) is None: raise NoServiceConfigured("No Qmatic service defined, aborting!") assert isinstance(service, Service) - service_client_factory = ServiceClientFactory(service) - return Client.configure_from(service_client_factory) + return build_client(service, client_factory=Client) def startswith_version(url: str) -> bool: diff --git a/src/openforms/appointments/contrib/qmatic/tests/factories.py b/src/openforms/appointments/contrib/qmatic/tests/factories.py index e78c7d9bc4..f3ed17bcc7 100644 --- a/src/openforms/appointments/contrib/qmatic/tests/factories.py +++ b/src/openforms/appointments/contrib/qmatic/tests/factories.py @@ -1,7 +1,6 @@ import factory from zgw_consumers.constants import APITypes - -from zgw_consumers_ext.tests.factories import ServiceFactory as _ServiceFactory +from zgw_consumers.test.factories import ServiceFactory as _ServiceFactory from ..models import QmaticConfig diff --git a/src/openforms/contrib/brk/client.py b/src/openforms/contrib/brk/client.py index d31e089599..9793405ea6 100644 --- a/src/openforms/contrib/brk/client.py +++ b/src/openforms/contrib/brk/client.py @@ -3,8 +3,7 @@ import requests from typing_extensions import NotRequired - -from zgw_consumers_ext.api_client import ServiceClientFactory +from zgw_consumers.client import build_client from ..hal_client import HALClient from .models import BRKConfig @@ -21,8 +20,7 @@ def get_client() -> "BRKClient": assert isinstance(config, BRKConfig) if not (service := config.service): raise NoServiceConfigured("No BRK service configured!") - service_client_factory = ServiceClientFactory(service) - return BRKClient.configure_from(service_client_factory) + return build_client(service, client_factory=BRKClient) class SearchParams(TypedDict): diff --git a/src/openforms/contrib/brk/tests/base.py b/src/openforms/contrib/brk/tests/base.py index 4bcf021428..51a37b25b3 100644 --- a/src/openforms/contrib/brk/tests/base.py +++ b/src/openforms/contrib/brk/tests/base.py @@ -3,9 +3,9 @@ from unittest.mock import patch from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.test.factories import ServiceFactory from openforms.contrib.brk.models import BRKConfig -from zgw_consumers_ext.tests.factories import ServiceFactory TEST_FILES = Path(__file__).parent.resolve() / "files" BRK_API_KEY = os.getenv("BRK_API_KEY", "placeholder_key") diff --git a/src/openforms/contrib/haal_centraal/clients/__init__.py b/src/openforms/contrib/haal_centraal/clients/__init__.py index 91f0359c22..b38178fab1 100644 --- a/src/openforms/contrib/haal_centraal/clients/__init__.py +++ b/src/openforms/contrib/haal_centraal/clients/__init__.py @@ -1,9 +1,10 @@ from typing import Any +from zgw_consumers.client import build_client + from openforms.authentication.constants import AuthAttribute from openforms.config.models import GlobalConfiguration from openforms.submissions.models import Submission -from zgw_consumers_ext.api_client import build_client from ..constants import DEFAULT_HC_BRP_PERSONEN_GEBRUIKER_HEADER from ..models import BRPPersonenRequestOptions, HaalCentraalConfig diff --git a/src/openforms/contrib/haal_centraal/tests/factories.py b/src/openforms/contrib/haal_centraal/tests/factories.py index b4a53ac25d..fa14ca4c20 100644 --- a/src/openforms/contrib/haal_centraal/tests/factories.py +++ b/src/openforms/contrib/haal_centraal/tests/factories.py @@ -5,8 +5,7 @@ from factory.django import DjangoModelFactory from simple_certmanager.constants import CertificateTypes from zgw_consumers.constants import AuthTypes - -from zgw_consumers_ext.tests.factories import ServiceFactory +from zgw_consumers.test.factories import ServiceFactory from ..constants import BRPVersions from ..models import HaalCentraalConfig diff --git a/src/openforms/contrib/haal_centraal/tests/test_brp_clients.py b/src/openforms/contrib/haal_centraal/tests/test_brp_clients.py index d0ac7700c0..d000eecfff 100644 --- a/src/openforms/contrib/haal_centraal/tests/test_brp_clients.py +++ b/src/openforms/contrib/haal_centraal/tests/test_brp_clients.py @@ -4,12 +4,12 @@ import requests_mock from glom import glom +from zgw_consumers.test.factories import ServiceFactory from openforms.authentication.constants import AuthAttribute from openforms.authentication.utils import store_registrator_details from openforms.config.models import GlobalConfiguration from openforms.submissions.tests.factories import SubmissionFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ..clients import get_brp_client from ..constants import DEFAULT_HC_BRP_PERSONEN_GEBRUIKER_HEADER, BRPVersions diff --git a/src/openforms/contrib/kadaster/clients/__init__.py b/src/openforms/contrib/kadaster/clients/__init__.py index d66b91cc92..d952af997a 100644 --- a/src/openforms/contrib/kadaster/clients/__init__.py +++ b/src/openforms/contrib/kadaster/clients/__init__.py @@ -1,4 +1,4 @@ -from zgw_consumers_ext.api_client import ServiceClientFactory +from zgw_consumers.client import build_client from ..models import KadasterApiConfig from .bag import BAGClient @@ -14,8 +14,7 @@ def get_locatieserver_client() -> LocatieServerClient: assert isinstance(config, KadasterApiConfig) # model field is not nullable because a default is configured assert (service := config.search_service) - service_client_factory = ServiceClientFactory(service) - return LocatieServerClient.configure_from(service_client_factory) + return build_client(service, client_factory=LocatieServerClient) def get_bag_client() -> BAGClient: @@ -23,5 +22,4 @@ def get_bag_client() -> BAGClient: assert isinstance(config, KadasterApiConfig) if not (service := config.bag_service): raise NoServiceConfigured("No BAG service configured!") - service_client_factory = ServiceClientFactory(service) - return BAGClient.configure_from(service_client_factory) + return build_client(service, client_factory=BAGClient) diff --git a/src/openforms/contrib/kadaster/tests/test_api_address_autocomplete.py b/src/openforms/contrib/kadaster/tests/test_api_address_autocomplete.py index e78544c98b..b6a6f7b1f9 100644 --- a/src/openforms/contrib/kadaster/tests/test_api_address_autocomplete.py +++ b/src/openforms/contrib/kadaster/tests/test_api_address_autocomplete.py @@ -7,10 +7,10 @@ from django.utils.translation import gettext_lazy as _ import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.submissions.tests.factories import SubmissionFactory from openforms.submissions.tests.mixins import SubmissionsMixin -from zgw_consumers_ext.tests.factories import ServiceFactory from ..clients.bag import AddressResult from ..models import KadasterApiConfig diff --git a/src/openforms/contrib/kadaster/tests/test_api_address_search.py b/src/openforms/contrib/kadaster/tests/test_api_address_search.py index e960b63900..8402252ac4 100644 --- a/src/openforms/contrib/kadaster/tests/test_api_address_search.py +++ b/src/openforms/contrib/kadaster/tests/test_api_address_search.py @@ -7,10 +7,10 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase +from zgw_consumers.test.factories import ServiceFactory from openforms.submissions.tests.factories import SubmissionFactory from openforms.submissions.tests.mixins import SubmissionsMixin -from zgw_consumers_ext.tests.factories import ServiceFactory from ..models import KadasterApiConfig diff --git a/src/openforms/contrib/kadaster/tests/test_bag_client.py b/src/openforms/contrib/kadaster/tests/test_bag_client.py index 0a9ff46c6b..d7d326c110 100644 --- a/src/openforms/contrib/kadaster/tests/test_bag_client.py +++ b/src/openforms/contrib/kadaster/tests/test_bag_client.py @@ -6,8 +6,7 @@ import requests import requests_mock - -from zgw_consumers_ext.tests.factories import ServiceFactory +from zgw_consumers.test.factories import ServiceFactory from ..clients import get_bag_client from ..models import KadasterApiConfig diff --git a/src/openforms/contrib/kadaster/tests/test_config_checks.py b/src/openforms/contrib/kadaster/tests/test_config_checks.py index a0345695cd..9e9882cfa2 100644 --- a/src/openforms/contrib/kadaster/tests/test_config_checks.py +++ b/src/openforms/contrib/kadaster/tests/test_config_checks.py @@ -3,9 +3,9 @@ from django.test import SimpleTestCase import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.plugins.exceptions import InvalidPluginConfiguration -from zgw_consumers_ext.tests.factories import ServiceFactory from ..config_check import BAGCheck, LocatieServerCheck from ..models import KadasterApiConfig diff --git a/src/openforms/contrib/kvk/client.py b/src/openforms/contrib/kvk/client.py index cb68e17685..608e66fdc9 100644 --- a/src/openforms/contrib/kvk/client.py +++ b/src/openforms/contrib/kvk/client.py @@ -3,9 +3,9 @@ import elasticapm import requests +from zgw_consumers.client import build_client from openforms.contrib.hal_client import HALClient -from zgw_consumers_ext.api_client import ServiceClientFactory from .api_models.basisprofiel import BasisProfiel from .models import KVKConfig @@ -22,8 +22,7 @@ def get_client() -> "KVKClient": assert isinstance(config, KVKConfig) if not (service := config.service): raise NoServiceConfigured("No KVK service configured!") - service_client_factory = ServiceClientFactory(service) - return KVKClient.configure_from(service_client_factory) + return build_client(service, client_factory=KVKClient) class SearchParams(TypedDict, total=False): diff --git a/src/openforms/contrib/kvk/tests/base.py b/src/openforms/contrib/kvk/tests/base.py index ba5aab40bb..c9c9429515 100644 --- a/src/openforms/contrib/kvk/tests/base.py +++ b/src/openforms/contrib/kvk/tests/base.py @@ -6,9 +6,9 @@ from simple_certmanager.constants import CertificateTypes from simple_certmanager.test.factories import CertificateFactory from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.test.factories import ServiceFactory from openforms.contrib.kvk.models import KVKConfig -from zgw_consumers_ext.tests.factories import ServiceFactory TEST_FILES = Path(__file__).parent.resolve() / "files" diff --git a/src/openforms/contrib/objects_api/clients/objects.py b/src/openforms/contrib/objects_api/clients/objects.py index 2f9784b017..a739003aed 100644 --- a/src/openforms/contrib/objects_api/clients/objects.py +++ b/src/openforms/contrib/objects_api/clients/objects.py @@ -1,4 +1,4 @@ -from zgw_consumers_ext.api_client import NLXClient +from zgw_consumers.nlx import NLXClient CRS_HEADERS = {"Content-Crs": "EPSG:4326"} diff --git a/src/openforms/contrib/zgw/clients/catalogi.py b/src/openforms/contrib/zgw/clients/catalogi.py index 8ec8ef15fb..a5a8bad76f 100644 --- a/src/openforms/contrib/zgw/clients/catalogi.py +++ b/src/openforms/contrib/zgw/clients/catalogi.py @@ -1,6 +1,6 @@ from typing import Callable -from zgw_consumers_ext.api_client import NLXClient +from zgw_consumers.nlx import NLXClient from .utils import pagination_helper diff --git a/src/openforms/contrib/zgw/clients/documenten.py b/src/openforms/contrib/zgw/clients/documenten.py index 41453f7356..ab01d61ede 100644 --- a/src/openforms/contrib/zgw/clients/documenten.py +++ b/src/openforms/contrib/zgw/clients/documenten.py @@ -3,7 +3,7 @@ from django.core.files.base import ContentFile -from zgw_consumers_ext.api_client import NLXClient +from zgw_consumers.nlx import NLXClient from .utils import get_today diff --git a/src/openforms/contrib/zgw/clients/zaken.py b/src/openforms/contrib/zgw/clients/zaken.py index a30c001962..695d6f86c3 100644 --- a/src/openforms/contrib/zgw/clients/zaken.py +++ b/src/openforms/contrib/zgw/clients/zaken.py @@ -2,7 +2,7 @@ from django.utils import timezone -from zgw_consumers_ext.api_client import NLXClient +from zgw_consumers.nlx import NLXClient from .catalogi import CatalogiClient from .utils import get_today diff --git a/src/openforms/formio/components/np_family_members/tests/test_family_members.py b/src/openforms/formio/components/np_family_members/tests/test_family_members.py index 034cb62e20..3c35da6da2 100644 --- a/src/openforms/formio/components/np_family_members/tests/test_family_members.py +++ b/src/openforms/formio/components/np_family_members/tests/test_family_members.py @@ -7,6 +7,7 @@ from django.utils.translation import gettext as _ import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.authentication.constants import AuthAttribute from openforms.contrib.haal_centraal.models import HaalCentraalConfig @@ -16,7 +17,6 @@ from stuf.constants import EndpointType from stuf.stuf_bg.models import StufBGConfig from stuf.tests.factories import StufServiceFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ..constants import FamilyMembersDataAPIChoices from ..haal_centraal import get_np_family_members_haal_centraal diff --git a/src/openforms/forms/tests/variables/test_viewset.py b/src/openforms/forms/tests/variables/test_viewset.py index 8e7005c2fd..415cd57d35 100644 --- a/src/openforms/forms/tests/variables/test_viewset.py +++ b/src/openforms/forms/tests/variables/test_viewset.py @@ -9,6 +9,7 @@ from rest_framework.reverse import reverse from rest_framework.test import APITestCase from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.test.factories import ServiceFactory from openforms.accounts.tests.factories import ( StaffUserFactory, @@ -29,7 +30,6 @@ ) from openforms.variables.models import ServiceFetchConfiguration from openforms.variables.tests.factories import ServiceFetchConfigurationFactory -from zgw_consumers_ext.tests.factories import ServiceFactory @override_settings(LANGUAGE_CODE="en") diff --git a/src/openforms/pre_requests/tests/test_clients.py b/src/openforms/pre_requests/tests/test_clients.py index e5712ab650..5b60c850e0 100644 --- a/src/openforms/pre_requests/tests/test_clients.py +++ b/src/openforms/pre_requests/tests/test_clients.py @@ -3,12 +3,12 @@ from django.test import SimpleTestCase import requests_mock +from zgw_consumers.client import build_client +from zgw_consumers.nlx import NLXClient +from zgw_consumers.test.factories import ServiceFactory from openforms.submissions.tests.factories import SubmissionFactory from openforms.utils.tests.nlx import DisableNLXRewritingMixin -from zgw_consumers_ext.api_client import build_client -from zgw_consumers_ext.nlx import NLXClient -from zgw_consumers_ext.tests.factories import ServiceFactory from ..base import PreRequestHookBase from ..clients import PreRequestClientContext, PreRequestMixin @@ -25,7 +25,7 @@ def test_pre_request_hook(self): @register("test-hook") class PreRequestHook(PreRequestHookBase): - def __call__(self, url, method, kwargs, context): + def __call__(self, url, method, kwargs, context=None): kwargs.setdefault("headers", {}) kwargs["headers"].update({"test": "test"}) diff --git a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_co_sign.py b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_co_sign.py index e449c81fee..275dc53352 100644 --- a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_co_sign.py +++ b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_co_sign.py @@ -3,12 +3,12 @@ from django.test import TestCase import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.contrib.haal_centraal.constants import BRPVersions from openforms.contrib.haal_centraal.models import HaalCentraalConfig from openforms.contrib.haal_centraal.tests.utils import load_json_mock from openforms.submissions.tests.factories import SubmissionFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ....co_sign import add_co_sign_representation from ....models import PrefillConfig diff --git a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_config_check.py b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_config_check.py index 39157cb741..adc9c8b1c3 100644 --- a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_config_check.py +++ b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_config_check.py @@ -4,12 +4,12 @@ from django.utils.translation import gettext as _ import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.config.models import GlobalConfiguration from openforms.contrib.haal_centraal.constants import BRPVersions from openforms.contrib.haal_centraal.models import HaalCentraalConfig from openforms.plugins.exceptions import InvalidPluginConfiguration -from zgw_consumers_ext.tests.factories import ServiceFactory from ....registry import register diff --git a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py index ef3dc738af..e0418a9067 100644 --- a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py +++ b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py @@ -4,6 +4,7 @@ import requests_mock from glom import glom +from zgw_consumers.test.factories import ServiceFactory from openforms.contrib.haal_centraal.constants import BRPVersions from openforms.contrib.haal_centraal.models import HaalCentraalConfig @@ -11,7 +12,6 @@ from openforms.pre_requests.base import PreRequestHookBase from openforms.pre_requests.registry import Registry from openforms.submissions.tests.factories import SubmissionFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ....constants import IdentifierRoles from ..constants import AttributesV1 as DefaultAttributes diff --git a/src/openforms/prefill/tests/test_prefill_variables.py b/src/openforms/prefill/tests/test_prefill_variables.py index 6bc875bfab..d138ffe7d8 100644 --- a/src/openforms/prefill/tests/test_prefill_variables.py +++ b/src/openforms/prefill/tests/test_prefill_variables.py @@ -3,6 +3,7 @@ from django.test import RequestFactory, TestCase, TransactionTestCase import requests_mock +from zgw_consumers.test.factories import ServiceFactory from openforms.authentication.constants import AuthAttribute from openforms.contrib.haal_centraal.models import HaalCentraalConfig @@ -18,7 +19,6 @@ SubmissionFactory, SubmissionStepFactory, ) -from zgw_consumers_ext.tests.factories import ServiceFactory from .. import prefill_variables diff --git a/src/openforms/registrations/api/filters.py b/src/openforms/registrations/api/filters.py index 7fc02056ea..0541d6f6ae 100644 --- a/src/openforms/registrations/api/filters.py +++ b/src/openforms/registrations/api/filters.py @@ -1,13 +1,13 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers +from zgw_consumers.client import build_client from openforms.api.fields import PrimaryKeyRelatedAsChoicesField from openforms.contrib.zgw.clients.catalogi import CatalogiClient from openforms.registrations.contrib.objects_api.models import ObjectsAPIConfig from openforms.registrations.contrib.zgw_apis.client import get_catalogi_client from openforms.registrations.contrib.zgw_apis.models import ZGWApiGroupConfig, ZgwConfig -from zgw_consumers_ext.api_client import build_client from ..registry import register diff --git a/src/openforms/registrations/contrib/objects_api/client.py b/src/openforms/registrations/contrib/objects_api/client.py index 24e0b577b0..509b3363b1 100644 --- a/src/openforms/registrations/contrib/objects_api/client.py +++ b/src/openforms/registrations/contrib/objects_api/client.py @@ -9,9 +9,11 @@ in the form builder """ +from zgw_consumers.client import build_client +from zgw_consumers.nlx import NLXClient + from openforms.contrib.objects_api.clients import ObjectsClient from openforms.contrib.zgw.clients import DocumentenClient -from zgw_consumers_ext.api_client import NLXClient, build_client from .models import ObjectsAPIConfig diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_backend.py b/src/openforms/registrations/contrib/objects_api/tests/test_backend.py index 1ff54bda01..3718874533 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_backend.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_backend.py @@ -7,6 +7,7 @@ import requests_mock from zgw_consumers.constants import APITypes from zgw_consumers.test import generate_oas_component +from zgw_consumers.test.factories import ServiceFactory from openforms.payments.constants import PaymentStatus from openforms.payments.tests.factories import SubmissionPaymentFactory @@ -14,7 +15,6 @@ SubmissionFactory, SubmissionFileAttachmentFactory, ) -from zgw_consumers_ext.tests.factories import ServiceFactory from ....constants import RegistrationAttribute from ....service import NoSubmissionReference, extract_submission_reference diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_config_checks.py b/src/openforms/registrations/contrib/objects_api/tests/test_config_checks.py index db6e59b1e9..a29a303c99 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_config_checks.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_config_checks.py @@ -6,10 +6,10 @@ import requests import requests_mock from zgw_consumers.constants import APITypes +from zgw_consumers.test.factories import ServiceFactory from openforms.plugins.exceptions import InvalidPluginConfiguration from openforms.utils.tests.nlx import DisableNLXRewritingMixin -from zgw_consumers_ext.tests.factories import ServiceFactory from ..models import ObjectsAPIConfig from ..plugin import PLUGIN_IDENTIFIER, ObjectsAPIRegistration diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_template.py b/src/openforms/registrations/contrib/objects_api/tests/test_template.py index b093fc7ce0..8a72c10d7b 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_template.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_template.py @@ -8,12 +8,12 @@ import tablib from freezegun import freeze_time from zgw_consumers.constants import APITypes +from zgw_consumers.test.factories import ServiceFactory from openforms.submissions.tests.factories import ( SubmissionFactory, SubmissionFileAttachmentFactory, ) -from zgw_consumers_ext.tests.factories import ServiceFactory from ..models import ObjectsAPIConfig from ..plugin import PLUGIN_IDENTIFIER, ObjectsAPIRegistration diff --git a/src/openforms/registrations/contrib/objects_api/tests/test_update_payment_status.py b/src/openforms/registrations/contrib/objects_api/tests/test_update_payment_status.py index e0c8f7ddc8..e2205c9efc 100644 --- a/src/openforms/registrations/contrib/objects_api/tests/test_update_payment_status.py +++ b/src/openforms/registrations/contrib/objects_api/tests/test_update_payment_status.py @@ -6,11 +6,11 @@ import requests_mock from freezegun import freeze_time from zgw_consumers.constants import APITypes +from zgw_consumers.test.factories import ServiceFactory from openforms.payments.constants import PaymentStatus from openforms.payments.tests.factories import SubmissionPaymentFactory from openforms.submissions.tests.factories import SubmissionFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ..models import ObjectsAPIConfig from ..plugin import PLUGIN_IDENTIFIER, ObjectsAPIRegistration diff --git a/src/openforms/registrations/contrib/zgw_apis/client.py b/src/openforms/registrations/contrib/zgw_apis/client.py index 3e876af969..f486cfdaf8 100644 --- a/src/openforms/registrations/contrib/zgw_apis/client.py +++ b/src/openforms/registrations/contrib/zgw_apis/client.py @@ -9,8 +9,9 @@ in the form builder """ +from zgw_consumers.client import build_client + from openforms.contrib.zgw.clients import CatalogiClient, DocumentenClient, ZakenClient -from zgw_consumers_ext.api_client import build_client from .models import ZGWApiGroupConfig diff --git a/src/openforms/registrations/contrib/zgw_apis/tests/factories.py b/src/openforms/registrations/contrib/zgw_apis/tests/factories.py index 73ddcb48d1..62e13bd39c 100644 --- a/src/openforms/registrations/contrib/zgw_apis/tests/factories.py +++ b/src/openforms/registrations/contrib/zgw_apis/tests/factories.py @@ -7,13 +7,13 @@ class ZGWApiGroupConfigFactory(factory.django.DjangoModelFactory): name = factory.Sequence(lambda n: "ZGW API set %03d" % n) zrc_service = factory.SubFactory( - "zgw_consumers_ext.tests.factories.ServiceFactory", api_type=APITypes.zrc + "zgw_consumers.test.factories.ServiceFactory", api_type=APITypes.zrc ) drc_service = factory.SubFactory( - "zgw_consumers_ext.tests.factories.ServiceFactory", api_type=APITypes.drc + "zgw_consumers.test.factories.ServiceFactory", api_type=APITypes.drc ) ztc_service = factory.SubFactory( - "zgw_consumers_ext.tests.factories.ServiceFactory", api_type=APITypes.ztc + "zgw_consumers.test.factories.ServiceFactory", api_type=APITypes.ztc ) class Meta: diff --git a/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py b/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py index ee03cb85ce..7fff6a1bbd 100644 --- a/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py +++ b/src/openforms/registrations/contrib/zgw_apis/tests/test_backend.py @@ -13,6 +13,7 @@ from privates.test import temp_private_root from zgw_consumers.constants import APITypes from zgw_consumers.test import generate_oas_component +from zgw_consumers.test.factories import ServiceFactory from openforms.authentication.tests.factories import RegistratorInfoFactory from openforms.registrations.contrib.objects_api.models import ObjectsAPIConfig @@ -23,7 +24,6 @@ SubmissionFactory, SubmissionFileAttachmentFactory, ) -from zgw_consumers_ext.tests.factories import ServiceFactory from ....constants import RegistrationAttribute from ....exceptions import RegistrationFailed diff --git a/src/openforms/services/tests/test_api_list.py b/src/openforms/services/tests/test_api_list.py index a3e212c95a..7ec386c2dd 100644 --- a/src/openforms/services/tests/test_api_list.py +++ b/src/openforms/services/tests/test_api_list.py @@ -1,9 +1,9 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase +from zgw_consumers.test.factories import ServiceFactory from openforms.accounts.tests.factories import StaffUserFactory, UserFactory -from zgw_consumers_ext.tests.factories import ServiceFactory class AccessControlTests(APITestCase): diff --git a/src/openforms/submissions/logic/service_fetching.py b/src/openforms/submissions/logic/service_fetching.py index d721d3e1ca..46727ff399 100644 --- a/src/openforms/submissions/logic/service_fetching.py +++ b/src/openforms/submissions/logic/service_fetching.py @@ -6,11 +6,11 @@ import jq from json_logic import jsonLogic +from zgw_consumers.client import build_client from openforms.forms.models import FormVariable from openforms.typing import DataMapping, JSONObject, JSONValue from openforms.variables.models import DataMappingTypes, ServiceFetchConfiguration -from zgw_consumers_ext.api_client import build_client @dataclass diff --git a/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py b/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py index 5867894b88..83803cd92b 100644 --- a/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py +++ b/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py @@ -11,13 +11,13 @@ from furl import furl from hypothesis import assume, example, given, strategies as st from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.test.factories import ServiceFactory from openforms.forms.tests.factories import FormVariableFactory from openforms.utils.tests.nlx import DisableNLXRewritingMixin from openforms.variables.constants import DataMappingTypes from openforms.variables.tests.factories import ServiceFetchConfigurationFactory from openforms.variables.validators import HeaderValidator, ValidationError -from zgw_consumers_ext.tests.factories import ServiceFactory from ...logic.service_fetching import perform_service_fetch diff --git a/src/openforms/submissions/tests/test_variables/test_fetch_with_logic.py b/src/openforms/submissions/tests/test_variables/test_fetch_with_logic.py index c1ba489f5c..d8a842c3fd 100644 --- a/src/openforms/submissions/tests/test_variables/test_fetch_with_logic.py +++ b/src/openforms/submissions/tests/test_variables/test_fetch_with_logic.py @@ -6,11 +6,11 @@ from rest_framework.reverse import reverse from rest_framework.test import APITestCase from zgw_consumers.constants import APITypes, AuthTypes +from zgw_consumers.test.factories import ServiceFactory from openforms.forms.constants import LogicActionTypes from openforms.forms.tests.factories import FormLogicFactory from openforms.variables.tests.factories import ServiceFetchConfigurationFactory -from zgw_consumers_ext.tests.factories import ServiceFactory from ..factories import SubmissionFactory from ..mixins import SubmissionsMixin diff --git a/src/openforms/tests/test_registrator_prefill.py b/src/openforms/tests/test_registrator_prefill.py index 03d368f8f1..9002e1bb14 100644 --- a/src/openforms/tests/test_registrator_prefill.py +++ b/src/openforms/tests/test_registrator_prefill.py @@ -8,6 +8,7 @@ from furl import furl from mozilla_django_oidc_db.models import OpenIDConnectConfig from rest_framework import status +from zgw_consumers.test.factories import ServiceFactory from openforms.accounts.models import User from openforms.authentication.constants import ( @@ -21,7 +22,6 @@ from openforms.prefill.contrib.haalcentraal_brp.constants import AttributesV1 from openforms.submissions.models import Submission from openforms.utils.urls import reverse_plus -from zgw_consumers_ext.tests.factories import ServiceFactory CONFIGURATION = { "display": "form", diff --git a/src/openforms/utils/tests/nlx.py b/src/openforms/utils/tests/nlx.py index c945014a54..aff49a8ab9 100644 --- a/src/openforms/utils/tests/nlx.py +++ b/src/openforms/utils/tests/nlx.py @@ -11,8 +11,8 @@ class DisableNLXRewritingMixin: def setUp(self): patchers = ( - patch("zgw_consumers_ext.nlx.Rewriter._rewrite", new=lambda *args: None), - patch("zgw_consumers_ext.nlx.Rewriter.reverse_rewrites", new=[]), + patch("zgw_consumers.nlx.Rewriter._rewrite", new=lambda *args: None), + patch("zgw_consumers.nlx.Rewriter.reverse_rewrites", new=[]), ) for patcher in patchers: patcher.start() diff --git a/src/openforms/variables/tests/factories.py b/src/openforms/variables/tests/factories.py index ed3bc81569..30e07c0180 100644 --- a/src/openforms/variables/tests/factories.py +++ b/src/openforms/variables/tests/factories.py @@ -1,6 +1,5 @@ import factory - -from zgw_consumers_ext.tests.factories import ServiceFactory +from zgw_consumers.test.factories import ServiceFactory from ..models import ServiceFetchConfiguration diff --git a/src/openforms/variables/tests/test_e2e.py b/src/openforms/variables/tests/test_e2e.py index 46557468fd..ac9d289966 100644 --- a/src/openforms/variables/tests/test_e2e.py +++ b/src/openforms/variables/tests/test_e2e.py @@ -3,6 +3,7 @@ from asgiref.sync import sync_to_async from furl import furl from playwright.async_api import expect +from zgw_consumers.test.factories import ServiceFactory from openforms.forms.constants import LogicActionTypes from openforms.forms.tests.factories import ( @@ -13,7 +14,6 @@ ) from openforms.tests.e2e.base import E2ETestCase, browser_page, create_superuser from openforms.variables.tests.factories import ServiceFetchConfigurationFactory -from zgw_consumers_ext.tests.factories import ServiceFactory class ServiceFetchConfigTests(E2ETestCase): diff --git a/src/zgw_consumers_ext/__init__.py b/src/zgw_consumers_ext/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/zgw_consumers_ext/api_client.py b/src/zgw_consumers_ext/api_client.py deleted file mode 100644 index ee2ed117c8..0000000000 --- a/src/zgw_consumers_ext/api_client.py +++ /dev/null @@ -1,114 +0,0 @@ -import logging -from dataclasses import dataclass, field -from typing import Any, TypeVar - -from requests.auth import AuthBase -from requests.models import PreparedRequest -from zds_client import ClientAuth -from zgw_consumers.constants import AuthTypes -from zgw_consumers.models import Service - -from .nlx import NLXClient - -logger = logging.getLogger(__name__) - - -T = TypeVar("T", bound=NLXClient) - - -def build_client(service: Service, client_factory: type[T] = NLXClient, **kwargs) -> T: - """ - Build a client for a given :class:`zgw_consumers.models.Service`. - - :arg service: The model instance holding the service configuration. - :arg client_factory: Particular client (sub)class for more specialized clients. - - Any additional keyword arguments are forwarded to the client initialization. - """ - factory = ServiceClientFactory(service) - return client_factory.configure_from(factory, nlx_base_url=service.nlx, **kwargs) - - -@dataclass -class ServiceClientFactory: - """ - Map zgw_consumers.Service model configuration to API client parameters. - """ - - service: Service - - def get_client_base_url(self) -> str: - """ - Use the configured API root as client base URL. - """ - return self.service.api_root - - def get_client_session_kwargs(self) -> dict[str, Any]: - """ - Pass connection parameters from the configured service. - - * mTLS configuration from uploaded/configured certificates - * authentication type and credentials from DB configuration - """ - kwargs = {} - - # mTLS: verify server certificate if configured - if server_cert := self.service.server_certificate: - # NOTE: this only works with a file-system based storage! - kwargs["verify"] = server_cert.public_certificate.path - - # mTLS: offer client certificate if configured - if client_cert := self.service.client_certificate: - client_cert_path = client_cert.public_certificate.path - # decide between single cert or cert,key tuple variant - kwargs["cert"] = ( - (client_cert_path, privkey.path) - if (privkey := client_cert.private_key) - else client_cert_path - ) - - match self.service.auth_type: - case AuthTypes.api_key: - kwargs["auth"] = APIKeyAuth( - header=self.service.header_key, key=self.service.header_value - ) - case AuthTypes.zgw: - kwargs["auth"] = ZGWAuth(service=self.service) - - return kwargs - - -@dataclass -class APIKeyAuth(AuthBase): - """ - Requests authentication class for API key-based auth (in the request headers). - """ - - header: str - key: str - - def __call__(self, request: PreparedRequest): - request.headers[self.header] = self.key - return request - - -@dataclass -class ZGWAuth(AuthBase): - """ - Requests authentication class for JWT-based ZGW auth. - """ - - service: Service - auth: ClientAuth = field(init=False) - - def __post_init__(self): - self.auth = ClientAuth( - client_id=self.service.client_id, - secret=self.service.secret, - user_id=self.service.user_id, - user_representation=self.service.user_representation, - ) - - def __call__(self, request: PreparedRequest): - request.headers.update(self.auth.credentials()) - return request diff --git a/src/zgw_consumers_ext/nlx.py b/src/zgw_consumers_ext/nlx.py deleted file mode 100644 index 7d0c2c48ec..0000000000 --- a/src/zgw_consumers_ext/nlx.py +++ /dev/null @@ -1,80 +0,0 @@ -import json -import logging - -from ape_pie import APIClient -from requests import JSONDecodeError -from requests.models import PreparedRequest, Request, Response -from requests.utils import guess_json_utf -from zgw_consumers.nlx import Rewriter - -logger = logging.getLogger(__name__) - - -def nlx_rewrite_hook(response: Response, *args, **kwargs): - try: - json_data = response.json() - # it may be a different content type than JSON! Checking for application/json - # content type header is a bit annoying because there are alternatives like - # application/hal+json :( - except JSONDecodeError: - return response - - # rewrite the JSON - logger.debug( - "NLX client: Rewriting response JSON to replace outway URLs", - extra={"request": response.request}, - ) - # apply similar logic to response.json() itself - encoding = ( - response.encoding - or guess_json_utf(response.content) - or response.apparent_encoding - ) - assert encoding - rewriter = Rewriter() - rewriter.backwards(json_data) - response._content = json.dumps(json_data).encode(encoding) - - return response - - -class NLXMixin: - base_url: str - - def __init__(self, *args, nlx_base_url: str = "", **kwargs): - super().__init__(*args, **kwargs) - self.nlx_base_url = nlx_base_url - - if self.nlx_base_url: - self.hooks["response"].insert(0, nlx_rewrite_hook) # type: ignore - - def prepare_request(self, request: Request) -> PreparedRequest: - prepared_request = super().prepare_request(request) # type: ignore - - if not self.nlx_base_url: - return prepared_request - - # change the actual URL being called so that it uses NLX - # XXX: it would be really nice if at some point NLX would be just a normal HTTP - # proxy so we can instead just map DB configuration to proxy setup. - new_url = (original := prepared_request.url).replace( - self.base_url, self.nlx_base_url, 1 - ) - logger.debug( - "NLX client: URL %s rewritten to %s", - original, - new_url, - extra={ - "original_url": original, - "base_url": self.base_url, - "nlx_base_url": self.nlx_base_url, - "client": self, - }, - ) - prepared_request.url = new_url - - return prepared_request - - -class NLXClient(NLXMixin, APIClient): - pass diff --git a/src/zgw_consumers_ext/tests/__init__.py b/src/zgw_consumers_ext/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/zgw_consumers_ext/tests/factories.py b/src/zgw_consumers_ext/tests/factories.py deleted file mode 100644 index fd35cb78b5..0000000000 --- a/src/zgw_consumers_ext/tests/factories.py +++ /dev/null @@ -1,37 +0,0 @@ -import factory -from zgw_consumers.models import Service - - -class UriPathFaker(factory.Faker): - def __init__(self, **kwargs): - super().__init__("uri_path", **kwargs) - - def generate(self, extra_kwargs=None): - uri_path = super().generate(extra_kwargs) - # faker generates them without trailing slash, but let's make sure this stays true - # zgw_consumers.Service normalizes api_root to append missing trailing slashes - assert not uri_path.endswith("/") - return f"{uri_path}/" - - -class ServiceFactory(factory.django.DjangoModelFactory): - label = factory.Sequence(lambda n: f"API-{n}") - api_root = UriPathFaker() # FIXME: this should be a fully qualified URL - - class Meta: - model = Service - django_get_or_create = ("api_root",) - - class Params: - with_server_cert = factory.Trait( - server_certificate=factory.SubFactory( - "simple_certmanager.test.factories.CertificateFactory", - public_certificate__filename="server.cert", - ), - ) - with_client_cert = factory.Trait( - client_certificate=factory.SubFactory( - "simple_certmanager.test.factories.CertificateFactory", - public_certificate__filename="client.cert", - ), - ) diff --git a/src/zgw_consumers_ext/tests/test_client_factory.py b/src/zgw_consumers_ext/tests/test_client_factory.py deleted file mode 100644 index c65067ef4f..0000000000 --- a/src/zgw_consumers_ext/tests/test_client_factory.py +++ /dev/null @@ -1,135 +0,0 @@ -from django.test import TestCase - -import requests_mock -from ape_pie import APIClient -from privates.test import temp_private_root -from simple_certmanager.constants import CertificateTypes -from simple_certmanager.test.factories import CertificateFactory -from zgw_consumers.constants import AuthTypes - -from ..api_client import ServiceClientFactory -from .factories import ServiceFactory - - -@temp_private_root() -class ClientFromServiceTests(TestCase): - @classmethod - def setUpTestData(cls): - super().setUpTestData() - - cls.client_cert_only = CertificateFactory.create( - label="Gateway client certificate", - type=CertificateTypes.cert_only, - public_certificate__filename="client_cert.pem", - ) - cls.client_cert_and_privkey = CertificateFactory.create( - label="Gateway client certificate", - with_private_key=True, - public_certificate__filename="client_cert.pem", - private_key__filename="client_key.pem", - ) - cls.server_cert = CertificateFactory.create( - label="Gateway server certificate", - type=CertificateTypes.cert_only, - public_certificate__filename="server.pem", - ) - - def test_no_server_cert_specified(self): - service = ServiceFactory.build() - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertIs(client.verify, True) # not just truthy, but identity check - - def test_server_cert_specified(self): - service = ServiceFactory.build(server_certificate=self.server_cert) - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertEqual(client.verify, self.server_cert.public_certificate.path) - - def test_no_client_cert_specified(self): - service = ServiceFactory.build() - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertIsNone(client.cert) - - def test_client_cert_only_public_cert_specified(self): - service = ServiceFactory.build(client_certificate=self.client_cert_only) - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertEqual(client.cert, self.client_cert_only.public_certificate.path) - - def test_client_cert_public_cert_and_privkey_specified(self): - service = ServiceFactory.build(client_certificate=self.client_cert_and_privkey) - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertEqual( - client.cert, - ( - self.client_cert_and_privkey.public_certificate.path, - self.client_cert_and_privkey.private_key.path, - ), - ) - - def test_no_auth(self): - service = ServiceFactory.build(auth_type=AuthTypes.no_auth) - factory = ServiceClientFactory(service) - - client = APIClient.configure_from(factory) - - self.assertIsNone(client.auth) - - def test_api_key_auth(self): - service = ServiceFactory.build( - api_root="https://example.com/", - auth_type=AuthTypes.api_key, - header_key="Some-Auth-Header", - header_value="some-api-key", - ) - factory = ServiceClientFactory(service) - client = APIClient.configure_from(factory) - - with self.subTest("client.auth configuration"): - self.assertIsNotNone(client.auth) - - with self.subTest("dummy API call"): - with requests_mock.Mocker() as m, client: - m.get("https://example.com/foo") - - client.get("foo") - - headers = m.last_request.headers - self.assertIn("Some-Auth-Header", headers) - self.assertEqual(headers["Some-Auth-Header"], "some-api-key") - - def test_zgw_auth(self): - service = ServiceFactory.build( - api_root="https://example.com/", - auth_type=AuthTypes.zgw, - client_id="my-client-id", - secret="my-secret", - ) - factory = ServiceClientFactory(service) - client = APIClient.configure_from(factory) - - with self.subTest("client.auth configuration"): - self.assertIsNotNone(client.auth) - - with self.subTest("dummy API call"): - with requests_mock.Mocker() as m, client: - m.get("https://example.com/foo") - - client.get("foo") - - headers = m.last_request.headers - self.assertIn("Authorization", headers) - self.assertTrue(headers["Authorization"].startswith("Bearer ")) diff --git a/src/zgw_consumers_ext/tests/test_nlx_rewriting.py b/src/zgw_consumers_ext/tests/test_nlx_rewriting.py deleted file mode 100644 index 56f1cfebbf..0000000000 --- a/src/zgw_consumers_ext/tests/test_nlx_rewriting.py +++ /dev/null @@ -1,89 +0,0 @@ -from django.test import TestCase - -import requests_mock -from zgw_consumers.constants import AuthTypes - -from ..api_client import build_client -from .factories import ServiceFactory - - -class NLXClientTests(TestCase): - @requests_mock.Mocker() - def test_request_url_and_response_data_rewritten(self, m): - nlx_service = ServiceFactory.create( - label="Service with NLX", - api_root="https://example.com/", - auth_type=AuthTypes.no_auth, - nlx="http://localhost:8081/:serial-number/:service/", - ) - client = build_client(nlx_service) - - m.get( - "http://localhost:8081/:serial-number/:service/some-resource", - json=lambda req, _: {"url": req.url}, - ) - - with client: - response_data = client.get("some-resource").json() - - self.assertEqual(m.last_request.method, "GET") - self.assertEqual( - m.last_request.url, - "http://localhost:8081/:serial-number/:service/some-resource", - ) - self.assertEqual(response_data, {"url": "https://example.com/some-resource"}) - - @requests_mock.Mocker() - def test_non_json_response_data(self, m): - nlx_service = ServiceFactory.create( - label="Service with NLX", - api_root="https://example.com/", - auth_type=AuthTypes.no_auth, - nlx="http://localhost:8081/:serial-number/:service/", - ) - client = build_client(nlx_service) - - m.get( - "http://localhost:8081/:serial-number/:service/some-resource", - content=b"AAAAA", - ) - - with client: - response_data = client.get("some-resource").content - - self.assertEqual(m.last_request.method, "GET") - self.assertEqual( - m.last_request.url, - "http://localhost:8081/:serial-number/:service/some-resource", - ) - self.assertEqual(response_data, b"AAAAA") - - @requests_mock.Mocker() - def test_service_without_nlx(self, m): - ServiceFactory.create( - label="Service with NLX", - api_root="https://example.com/", - auth_type=AuthTypes.no_auth, - nlx="http://localhost:8081/:serial-number/:service/", - ) - normal_service = ServiceFactory.create( - label="Service without NLX", - api_root="https://second.example.com/", - auth_type=AuthTypes.no_auth, - ) - client = build_client(normal_service) - m.get( - "https://second.example.com/some-resource", - json={"url": "https://example.com"}, - ) - - with client: - response_data = client.get("some-resource").json() - - self.assertEqual(m.last_request.method, "GET") - self.assertEqual( - m.last_request.url, - "https://second.example.com/some-resource", - ) - # no rewriting of any sorts - self.assertEqual(response_data, {"url": "https://example.com"})