test_celery_rmq_broker.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. from unittest import mock
  2. import pytest
  3. from clean_python.amqp import CeleryRmqBroker
  4. @pytest.fixture
  5. def celery_rmq_broker():
  6. return CeleryRmqBroker("amqp://rmq:1234//", "some_queue", "host", False)
  7. @mock.patch("clean_python.amqp.celery_rmq_broker.pika.BlockingConnection")
  8. async def test_celery_rmq_broker(connection, celery_rmq_broker):
  9. await celery_rmq_broker.add({"task": "some.task", "args": ["foo", 15]})
  10. channel = connection().__enter__().channel()
  11. _, call_kwargs = channel.basic_publish.call_args
  12. assert call_kwargs["exchange"] == ""
  13. assert call_kwargs["routing_key"] == "some_queue"
  14. assert call_kwargs["body"] == '[["foo", 15], {}, null]'
  15. task_id = call_kwargs["properties"].correlation_id
  16. assert call_kwargs["properties"].headers["id"] == task_id
  17. assert call_kwargs["properties"].headers["root_id"] == task_id
  18. assert call_kwargs["properties"].headers["parent_id"] is None
  19. assert call_kwargs["properties"].headers["group"] is None
  20. assert call_kwargs["properties"].headers["lang"] == "py"
  21. assert call_kwargs["properties"].headers["task"] == "some.task"
  22. assert call_kwargs["properties"].headers["origin"] == "host"
  23. assert call_kwargs["properties"].headers["argsrepr"] == '["foo", 15]'
  24. assert call_kwargs["properties"].headers["kwargsrepr"] == "{}"