Skip to content

Commit

Permalink
[WIP] esuite test mocking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Jan 9, 2025
1 parent 2b40e49 commit ac63e0f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ def __init__(self, config: OpenKlantConfig | None = None):
"eSuiteKlantenService instance needs a servivce configuration"
)

self.client = build_zgw_client(service=self.service_config)
self.client = build_zgw_client(
service=self.service_config, client_factory=APIClient
)
if not self.client:
raise RuntimeError("eSuiteKlantenService instance needs a client")
# self.client = APIClient(base_url="https://klanten.nl/api/v1/")

def get_or_create_klant(
self, fetch_params: FetchParameters, user: User
Expand Down
38 changes: 38 additions & 0 deletions src/open_inwoner/openklant/tests/test_esuite_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.test import TestCase

import requests_mock

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.openklant.services import eSuiteKlantenService
from open_inwoner.openklant.tests.data import KLANTEN_ROOT, MockAPIReadData
from open_inwoner.utils.test import DisableRequestLogMixin


def request_matcher(request):
print(f"Request body: {request.body}")
print(f"Request headers: {request.headers}")
return True


class eSuiteServiceTestCase(TestCase, DisableRequestLogMixin):
maxDiff = None

def setUp(self):
super().setUp()
self.data = MockAPIReadData()
self.data.setUpServices()
self.service = eSuiteKlantenService()
self.user = UserFactory()

def test_create_klant(self):
with requests_mock.mock() as m:
m.post(
f"{KLANTEN_ROOT}klanten",
json=self.data.klant_bsn,
additional_matcher=request_matcher,
)

response = self.service.create_klant(user_bsn="123456789")

assert response.emailadres == "[email protected]"
assert m.request_history[0].json() == {}

0 comments on commit ac63e0f

Please sign in to comment.