Skip to content

Commit

Permalink
init app
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Sep 11, 2023
1 parent eef31f5 commit aaf88ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
14 changes: 14 additions & 0 deletions services/payments/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 1 addition & 13 deletions services/payments/tests/unit/test_rpc_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]],
Expand Down
12 changes: 5 additions & 7 deletions services/payments/tests/unit/test_services_payments_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
):
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aaf88ea

Please sign in to comment.