Skip to content

Commit

Permalink
fixes rpc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 11, 2023
1 parent df3d7dc commit 01a5ab6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions services/payments/src/simcore_service_payments/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


class BaseServiceError(PydanticErrorMixin, ValueError):
# TODO: error.code = __class__.__name__ and being able to de/serialize via rpc
...
@classmethod
def get_full_class_name(cls) -> str:
# Can be used as unique code identifier
return f"{cls.__module__}.{cls.__name__}"


class PaymentsError(BaseServiceError):
Expand Down
19 changes: 10 additions & 9 deletions services/payments/tests/unit/test_rpc_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import Any

import httpx
import pytest
from faker import Faker
from fastapi import FastAPI
Expand Down Expand Up @@ -70,7 +69,7 @@ def init_payment_kwargs(faker: Faker) -> dict[str, Any]:


@pytest.fixture
def _disable_startup(mocker: MockerFixture):
def _with_disabled_payments_gateway_startup(mocker: MockerFixture):
mocker.patch(
"simcore_service_payments.services.payments_gateway._create_start_policy",
return_value=lambda: print("on-startup"),
Expand All @@ -79,7 +78,7 @@ def _disable_startup(mocker: MockerFixture):

async def test_rpc_init_payment_fail(
is_pdb_enabled: bool,
_disable_startup,
_with_disabled_payments_gateway_startup: None,
app: FastAPI,
rpc_client: RabbitMQRPCClient,
init_payment_kwargs: dict[str, Any],
Expand All @@ -95,10 +94,11 @@ async def test_rpc_init_payment_fail(
timeout_s=None if is_pdb_enabled else 5,
)

exc: RPCServerError = exc_info.value
assert exc.exc_type == f"{httpx.ConnectError}"
assert exc.method_name == "init_payment"
assert exc.msg
error = exc_info.value
assert isinstance(error, RPCServerError)
assert error.exc_type == "httpx.ConnectError"
assert error.method_name == "init_payment"
assert error.msg


async def test_webserver_one_time_payment_workflow(
Expand Down Expand Up @@ -139,8 +139,9 @@ async def test_webserver_one_time_payment_workflow(

async def test_cancel_invalid_payment_id(
is_pdb_enabled: bool,
rpc_client: RabbitMQRPCClient,
mock_payments_gateway_service_or_none: MockRouter | None,
app: FastAPI,
rpc_client: RabbitMQRPCClient,
init_payment_kwargs: dict[str, Any],
faker: Faker,
payments_clean_db: None,
Expand All @@ -159,7 +160,7 @@ async def test_cancel_invalid_payment_id(
error = exc_info.value

assert isinstance(error, RPCServerError)
assert error.exc_type == f"{PaymentNotFoundError}"
assert error.exc_type == PaymentNotFoundError.get_full_class_name()
assert error.method_name == "cancel_payment"
assert error.msg == PaymentNotFoundError.msg_template.format(
payment_id=invalid_payment_id
Expand Down

0 comments on commit 01a5ab6

Please sign in to comment.