Skip to content

Commit

Permalink
MIJN-6678 - move zorgned api calls to post (#85)
Browse files Browse the repository at this point in the history
* fix: use post

* fix: remove None

* test: update them

* Update app/zorgned_service.py

Co-authored-by: Tim van Oostrom <[email protected]>

---------

Co-authored-by: Tim van Oostrom <[email protected]>
  • Loading branch information
janthijs and timvanoostrom authored Dec 4, 2023
1 parent e16effa commit 2333f49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/test_zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ def raise_for_status(self):


class ZorgnedServiceTest(TestCase):
@patch("app.zorgned_service.requests.get")
@patch("app.zorgned_service.requests.post")
def test_get_clientnummer_response(self, get_mock):
get_mock.return_value = ZorgnedApiMock(BASE_PATH + "/fixtures/persoon.json")

clientnummer = get_clientnummer(123)

self.assertEqual(clientnummer, 304184)

@patch("app.zorgned_service.requests.get")
@patch("app.zorgned_service.requests.post")
def test_get_clientnummer_not_found_response(self, get_mock):
get_mock.return_value = ZorgnedApiMock(status_code=404)

clientnummer = get_clientnummer(123)

self.assertEqual(clientnummer, None)

@patch("app.zorgned_service.requests.get")
@patch("app.zorgned_service.requests.post")
def test_get_clientnummer_bad_request_response(self, get_mock):
get_mock.return_value = ZorgnedApiMock(status_code=400)

Expand Down
17 changes: 11 additions & 6 deletions app/zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
)


def send_api_request(bsn, operation="", query_params=None):
def send_api_request(bsn, operation="", post_message={}):
headers = None
cert = None

headers = {"Token": ZORGNED_API_TOKEN}
cert = (SERVER_CLIENT_CERT, SERVER_CLIENT_KEY)
url = f"{ZORGNED_API_URL}/gemeenten/{ZORGNED_GEMEENTE_CODE}/ingeschrevenpersonen/{bsn}{operation}"

res = requests.get(
url = f"{ZORGNED_API_URL}{operation}"
default_post_params = {
"burgerservicenummer": bsn,
"gemeentecode": ZORGNED_GEMEENTE_CODE,
}

res = requests.post(
url,
timeout=ZORGNED_API_REQUEST_TIMEOUT_SECONDS,
headers=headers,
cert=cert,
params=query_params,
json=default_post_params | post_message # Pipe operator merges the 2 dicts
)

return res


def send_api_request_json(bsn, operation="", query_params=None):
res = send_api_request(bsn, operation, query_params)
def send_api_request_json(bsn, operation="", post_message={}):
res = send_api_request(bsn, operation, post_message)

# 404 means bsn is now known to ZorgNed
if len(res.content) < 1 or res.status_code == 404:
Expand Down

0 comments on commit 2333f49

Please sign in to comment.