|
5 | 5 | from configmanager import Config
|
6 | 6 |
|
7 | 7 | P2P_PUB_URI = "/api/v0/p2p/pubsub/pub"
|
| 8 | +POST_MESSAGES_URI = "/api/v0/messages" |
8 | 9 |
|
9 | 10 | MESSAGE_DICT = {
|
10 | 11 | "chain": "NULS2",
|
@@ -63,3 +64,37 @@ async def test_pubsub_pub_errors(ccn_api_client, mock_config: Config):
|
63 | 64 | P2P_PUB_URI, json={"topic": message_topic, "data": json.dumps(message_dict)}
|
64 | 65 | )
|
65 | 66 | assert response.status == 422, await response.text()
|
| 67 | + |
| 68 | + |
| 69 | +@pytest.mark.asyncio |
| 70 | +async def test_post_message_sync(ccn_api_client, mocker): |
| 71 | + # Mock the functions used to create the RabbitMQ queue |
| 72 | + mocker.patch("aleph.web.controllers.p2p.get_mq_channel_from_request") |
| 73 | + mocked_queue = mocker.patch( |
| 74 | + "aleph.web.controllers.p2p.mq_make_aleph_message_topic_queue" |
| 75 | + ) |
| 76 | + |
| 77 | + # Create a mock MQ response object |
| 78 | + mock_mq_message = mocker.Mock() |
| 79 | + mock_mq_message.routing_key = f"processed.{MESSAGE_DICT['item_hash']}" |
| 80 | + mocker.patch( |
| 81 | + "aleph.web.controllers.p2p._mq_read_one_message", return_value=mock_mq_message |
| 82 | + ) |
| 83 | + |
| 84 | + response = await ccn_api_client.post( |
| 85 | + POST_MESSAGES_URI, |
| 86 | + json={ |
| 87 | + "message": MESSAGE_DICT, |
| 88 | + "sync": True, |
| 89 | + }, |
| 90 | + ) |
| 91 | + |
| 92 | + assert response.status == 200, await response.text() |
| 93 | + json_response = await response.json() |
| 94 | + pub_status = json_response["publication_status"] |
| 95 | + assert json_response["message_status"] == "processed" |
| 96 | + assert pub_status["status"] == "success" |
| 97 | + assert pub_status["failed"] == [] |
| 98 | + |
| 99 | + # Check that we cleaned up the queue |
| 100 | + assert mocked_queue.delete.called_once |
0 commit comments