From aaf88eabd39f8fe440e1642e2821b10000b73131 Mon Sep 17 00:00:00 2001 From: Pedro Crespo <32402063+pcrespov@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:33:58 +0200 Subject: [PATCH] init app --- services/payments/tests/unit/conftest.py | 14 ++++++++++++++ services/payments/tests/unit/test_rpc_payments.py | 14 +------------- .../tests/unit/test_services_payments_gateway.py | 12 +++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/services/payments/tests/unit/conftest.py b/services/payments/tests/unit/conftest.py index eded9906fa53..776309c1a5c4 100644 --- a/services/payments/tests/unit/conftest.py +++ b/services/payments/tests/unit/conftest.py @@ -5,7 +5,10 @@ # pylint: disable=unused-variable +from collections.abc import AsyncIterator + import pytest +from asgi_lifespan import LifespanManager from fastapi import FastAPI from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_payments.core.application import create_app @@ -15,3 +18,14 @@ def app(app_environment: EnvVarsDict) -> FastAPI: """Inits app on a light environment""" return create_app() + + +@pytest.fixture +async def initialized_app(app: FastAPI) -> AsyncIterator[FastAPI]: + """Inits app on a light environment""" + async with LifespanManager( + app, + startup_timeout=10, + shutdown_timeout=10, + ): + yield app diff --git a/services/payments/tests/unit/test_rpc_payments.py b/services/payments/tests/unit/test_rpc_payments.py index 20cf687afe99..a295abd7f357 100644 --- a/services/payments/tests/unit/test_rpc_payments.py +++ b/services/payments/tests/unit/test_rpc_payments.py @@ -4,11 +4,10 @@ # pylint: disable=unused-argument # pylint: disable=unused-variable -from collections.abc import AsyncIterator, Awaitable, Callable +from collections.abc import Awaitable, Callable import orjson import pytest -from asgi_lifespan import LifespanManager from fastapi import FastAPI from models_library.api_schemas_webserver.wallets import WalletPaymentCreated from pytest_simcore.helpers.typing_env import EnvVarsDict @@ -38,17 +37,6 @@ def app_environment( ) -@pytest.fixture -async def initialized_app(app: FastAPI) -> AsyncIterator[FastAPI]: - """Inits app on a light environment""" - async with LifespanManager( - app, - startup_timeout=10, - shutdown_timeout=10, - ): - yield app - - async def test_webserver_one_time_payment_workflow( initialized_app: FastAPI, rabbitmq_rpc_client: Callable[[str], Awaitable[RabbitMQRPCClient]], diff --git a/services/payments/tests/unit/test_services_payments_gateway.py b/services/payments/tests/unit/test_services_payments_gateway.py index 5f13f9abdf69..27124cda2dd5 100644 --- a/services/payments/tests/unit/test_services_payments_gateway.py +++ b/services/payments/tests/unit/test_services_payments_gateway.py @@ -50,12 +50,11 @@ def mock_payments_gateway_service_api_base( async def test_payment_gateway_responsiveness( - app: FastAPI, + initialized_app: FastAPI, mock_payments_gateway_service_api_base: MockRouter, ): # NOTE: should be standard practice - PaymentGatewayApi.setup(app) - payment_gateway_api = PaymentGatewayApi.get_from_state(app) + payment_gateway_api = PaymentGatewayApi.get_from_state(initialized_app) assert payment_gateway_api mock_payments_gateway_service_api_base.get( @@ -76,7 +75,7 @@ async def test_payment_gateway_responsiveness( async def test_one_time_payment_workflow( - app: FastAPI, + initialized_app: FastAPI, faker: Faker, mock_payments_gateway_service_api_base: MockRouter, ): @@ -96,8 +95,7 @@ def _init_payment(request: httpx.Request): # ------------------------------------- - PaymentGatewayApi.setup(app) - payment_gateway_api = PaymentGatewayApi.get_from_state(app) + payment_gateway_api = PaymentGatewayApi.get_from_state(initialized_app) assert payment_gateway_api # init @@ -116,7 +114,7 @@ def _init_payment(request: httpx.Request): payment_initiated.payment_id ) - app_settings: ApplicationSettings = app.state.settings + app_settings: ApplicationSettings = initialized_app.state.settings assert submission_link.host == app_settings.PAYMENTS_GATEWAY_URL.host # check mock