From 9b2b60146ed94936cc9abe987d4a5caa9cc8af75 Mon Sep 17 00:00:00 2001 From: DanielePalaia Date: Fri, 13 Dec 2024 09:32:34 +0100 Subject: [PATCH] adding publisher basic test --- examples/getting_started/main.py | 3 +-- rabbitmq_amqp_python_client/__init__.py | 3 +++ tests/test_publisher.py | 32 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/test_publisher.py diff --git a/examples/getting_started/main.py b/examples/getting_started/main.py index 165a4c3..e84fc13 100644 --- a/examples/getting_started/main.py +++ b/examples/getting_started/main.py @@ -1,9 +1,8 @@ -from proton import Message - from rabbitmq_amqp_python_client import ( BindingSpecification, Connection, ExchangeSpecification, + Message, QueueSpecification, QueueType, exchange_address, diff --git a/rabbitmq_amqp_python_client/__init__.py b/rabbitmq_amqp_python_client/__init__.py index 9b2949b..4d53bde 100644 --- a/rabbitmq_amqp_python_client/__init__.py +++ b/rabbitmq_amqp_python_client/__init__.py @@ -1,5 +1,7 @@ from importlib import metadata +from proton import Message + from .address_helper import exchange_address from .common import QueueType from .connection import Connection @@ -27,4 +29,5 @@ "QueueType", "Publisher", "exchange_address", + "Message", ] diff --git a/tests/test_publisher.py b/tests/test_publisher.py new file mode 100644 index 0000000..e437aa4 --- /dev/null +++ b/tests/test_publisher.py @@ -0,0 +1,32 @@ +from rabbitmq_amqp_python_client import ( + Connection, + Message, + QueueSpecification, + QueueType, +) + + +def test_bind_exchange_to_queue() -> None: + connection = Connection("amqp://guest:guest@localhost:5672/") + connection.dial() + + queue_name = "test-queue" + management = connection.management() + + management.declare_queue( + QueueSpecification(name=queue_name, queue_type=QueueType.quorum, arguments={}) + ) + + raised = False + + try: + publisher = connection.publisher("/queues/" + queue_name) + publisher.publish(Message(body="test")) + except Exception: + raised = True + + assert raised is False + + publisher.close() + # Still not working + # management.delete_queue(queue_name)