Skip to content

Commit ae56b54

Browse files
authored
Merge pull request #55 from modern-python/required-app-faststream
make app required for faststream bootstrapper
2 parents e12b663 + 4ceddb6 commit ae56b54

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lite_bootstrap/bootstrappers/faststream_bootstrapper.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
if import_checker.is_faststream_installed:
15-
from faststream._internal.broker import BrokerUsecase
1615
from faststream.asgi import AsgiFastStream, AsgiResponse
1716
from faststream.asgi import get as handle_get
1817

@@ -50,8 +49,7 @@ def __init__(
5049

5150
@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
5251
class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, SentryConfig):
53-
application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream())
54-
broker: typing.Optional["BrokerUsecase[typing.Any, typing.Any]"] = None
52+
application: "AsgiFastStream"
5553
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
5654
prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None
5755
health_checks_additional_checker: typing.Callable[[], typing.Coroutine[bool, typing.Any, typing.Any]] | None = None
@@ -160,8 +158,6 @@ def is_ready(self) -> bool:
160158

161159
def __init__(self, bootstrap_config: FastStreamConfig) -> None:
162160
super().__init__(bootstrap_config)
163-
if self.bootstrap_config.broker:
164-
self.bootstrap_config.application.set_broker(self.bootstrap_config.broker)
165161
self.bootstrap_config.application.on_shutdown(self.teardown)
166162

167163
def _prepare_application(self) -> "AsgiFastStream":

tests/test_faststream_bootstrap.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typing
22

3+
import faststream.asgi
34
import pytest
45
import structlog
56
from faststream._internal.broker import BrokerUsecase
@@ -39,8 +40,12 @@ def build_faststream_config(
3940
sentry_dsn="https://testdsn@localhost/1",
4041
health_checks_path="/custom-health/",
4142
logging_buffer_capacity=0,
42-
broker=broker,
4343
health_checks_additional_checker=health_checks_additional_checker,
44+
application=faststream.asgi.AsgiFastStream(
45+
broker,
46+
asyncapi_path=faststream.asgi.AsyncAPIRoute("/docs/"),
47+
specification=faststream.AsyncAPI(),
48+
),
4449
)
4550

4651

@@ -64,6 +69,9 @@ async def test_faststream_bootstrap(broker: RedisBroker) -> None:
6469
response = test_client.get(bootstrap_config.prometheus_metrics_path)
6570
assert response.status_code == status.HTTP_200_OK
6671

72+
response = test_client.get("/docs/")
73+
assert response.status_code == status.HTTP_200_OK
74+
6775
assert not bootstrapper.is_bootstrapped
6876

6977

@@ -94,7 +102,7 @@ async def custom_checker() -> bool:
94102

95103
def test_faststream_bootstrapper_not_ready() -> None:
96104
with emulate_package_missing("faststream"), pytest.raises(RuntimeError, match="faststream is not installed"):
97-
FastStreamBootstrapper(bootstrap_config=FastStreamConfig())
105+
FastStreamBootstrapper(bootstrap_config=FastStreamConfig(application=faststream.asgi.AsgiFastStream()))
98106

99107

100108
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)