Skip to content

Commit

Permalink
MIJN-6678 - Move to post (#59)
Browse files Browse the repository at this point in the history
* fix: move to post

* fix: rmove old fn

* fix: rename var

* fix: update

* fix: format

* test: update tests
  • Loading branch information
janthijs authored Nov 28, 2023
1 parent 03788a6 commit b1ad9fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
8 changes: 4 additions & 4 deletions app/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestAPI(FlaskServerTestCase):
app = app
TEST_BSN = "111222333"

@patch("app.zorgned_service.requests.get", autospec=True)
@patch("app.zorgned_service.requests.post", autospec=True)
def test_get_voorzieningen(self, api_mocked):
api_mocked.return_value = ZorgnedApiMock(BASE_PATH + "/fixtures/aanvragen.json")

Expand Down Expand Up @@ -139,7 +139,7 @@ def test_get_voorzieningen(self, api_mocked):
],
)

@patch("app.zorgned_service.requests.get", autospec=True)
@patch("app.zorgned_service.requests.post", autospec=True)
def test_get_voorzieningen_2(self, api_mocked):
api_mocked.return_value = ZorgnedApiMock(
BASE_PATH + "/fixtures/aanvragen-2.json"
Expand All @@ -150,7 +150,7 @@ def test_get_voorzieningen_2(self, api_mocked):
self.assertEqual(res.status_code, 200, res.data)
self.assertEqual(res.json["status"], "OK")

@patch("app.zorgned_service.requests.get", autospec=True)
@patch("app.zorgned_service.requests.post", autospec=True)
def test_get_voorzieningen_error(self, api_mocked):
api_mocked.return_value = ZorgnedApiMockError()

Expand All @@ -160,7 +160,7 @@ def test_get_voorzieningen_error(self, api_mocked):
self.assertEqual(res.json["status"], "ERROR")
self.assertTrue("content" not in res.json)

@patch("app.zorgned_service.requests.get", autospec=True)
@patch("app.zorgned_service.requests.post", autospec=True)
def test_get_voorzieningen_token_error(self, api_mocked):
api_mocked.return_value = ZorgnedApiMock(None)

Expand Down
4 changes: 2 additions & 2 deletions app/test_zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ZorgnedServiceTest(TestCase):
@patch("app.zorgned_service.format_aanvragen")
@patch("app.zorgned_service.requests.get")
@patch("app.zorgned_service.requests.post")
def test_get_aanvragen(self, get_mock, format_mock):
get_mock.return_value = ZorgnedApiMock(
{"_embedded": {"aanvraag": [{"foo": "bar"}]}}
Expand All @@ -28,7 +28,7 @@ def test_get_aanvragen(self, get_mock, format_mock):

format_mock.assert_called_with([{"foo": "bar"}])

@patch("app.zorgned_service.requests.get")
@patch("app.zorgned_service.requests.post")
def test_get_aanvragen_fail(self, get_mock):
get_mock.return_value = ZorgnedApiMock(None)

Expand Down
37 changes: 16 additions & 21 deletions app/zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,33 @@ def format_aanvragen(aanvragen_source=[]):
return aanvragen


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}"
url = f"{ZORGNED_API_URL}{operation}"
default_post_params = {
"burgerservicenummer": bsn,
"gemeentecode": ZORGNED_GEMEENTE_CODE,
}

res = requests.get(
res = requests.post(
url,
timeout=ZORGNED_API_REQUEST_TIMEOUT_SECONDS,
headers=headers,
cert=cert,
params=query_params,
json={**default_post_params, **post_message}
)

res.raise_for_status()

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)

response_data = res.json()

Expand All @@ -179,27 +183,18 @@ def send_api_request_json(bsn, operation="", query_params=None):
return response_data


def get_aanvragen(bsn, query_params=None):
def get_aanvragen(bsn, post_message={}):
response_data = send_api_request_json(
bsn,
"/aanvragen",
query_params,
post_message
)

response_aanvragen = response_data["_embedded"]["aanvraag"]

return format_aanvragen(response_aanvragen)


def get_persoonsgegevens(bsn, query_params=None):
response_data = send_api_request_json(
bsn,
"/persoonsgegevens",
query_params,
)

return response_data


def has_start_date_in_past(aanvraag_source):
return (
aanvraag_source.get("dateStart")
Expand All @@ -208,12 +203,12 @@ def has_start_date_in_past(aanvraag_source):


def get_voorzieningen(bsn):
query_params = {
post_message = {
"maxeinddatum": DATE_END_NOT_OLDER_THAN,
"regeling": REGELING_IDENTIFICATIE,
}

aanvragen = get_aanvragen(bsn, query_params)
aanvragen = get_aanvragen(bsn, post_message)

voorzieningen = []

Expand All @@ -225,7 +220,7 @@ def get_voorzieningen(bsn):


def get_document(bsn, documentidentificatie):
response_data = send_api_request_json(bsn, f"/document/{documentidentificatie}")
response_data = send_api_request_json(bsn, "/document", {"documentidentificatie": documentidentificatie})

logging.debug(response_data)

Expand Down
3 changes: 1 addition & 2 deletions scripts/get_raw.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from sys import argv
import json
from app.zorgned_service import get_persoonsgegevens, get_voorzieningen
from app.zorgned_service import get_voorzieningen

bsn = argv[1]

response = get_voorzieningen(bsn)
# response = get_persoonsgegevens(bsn)

print("\n\n\nResponse.v2\n\n\n")
print(json.dumps(response, indent=4))
Expand Down

0 comments on commit b1ad9fa

Please sign in to comment.