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

test: added tests for a full webhook process using litestar #16

Merged
merged 3 commits into from
Jun 2, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/test_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
else
echo "CREDENTIALS_JSON=${{ secrets.PYTEST_CREDENTIALS_LINUX }}" >> $GITHUB_ENV
fi
echo "NGROK_AUTH_TOKEN=${{ secrets.PYTEST_NGROK_AUTH_TOKEN }}" >> $GITHUB_ENV

#-----------------------------------------------
# ------------- run test suite ------------
Expand All @@ -86,6 +87,7 @@ jobs:
if: always()
run: |
echo $CREDENTIALS_JSON | base64 -d > ./tests/credentials/test_creds.json
echo "NGROK_AUTH_TOKEN=$NGROK_AUTH_TOKEN" > ./tests/credentials/.env
make test

#----------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ test:
$(MAKE) test-integration
@echo "Tests complete!"

### Commands to run the docs ###
run-docs:
@echo "Building documentation..."
@poetry run mkdocs serve
@echo "Documentation built!"

### Commands to git commit ###
stage:
@echo "Staging changes..."
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ The wrapper currently supports the following APIs:
- [x] Delete a webhook
- [x] Rotate a webhook signing secret
- [x] Retrieve a list of failed webhook events
- [x] Verify a webhook signature

## **Contributing**

Expand Down
50 changes: 46 additions & 4 deletions docs/code_reference/exceptions/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,60 @@ PyRevolut provides a number of exceptions that can be raised during the executio

---

::: pyrevolut.exceptions.common.PyRevolutAPIException
::: pyrevolut.exceptions.common.PyRevolutBaseException

---

::: pyrevolut.exceptions.bad_request.BadRequestException
::: pyrevolut.exceptions.bad_request.PyRevolutBadRequest

---

::: pyrevolut.exceptions.internal_revolut_error.InternalRevolutError
::: pyrevolut.exceptions.conflict.PyRevolutConflict

---

::: pyrevolut.exceptions.invalid_environment.InvalidEnvironmentException
::: pyrevolut.exceptions.forbidden.PyRevolutForbidden

---

::: pyrevolut.exceptions.internal_server_error.PyRevolutInternalServerError

---

::: pyrevolut.exceptions.invalid_environment.PyRevolutInvalidEnvironment

---

::: pyrevolut.exceptions.invalid_payload.PyRevolutInvalidPayload

---

::: pyrevolut.exceptions.method_not_allowed.PyRevolutMethodNotAllowed

---

::: pyrevolut.exceptions.network_error.PyRevolutNetworkError

---

::: pyrevolut.exceptions.not_acceptable.PyRevolutNotAcceptable

---

::: pyrevolut.exceptions.not_found.PyRevolutNotFound

---

::: pyrevolut.exceptions.server_unavailable.PyRevolutServerUnavailable

---

::: pyrevolut.exceptions.timeout_error.PyRevolutTimeoutError

---

::: pyrevolut.exceptions.too_many_requests.PyRevolutTooManyRequests

---

::: pyrevolut.exceptions.unauthorized.PyRevolutUnauthorized
669 changes: 477 additions & 192 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pytest-randomly = "3.*"
pytest-clarity = "1.*"
pytest-split = "0.*"
pytest-env = "1.*"
pyngrok = "7.*"
litestar = "2.*"
uvicorn = "0.*"
python-dotenv = "1.*"

[tool.poetry.group.docs.dependencies]
mkdocs-material = "9.*"
Expand Down
6 changes: 3 additions & 3 deletions pyrevolut/api/cards/endpoint/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel

from pyrevolut.utils import DateTime
from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.api.common import BaseEndpointAsync, EnumMerchantCategory
from pyrevolut.api.cards.get import (
RetrieveListOfCards,
Expand Down Expand Up @@ -595,10 +595,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is not available in Sandbox."
)
6 changes: 3 additions & 3 deletions pyrevolut/api/cards/endpoint/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel

from pyrevolut.utils import DateTime
from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.api.common import BaseEndpointSync, EnumMerchantCategory
from pyrevolut.api.cards.get import (
RetrieveListOfCards,
Expand Down Expand Up @@ -595,10 +595,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is not available in Sandbox."
)
1 change: 0 additions & 1 deletion pyrevolut/api/common/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .profile_state import EnumProfileState
from .profile_type import EnumProfileType
from .recipient_charges import EnumRecipientCharges
from .simulate_transfer_state_action import EnumSimulateTransferStateAction
from .team_member_state import EnumTeamMemberState
from .time_unit import EnumTimeUnit
from .transaction_type import EnumTransactionType
Expand Down
12 changes: 0 additions & 12 deletions pyrevolut/api/common/enums/simulate_transfer_state_action.py

This file was deleted.

13 changes: 7 additions & 6 deletions pyrevolut/api/simulations/endpoint/asynchronous.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from uuid import UUID
from typing import Literal

from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.api.common import (
BaseEndpointAsync,
EnumTransactionState,
EnumSimulateTransferStateAction,
)
from pyrevolut.api.simulations.post import (
SimulateAccountTopup,
Expand Down Expand Up @@ -92,7 +92,7 @@ async def simulate_account_topup(
async def simulate_transfer_state_update(
self,
transfer_id: UUID,
action: EnumSimulateTransferStateAction,
action: Literal["complete", "revert", "decline", "fail"],
**kwargs,
) -> dict | SimulateTransferStateUpdate.Response:
"""
Expand All @@ -107,7 +107,7 @@ async def simulate_transfer_state_update(
----------
transfer_id : UUID
The ID of the transfer whose state you want to update.
action : EnumSimulateTransferStateAction
action : Literal["complete", "revert", "decline", "fail"]
The action you want to perform on the transfer. Possible values:

complete:
Expand All @@ -125,6 +125,7 @@ async def simulate_transfer_state_update(
The updated transfer information.
"""
self.__check_sandbox()
assert action in ["complete", "revert", "decline", "fail"], "Invalid action"
endpoint = SimulateTransferStateUpdate
path = endpoint.ROUTE.format(transfer_id=transfer_id, action=action)
body = endpoint.Body()
Expand All @@ -142,10 +143,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if not self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is only available in the Sandbox."
)
13 changes: 7 additions & 6 deletions pyrevolut/api/simulations/endpoint/synchronous.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from uuid import UUID
from typing import Literal

from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.api.common import (
BaseEndpointSync,
EnumTransactionState,
EnumSimulateTransferStateAction,
)
from pyrevolut.api.simulations.post import (
SimulateAccountTopup,
Expand Down Expand Up @@ -92,7 +92,7 @@ def simulate_account_topup(
def simulate_transfer_state_update(
self,
transfer_id: UUID,
action: EnumSimulateTransferStateAction,
action: Literal["complete", "revert", "decline", "fail"],
**kwargs,
) -> dict | SimulateTransferStateUpdate.Response:
"""
Expand All @@ -107,7 +107,7 @@ def simulate_transfer_state_update(
----------
transfer_id : UUID
The ID of the transfer whose state you want to update.
action : EnumSimulateTransferStateAction
action : Literal["complete", "revert", "decline", "fail"]
The action you want to perform on the transfer. Possible values:

complete:
Expand All @@ -125,6 +125,7 @@ def simulate_transfer_state_update(
The updated transfer information.
"""
self.__check_sandbox()
assert action in ["complete", "revert", "decline", "fail"], "Invalid action"
endpoint = SimulateTransferStateUpdate
path = endpoint.ROUTE.format(transfer_id=transfer_id, action=action)
body = endpoint.Body()
Expand All @@ -142,10 +143,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if not self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is only available in the Sandbox."
)
6 changes: 3 additions & 3 deletions pyrevolut/api/team_members/endpoint/asynchronous.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import UUID
from datetime import datetime

from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.utils.datetime import DateTime
from pyrevolut.api.common import BaseEndpointAsync
from pyrevolut.api.team_members.get import RetrieveListOfTeamMembers, RetrieveTeamRoles
Expand Down Expand Up @@ -170,10 +170,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is not available in Sandbox."
)
6 changes: 3 additions & 3 deletions pyrevolut/api/team_members/endpoint/synchronous.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import UUID
from datetime import datetime

from pyrevolut.exceptions import InvalidEnvironmentException
from pyrevolut.exceptions import PyRevolutInvalidEnvironment
from pyrevolut.utils.datetime import DateTime
from pyrevolut.api.common import BaseEndpointSync
from pyrevolut.api.team_members.get import RetrieveListOfTeamMembers, RetrieveTeamRoles
Expand Down Expand Up @@ -170,10 +170,10 @@ def __check_sandbox(self):

Raises
------
InvalidEnvironmentException
PyRevolutInvalidEnvironment
If the sandbox is enabled.
"""
if self.client.sandbox:
raise InvalidEnvironmentException(
raise PyRevolutInvalidEnvironment(
"This feature is not available in Sandbox."
)
Loading
Loading