Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ Also, you can run the `FastStream` application manually, as a regular async func
{!> docs_src/getting_started/manual_run/redis_base_run.py!}
```

### Testing

The service can be tested using the `TestBroker` context managers, which, by default, puts the Broker into "testing mode".

=== "AIOKafka"
```python linenums="1"
{!> docs_src/getting_started/testing/kafka_test_service.py!}
```

=== "Confluent"
```python linenums="1"
{!> docs_src/getting_started/testing/confluent_test_service.py!}
```

=== "RabbitMQ"
```python linenums="1"
{!> docs_src/getting_started/testing/rabbit_test_service.py!}
```

=== "NATS"
```python linenums="1"
{!> docs_src/getting_started/testing/nats_test_service.py!}
```

=== "Redis"
```python linenums="1"
{!> docs_src/getting_started/testing/redis_test_service.py!}
```

### Other tools integrations

If you want to use **FastStream** as part of another framework service, you probably don't need to utilize the `FastStream` object at all, as it is primarily intended as a **CLI** tool target. Instead, you can start and stop your broker as part of another framework's lifespan. You can find such examples in the [integrations section](./integrations/frameworks/index.md){.internal-link}.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/en/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -3220,7 +3220,7 @@ pip install faststream==0.3.0rc0 && pip install "faststream[redis]"
#### Misc

* chore: polishing by [@davorrunje](https://github.com/davorrunje){.external-link target="_blank"} in [https://github.com/ag2ai/faststream/pull/946](https://github.com/ag2ai/faststream/pull/946){.external-link target="_blank"}
* сhore: add manual publish btn to CI by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [https://github.com/ag2ai/faststream/pull/950](https://github.com/ag2ai/faststream/pull/950){.external-link target="_blank"}
* chore: add manual publish btn to CI by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [https://github.com/ag2ai/faststream/pull/950](https://github.com/ag2ai/faststream/pull/950){.external-link target="_blank"}
* chore: limit open dev dependency versions by [@kumaranvpl](https://github.com/kumaranvpl){.external-link target="_blank"} in [https://github.com/ag2ai/faststream/pull/953](https://github.com/ag2ai/faststream/pull/953){.external-link target="_blank"}


Expand Down
Empty file.
19 changes: 19 additions & 0 deletions docs/docs_src/getting_started/testing/confluent_test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from pydantic import ValidationError
from faststream import FastStream
from faststream.confluent import KafkaBroker, TestKafkaBroker


broker = KafkaBroker("localhost:9092")
app = FastStream(broker)


@pytest.mark.asyncio
async def test_correct() -> None:
async with TestKafkaBroker(broker) as br:
await br.publish(...)

@pytest.mark.asyncio
async def test_invalid() -> None:
async with TestKafkaBroker(broker) as br:
with pytest.raises(ValidationError): ...
19 changes: 19 additions & 0 deletions docs/docs_src/getting_started/testing/kafka_test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from pydantic import ValidationError
from faststream import FastStream
from faststream.kafka import KafkaBroker, TestKafkaBroker


broker = KafkaBroker("localhost:9092")
app = FastStream(broker)


@pytest.mark.asyncio
async def test_correct() -> None:
async with TestKafkaBroker(broker) as br:
await br.publish(...)

@pytest.mark.asyncio
async def test_invalid() -> None:
async with TestKafkaBroker(broker) as br:
with pytest.raises(ValidationError): ...
19 changes: 19 additions & 0 deletions docs/docs_src/getting_started/testing/nats_test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from pydantic import ValidationError
from faststream import FastStream
from faststream.nats import NatsBroker, TestNatsBroker


broker = NatsBroker("nats://localhost:4222")
app = FastStream(broker)


@pytest.mark.asyncio
async def test_correct() -> None:
async with TestNatsBroker(broker) as br:
await br.publish(...)

@pytest.mark.asyncio
async def test_invalid() -> None:
async with TestNatsBroker(broker) as br:
with pytest.raises(ValidationError): ...
19 changes: 19 additions & 0 deletions docs/docs_src/getting_started/testing/rabbit_test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from pydantic import ValidationError
from faststream import FastStream
from faststream.rabbit import RabbitBroker, TestRabbitBroker


broker = RabbitBroker("amqp://guest:guest@localhost:5672/")
app = FastStream(broker)


@pytest.mark.asyncio
async def test_correct() -> None:
async with TestRabbitBroker(broker) as br:
await br.publish(...)

@pytest.mark.asyncio
async def test_invalid() -> None:
async with TestRabbitBroker(broker) as br:
with pytest.raises(ValidationError): ...
19 changes: 19 additions & 0 deletions docs/docs_src/getting_started/testing/redis_test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from pydantic import ValidationError
from faststream import FastStream
from faststream.redis import RedisBroker, TestRedisBroker


broker = RedisBroker("redis://localhost:6379")
app = FastStream(broker)


@pytest.mark.asyncio
async def test_correct() -> None:
async with TestRedisBroker(broker) as br:
await br.publish(...)

@pytest.mark.asyncio
async def test_invalid() -> None:
async with TestRedisBroker(broker) as br:
with pytest.raises(ValidationError): ...
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.