Skip to content

Commit 478a179

Browse files
committed
tests(aio-pika): Add tests to verify params combination
Signed-off-by: Varsha GS <[email protected]>
1 parent be45046 commit 478a179

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

tests/clients/test_aio_pika.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _resource(self) -> Generator[None, None, None]:
3030
# Ensure that allow_exit_as_root has the default value
3131
agent.options.allow_exit_as_root = False
3232

33-
async def publish_message(self) -> None:
33+
async def publish_message(self, params_combination: str = "both_args") -> None:
3434
# Perform connection
3535
connection = await connect()
3636

@@ -46,11 +46,21 @@ async def publish_message(self) -> None:
4646
exchange = await channel.declare_exchange("test.exchange")
4747
await queue.bind(exchange, routing_key=queue_name)
4848

49+
message = Message(f"Hello {queue_name}".encode())
50+
51+
args = ()
52+
kwargs = {}
53+
54+
if params_combination == "both_args":
55+
args = (message, queue_name)
56+
elif params_combination == "both_kwargs":
57+
kwargs = {"message": message, "routing_key": queue_name}
58+
elif params_combination == "arg_kwarg":
59+
args = (message,)
60+
kwargs = {"routing_key": queue_name}
61+
4962
# Sending the message
50-
await exchange.publish(
51-
Message(f"Hello {queue_name}".encode()),
52-
routing_key=queue_name,
53-
)
63+
await exchange.publish(*args, **kwargs)
5464

5565
async def delete_queue(self) -> None:
5666
connection = await connect()
@@ -75,9 +85,13 @@ async def consume_message(self, connect_method) -> None:
7585
if queue.name in message.body.decode():
7686
break
7787

78-
def test_basic_publish(self) -> None:
88+
@pytest.mark.parametrize(
89+
"params_combination",
90+
["both_args", "both_kwargs", "arg_kwarg"],
91+
)
92+
def test_basic_publish(self, params_combination) -> None:
7993
with tracer.start_as_current_span("test"):
80-
self.loop.run_until_complete(self.publish_message())
94+
self.loop.run_until_complete(self.publish_message(params_combination))
8195

8296
spans = self.recorder.queued_spans()
8397
assert len(spans) == 2

0 commit comments

Comments
 (0)