-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from foarsitter/development
feat: tests with mocked API responses
- Loading branch information
Showing
9 changed files
with
894 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Any | ||
from typing import Dict | ||
from typing import Optional | ||
|
||
|
||
class CheckedIDError(Exception): | ||
status_code: int | ||
json: Optional[Dict[str, Any]] = None | ||
|
||
def __init__( | ||
self, | ||
message: str, | ||
status_code: int, | ||
json: Optional[Dict[str, Any]] = None, | ||
*args: str | ||
): | ||
super().__init__(message, *args) | ||
self.status_code = status_code | ||
self.json = json | ||
|
||
|
||
class CheckedIDValidationError(CheckedIDError): | ||
pass | ||
|
||
|
||
class CheckedIDNotFoundError(CheckedIDError): | ||
pass | ||
|
||
|
||
class CheckedIDAuthenticationError(CheckedIDError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,47 @@ | ||
import pytest | ||
from httpx import Response | ||
|
||
from checkedid import errors | ||
|
||
def test_dossier(auth_client): | ||
response = auth_client.dossier("100029-0000031") | ||
|
||
assert response.DossierNumber == "100029-0000031" | ||
def test_dossier(auth_client, respx_mock): | ||
dossier_number = "999999-8888800" | ||
respx_mock.get("").mock( | ||
return_value=Response( | ||
status_code=200, json={"DossierNumber": dossier_number, "ReportPDF": ""} | ||
) | ||
) | ||
response = auth_client.dossier(dossier_number) | ||
|
||
assert response.DossierNumber == dossier_number | ||
|
||
|
||
def test_dossier_with_error(auth_client, respx_mock): | ||
respx_mock.get("").mock(return_value=Response(status_code=404)) | ||
response = auth_client.dossier("does-not-exist") | ||
|
||
assert response.status_code == 404 | ||
|
||
|
||
def test_dossier_with_scope(auth_client): | ||
with pytest.raises(errors.CheckedIDError): | ||
auth_client.dossier("does-not-exist") | ||
|
||
|
||
def test_dossier_with_scope(auth_client, respx_mock): | ||
dossier_number = "999999-8888800" | ||
respx_mock.get("").mock( | ||
return_value=Response( | ||
status_code=200, | ||
json={ | ||
"DossierNumber": dossier_number, | ||
"ReportPDF": "", | ||
"Authority": "Burg. van Groningen", | ||
}, | ||
) | ||
) | ||
response = auth_client.dossier_with_scope("100029-0000031", "10") | ||
|
||
assert response.DossierNumber == "100029-0000031" | ||
assert response.DossierNumber == dossier_number | ||
assert response.Authority == "Burg. van Groningen" | ||
|
||
|
||
def test_dossier_with_scope_with_error(auth_client, respx_mock): | ||
respx_mock.get("").mock(return_value=Response(status_code=404)) | ||
response = auth_client.dossier_with_scope("does-not-exist", "10") | ||
|
||
assert response.status_code == 404 | ||
with pytest.raises(errors.CheckedIDError): | ||
auth_client.dossier_with_scope("does-not-exist", "10") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import pytest | ||
from httpx import Response | ||
|
||
from checkedid import errors | ||
|
||
def test_invitation_status(auth_client): | ||
response = auth_client.invitation_status("15IMN4") | ||
|
||
def test_invitation_status(auth_client, respx_mock): | ||
invitation_code = "4ZCNXF" | ||
|
||
respx_mock.get("").mock( | ||
return_value=Response( | ||
status_code=200, | ||
json={"CustomerCode": 100029, "InvitationCode": invitation_code}, | ||
) | ||
) | ||
|
||
response = auth_client.invitation_status(invitation_code) | ||
|
||
assert response.CustomerCode == 100029 | ||
assert response.InvitationCode == invitation_code | ||
|
||
|
||
def test_invitation_status_not_found(auth_client, respx_mock): | ||
respx_mock.get("").mock(return_value=Response(status_code=404)) | ||
response = auth_client.invitation_status("15IMN4") | ||
|
||
assert response.status_code == 404 | ||
with pytest.raises(errors.CheckedIDNotFoundError): | ||
auth_client.invitation_status("15IMN4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import pytest | ||
from httpx import Response | ||
|
||
from checkedid import errors | ||
from checkedid.models import CreateInvitationDetails | ||
from checkedid.models import CreateInvitationRequest | ||
|
||
|
||
def test_invitations_create_and_delete(auth_client, employee_code): | ||
def test_invitations_create_and_delete( | ||
auth_client, employee_code, respx_mock, customer_code | ||
): | ||
details: CreateInvitationRequest = CreateInvitationRequest.construct() | ||
details.EmployeeCode = employee_code | ||
details.InviteeEmail = "[email protected]" | ||
|
@@ -11,6 +18,17 @@ def test_invitations_create_and_delete(auth_client, employee_code): | |
details.AppFlow = "10" | ||
details.PreferredLanguage = "nl" | ||
|
||
respx_mock.post("").mock( | ||
return_value=Response( | ||
status_code=200, | ||
json=CreateInvitationDetails( | ||
CustomerCode=customer_code, Invitations=[details] | ||
).dict(), | ||
) | ||
) | ||
|
||
respx_mock.delete("").mock(return_value=Response(status_code=200)) | ||
|
||
response = auth_client.invitations_create([details]) | ||
|
||
assert response.CustomerCode == 100029 | ||
|
@@ -19,14 +37,14 @@ def test_invitations_create_and_delete(auth_client, employee_code): | |
assert auth_client.invitation_delete(response.Invitations[0].InvitationCode) is True | ||
|
||
|
||
def test_invitations_create_with_error(auth_client): | ||
response = auth_client.invitations_create([CreateInvitationRequest.construct()]) | ||
|
||
assert response.status_code == 422 | ||
assert len(response.Errors) == 4 | ||
def test_invitations_create_with_error(auth_client, respx_mock): | ||
respx_mock.post("").mock(return_value=Response(status_code=422)) | ||
|
||
with pytest.raises(errors.CheckedIDValidationError): | ||
auth_client.invitations_create([CreateInvitationRequest.construct()]) | ||
|
||
def test_invitation_delete_with_error(auth_client): | ||
response = auth_client.invitation_delete("xyz") | ||
|
||
assert response.status_code == 404 | ||
def test_invitation_delete_with_error(auth_client, respx_mock): | ||
respx_mock.delete("").mock(return_value=Response(status_code=404)) | ||
with pytest.raises(errors.CheckedIDNotFoundError): | ||
auth_client.invitation_delete("xyz") |
Oops, something went wrong.