From 4ceddb6af09d91926912b19a8bb2bbb89ed5ccbb Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 16 Oct 2025 14:35:41 +0300 Subject: [PATCH] make app required for faststream bootstrapper --- .../bootstrappers/faststream_bootstrapper.py | 6 +----- tests/test_faststream_bootstrap.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py index db21a06..ae89211 100644 --- a/lite_bootstrap/bootstrappers/faststream_bootstrapper.py +++ b/lite_bootstrap/bootstrappers/faststream_bootstrapper.py @@ -12,7 +12,6 @@ if import_checker.is_faststream_installed: - from faststream._internal.broker import BrokerUsecase from faststream.asgi import AsgiFastStream, AsgiResponse from faststream.asgi import get as handle_get @@ -50,8 +49,7 @@ def __init__( @dataclasses.dataclass(kw_only=True, slots=True, frozen=True) class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, SentryConfig): - application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream()) - broker: typing.Optional["BrokerUsecase[typing.Any, typing.Any]"] = None + application: "AsgiFastStream" opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None health_checks_additional_checker: typing.Callable[[], typing.Coroutine[bool, typing.Any, typing.Any]] | None = None @@ -160,8 +158,6 @@ def is_ready(self) -> bool: def __init__(self, bootstrap_config: FastStreamConfig) -> None: super().__init__(bootstrap_config) - if self.bootstrap_config.broker: - self.bootstrap_config.application.set_broker(self.bootstrap_config.broker) self.bootstrap_config.application.on_shutdown(self.teardown) def _prepare_application(self) -> "AsgiFastStream": diff --git a/tests/test_faststream_bootstrap.py b/tests/test_faststream_bootstrap.py index 0883e7f..ffef06e 100644 --- a/tests/test_faststream_bootstrap.py +++ b/tests/test_faststream_bootstrap.py @@ -1,5 +1,6 @@ import typing +import faststream.asgi import pytest import structlog from faststream._internal.broker import BrokerUsecase @@ -39,8 +40,12 @@ def build_faststream_config( sentry_dsn="https://testdsn@localhost/1", health_checks_path="/custom-health/", logging_buffer_capacity=0, - broker=broker, health_checks_additional_checker=health_checks_additional_checker, + application=faststream.asgi.AsgiFastStream( + broker, + asyncapi_path=faststream.asgi.AsyncAPIRoute("/docs/"), + specification=faststream.AsyncAPI(), + ), ) @@ -64,6 +69,9 @@ async def test_faststream_bootstrap(broker: RedisBroker) -> None: response = test_client.get(bootstrap_config.prometheus_metrics_path) assert response.status_code == status.HTTP_200_OK + response = test_client.get("/docs/") + assert response.status_code == status.HTTP_200_OK + assert not bootstrapper.is_bootstrapped @@ -94,7 +102,7 @@ async def custom_checker() -> bool: def test_faststream_bootstrapper_not_ready() -> None: with emulate_package_missing("faststream"), pytest.raises(RuntimeError, match="faststream is not installed"): - FastStreamBootstrapper(bootstrap_config=FastStreamConfig()) + FastStreamBootstrapper(bootstrap_config=FastStreamConfig(application=faststream.asgi.AsgiFastStream())) @pytest.mark.parametrize(