Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIJN-6924 Request handling #73

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions app/test_zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class ZorgnedApiMock:
status_code = 200
response_json = None
content = {
"mock": "Data"
}
content = {"mock": "Data"}

def __init__(self, response_json=None, status_code=200):
self.status_code = status_code

def __init__(self, response_json=None):
if isinstance(response_json, str):
with open(response_json, "r") as read_file:
self.response_json = json.load(read_file)
Expand All @@ -29,7 +29,6 @@ def raise_for_status(self):


class ZorgnedServiceTest(TestCase):

@patch("app.zorgned_service.requests.get")
def test_get_clientnummer_response(self, get_mock):
get_mock.return_value = ZorgnedApiMock(BASE_PATH + "/fixtures/persoon.json")
Expand All @@ -38,5 +37,19 @@ def test_get_clientnummer_response(self, get_mock):

self.assertEqual(clientnummer, 304184)

@patch("app.zorgned_service.requests.get")
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")
def test_get_clientnummer_bad_request_response(self, get_mock):
get_mock.return_value = ZorgnedApiMock(status_code=400)

self.assertRaises(Exception, get_clientnummer, 123)

def test_volledig_clientnummer(self):
self.assertEquals(volledig_clientnummer(304184), "03630000304184")
self.assertEqual(volledig_clientnummer(304184), "03630000304184")
8 changes: 5 additions & 3 deletions app/zorgned_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ def send_api_request(bsn, operation="", query_params=None):
params=query_params,
)

res.raise_for_status()

return res


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

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

# Other error codes should be propagated
res.raise_for_status()

response_data = res.json()

logging.debug(json.dumps(response_data, indent=4))
Expand Down