def test_subscribe_to_queue(mock_pikathread): """Test subscribing to a queue (producer-consumer), callback functions and unsubscribe""" transport = PikaTransport() transport.connect() mock_cb = mock.Mock() transport._subscribe(1, str(mock.sentinel.queue1), mock_cb) mock_pikathread.subscribe_queue.assert_called_once() args, kwargs = mock_pikathread.subscribe_queue.call_args assert not args assert kwargs == { "auto_ack": True, "callback": mock.ANY, "subscription_id": 1, "prefetch_count": 1, "queue": str(mock.sentinel.queue1), "reconnectable": False, } transport._subscribe(2, str(mock.sentinel.queue2), mock_cb) assert mock_pikathread.subscribe_queue.call_count == 2 args, kwargs = mock_pikathread.subscribe_queue.call_args assert not args assert kwargs == { "auto_ack": True, "callback": mock.ANY, "subscription_id": 2, "prefetch_count": 1, "queue": str(mock.sentinel.queue2), "reconnectable": False, } transport._subscribe(3, str(mock.sentinel.queue3), mock_cb, acknowledgement=True) assert mock_pikathread.subscribe_queue.call_count == 3 args, kwargs = mock_pikathread.subscribe_queue.call_args assert not args assert kwargs == { "auto_ack": False, "callback": mock.ANY, "subscription_id": 3, "prefetch_count": 1, "queue": str(mock.sentinel.queue3), "reconnectable": False, } transport._unsubscribe(1) mock_pikathread.unsubscribe.assert_called_once_with(1) transport._unsubscribe(2) mock_pikathread.unsubscribe.assert_called_with(2)
def test_subscribe_to_broadcast(mock_pikathread): """Test subscribing to a queue (producer-consumer), callback functions and unsubscribe""" mock_cb = mock.Mock() transport = PikaTransport() transport.connect() transport._subscribe_broadcast(1, str(mock.sentinel.queue1), mock_cb) mock_pikathread.subscribe_broadcast.assert_called_once() args, kwargs = mock_pikathread.subscribe_broadcast.call_args assert not args assert kwargs == { "callback": mock.ANY, "exchange": str(mock.sentinel.queue1), "subscription_id": 1, "reconnectable": False, } transport._subscribe_broadcast( 2, str(mock.sentinel.queue2), mock_cb, ) assert mock_pikathread.subscribe_broadcast.call_count == 2 args, kwargs = mock_pikathread.subscribe_broadcast.call_args assert not args assert kwargs == { "callback": mock.ANY, "exchange": str(mock.sentinel.queue2), "subscription_id": 2, "reconnectable": False, } transport._unsubscribe(1) mock_pikathread.unsubscribe.assert_called_once_with(1) transport._unsubscribe(2) mock_pikathread.unsubscribe.assert_called_with(2)