diff --git a/services/payments/src/simcore_service_payments/core/errors.py b/services/payments/src/simcore_service_payments/core/errors.py index 748290c98a6a..186d37108c8e 100644 --- a/services/payments/src/simcore_service_payments/core/errors.py +++ b/services/payments/src/simcore_service_payments/core/errors.py @@ -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): diff --git a/services/payments/tests/unit/test_rpc_payments.py b/services/payments/tests/unit/test_rpc_payments.py index fcf9e3b4e3dc..c69bb57506fa 100644 --- a/services/payments/tests/unit/test_rpc_payments.py +++ b/services/payments/tests/unit/test_rpc_payments.py @@ -6,7 +6,6 @@ from typing import Any -import httpx import pytest from faker import Faker from fastapi import FastAPI @@ -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"), @@ -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], @@ -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( @@ -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, @@ -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