Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldygg committed Nov 26, 2024
1 parent 64c22b4 commit 51d7f6a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/brokers/base/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def patch_broker(
) -> BrokerUsecase:
return broker

async def test_broker_middleware_order(self, queue: str, mock: Mock):
async def test_broker_middleware_order(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def consume_scope(self, call_next, msg):
mock.consume_inner()
Expand Down Expand Up @@ -57,7 +57,7 @@ async def publish_scope(self, call_next, msg, *args, **kwargs):
async def handler(msg):
pass

async with self.patch_broker(broker) as br:
async with self.patch_broker(raw_broker, broker) as br:
await br.publish(None, queue)

mock.consume_inner.assert_called_once()
Expand All @@ -68,7 +68,7 @@ async def handler(msg):
assert [c.args[0] for c in mock.sub.call_args_list] == ["outer", "inner"]
assert [c.args[0] for c in mock.pub.call_args_list] == ["outer", "inner"]

async def test_publisher_middleware_order(self, queue: str, mock: Mock):
async def test_publisher_middleware_order(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def publish_scope(self, call_next, msg, *args, **kwargs):
mock.publish_inner()
Expand Down Expand Up @@ -102,7 +102,7 @@ async def publish_scope(self, call_next, msg, *args, **kwargs):
async def handler(msg):
pass

async with self.patch_broker(broker):
async with self.patch_broker(raw_broker, broker):
await publisher.publish(None, queue)

mock.publish_inner.assert_called_once()
Expand All @@ -111,7 +111,7 @@ async def handler(msg):

assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]

async def test_publisher_with_router_middleware_order(self, queue: str, mock: Mock):
async def test_publisher_with_router_middleware_order(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def publish_scope(self, call_next, msg, *args, **kwargs):
mock.publish_inner()
Expand Down Expand Up @@ -145,7 +145,7 @@ async def handler(msg):
router.include_router(router2)
broker.include_router(router)

async with self.patch_broker(broker):
async with self.patch_broker(raw_broker, broker):
await publisher.publish(None, queue)

mock.publish_inner.assert_called_once()
Expand All @@ -154,7 +154,7 @@ async def handler(msg):

assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]

async def test_consume_middleware_order(self, queue: str, mock: Mock):
async def test_consume_middleware_order(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def consume_scope(self, call_next, msg):
mock.consume_inner()
Expand Down Expand Up @@ -187,7 +187,7 @@ async def consume_scope(self, call_next, msg):
async def handler(msg):
pass

async with self.patch_broker(broker) as br:
async with self.patch_broker(raw_broker, broker) as br:
await br.publish(None, queue)

mock.consume_inner.assert_called_once()
Expand All @@ -196,7 +196,7 @@ async def handler(msg):

assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]

async def test_consume_with_middleware_order(self, queue: str, mock: Mock):
async def test_consume_with_middleware_order(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def consume_scope(self, call_next, msg):
mock.consume_inner()
Expand Down Expand Up @@ -227,7 +227,7 @@ async def handler(msg):

router.include_router(router2)
broker.include_router(router)
async with self.patch_broker(broker) as br:
async with self.patch_broker(raw_broker, broker) as br:
await br.publish(None, queue)

mock.consume_inner.assert_called_once()
Expand All @@ -236,7 +236,7 @@ async def handler(msg):

assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]

async def test_aenter_aexit(self, queue: str, mock: Mock):
async def test_aenter_aexit(self, queue: str, mock: Mock, raw_broker):
class InnerMiddleware(BaseMiddleware):
async def __aenter__(self):
mock.enter_inner()
Expand Down Expand Up @@ -274,10 +274,10 @@ async def __aexit__(
args, kwargs = self.get_subscriber_params(queue)

@broker.subscriber(*args, **kwargs)
async def handler(msg):
async def handler_sub(msg):
pass

async with self.patch_broker(broker) as br:
async with self.patch_broker(raw_broker, broker) as br:
await br.publish(None, queue)

mock.enter_inner.assert_called_once()
Expand Down
5 changes: 5 additions & 0 deletions tests/brokers/confluent/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.brokers.base.middlewares import (
ExceptionMiddlewareTestcase,
MiddlewareTestcase,
MiddlewaresOrderTestcase,
)

from .basic import ConfluentTestcaseConfig
Expand All @@ -17,3 +18,7 @@ class TestMiddlewares(ConfluentTestcaseConfig, MiddlewareTestcase):
@pytest.mark.confluent
class TestExceptionMiddlewares(ConfluentTestcaseConfig, ExceptionMiddlewareTestcase):
broker_class = KafkaBroker

@pytest.mark.confluent
class TestMiddlewaresOrder(MiddlewaresOrderTestcase):
broker_class = KafkaBroker
5 changes: 5 additions & 0 deletions tests/brokers/kafka/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.brokers.base.middlewares import (
ExceptionMiddlewareTestcase,
MiddlewareTestcase,
MiddlewaresOrderTestcase,
)


Expand All @@ -15,3 +16,7 @@ class TestMiddlewares(MiddlewareTestcase):
@pytest.mark.kafka
class TestExceptionMiddlewares(ExceptionMiddlewareTestcase):
broker_class = KafkaBroker

@pytest.mark.kafka
class TestMiddlewaresOrder(MiddlewaresOrderTestcase):
broker_class = KafkaBroker
23 changes: 23 additions & 0 deletions tests/brokers/nats/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from faststream.nats import NatsBroker
from tests.brokers.base.middlewares import (
ExceptionMiddlewareTestcase,
MiddlewareTestcase,
MiddlewaresOrderTestcase,
)


@pytest.mark.nats
class TestMiddlewares(MiddlewareTestcase):
broker_class = NatsBroker


@pytest.mark.nats
class TestExceptionMiddlewares(ExceptionMiddlewareTestcase):
broker_class = NatsBroker


@pytest.mark.nats
class TestMiddlewaresOrder(MiddlewaresOrderTestcase):
broker_class = NatsBroker
5 changes: 5 additions & 0 deletions tests/brokers/rabbit/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.brokers.base.middlewares import (
ExceptionMiddlewareTestcase,
MiddlewareTestcase,
MiddlewaresOrderTestcase,
)


Expand All @@ -15,3 +16,7 @@ class TestMiddlewares(MiddlewareTestcase):
@pytest.mark.rabbit
class TestExceptionMiddlewares(ExceptionMiddlewareTestcase):
broker_class = RabbitBroker

@pytest.mark.rabbit
class TestMiddlewaresOrder(MiddlewaresOrderTestcase):
broker_class = RabbitBroker
5 changes: 5 additions & 0 deletions tests/brokers/redis/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.brokers.base.middlewares import (
ExceptionMiddlewareTestcase,
MiddlewareTestcase,
MiddlewaresOrderTestcase,
)


Expand All @@ -15,3 +16,7 @@ class TestMiddlewares(MiddlewareTestcase):
@pytest.mark.redis
class TestExceptionMiddlewares(ExceptionMiddlewareTestcase):
broker_class = RedisBroker

@pytest.mark.redis
class TestMiddlewaresOrder(MiddlewaresOrderTestcase):
broker_class = RedisBroker

0 comments on commit 51d7f6a

Please sign in to comment.