Skip to content

Commit

Permalink
Add test (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
timvanoostrom authored Sep 21, 2023
1 parent 538ae07 commit abf1d6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
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

0 comments on commit abf1d6d

Please sign in to comment.