Skip to content

Commit

Permalink
AsyncAPI 3.0.0 Redis arguments tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KrySeyt committed Jul 31, 2024
1 parent a2300a2 commit 8de3846
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/asyncapi/redis/v3_0_0/test_arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from faststream.asyncapi.generate import get_app_schema
from faststream.redis import RedisBroker, StreamSub
from tests.asyncapi.base.v3_0_0.arguments import ArgumentsTestcase


class TestArguments(ArgumentsTestcase):
broker_class = RedisBroker

def test_channel_subscriber(self):
broker = self.broker_class()

@broker.subscriber("test")
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"redis": {
"bindingVersion": "custom",
"channel": "test",
"method": "subscribe",
}
}

def test_channel_pattern_subscriber(self):
broker = self.broker_class()

@broker.subscriber("test.{path}")
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"redis": {
"bindingVersion": "custom",
"channel": "test.*",
"method": "psubscribe",
}
}

def test_list_subscriber(self):
broker = self.broker_class()

@broker.subscriber(list="test")
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"redis": {"bindingVersion": "custom", "channel": "test", "method": "lpop"}
}

def test_stream_subscriber(self):
broker = self.broker_class()

@broker.subscriber(stream="test")
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"redis": {"bindingVersion": "custom", "channel": "test", "method": "xread"}
}

def test_stream_group_subscriber(self):
broker = self.broker_class()

@broker.subscriber(stream=StreamSub("test", group="group", consumer="consumer"))
async def handle(msg): ...

schema = get_app_schema(self.build_app(broker)).to_jsonable()
key = tuple(schema["channels"].keys())[0] # noqa: RUF015

assert schema["channels"][key]["bindings"] == {
"redis": {
"bindingVersion": "custom",
"channel": "test",
"consumer_name": "consumer",
"group_name": "group",
"method": "xreadgroup",
}
}

0 comments on commit 8de3846

Please sign in to comment.