|
| 1 | +from unittest.mock import patch |
| 2 | +from aries_cloudagent.connections.models.conn_record import ConnRecord |
| 3 | + |
| 4 | +import pytest |
| 5 | +from aries_cloudagent.messaging.agent_message import AgentMessage |
| 6 | +from asynctest import mock |
| 7 | + |
| 8 | +import acapy_plugin_toolbox.connections as con |
| 9 | +from aries_cloudagent.protocols.out_of_band.v1_0.messages.invitation import ( |
| 10 | + InvitationMessage, |
| 11 | +) |
| 12 | +from tests.conftest import RequestContext |
| 13 | + |
| 14 | + |
| 15 | +@pytest.fixture |
| 16 | +def connection(): |
| 17 | + yield ConnRecord() |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def message(): |
| 22 | + """Message fixture""" |
| 23 | + yield con.ReceiveInvitation( |
| 24 | + auto_accept=True, |
| 25 | + mediation_id="test_id", |
| 26 | + invitation="http://example.org?c_i=eyPartyTime", |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture |
| 31 | +def context(profile, mock_admin_connection, message): |
| 32 | + """RequestContext fixture.""" |
| 33 | + context = RequestContext(profile) |
| 34 | + context.connection_record = mock_admin_connection |
| 35 | + context.connection_ready = True |
| 36 | + context.message = message |
| 37 | + yield context |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.asyncio |
| 41 | +async def test_oobreceiveinvitationhandler(context, connection, mock_responder): |
| 42 | + """ReceiveOOBInvitationHandler test. |
| 43 | +
|
| 44 | + A unit test for the ReceiveOOBInvitationHandler class.""" |
| 45 | + receiveinv = con.ReceiveOOBInvitationHandler() |
| 46 | + mock_oob_mgr = mock.MagicMock() |
| 47 | + mock_oob_mgr.receive_invitation = mock.CoroutineMock(return_value=connection) |
| 48 | + |
| 49 | + with patch.object( |
| 50 | + AgentMessage, "assign_thread_from", mock.CoroutineMock() |
| 51 | + ) as mock_assign, patch.object( |
| 52 | + InvitationMessage, "from_url", mock.MagicMock() |
| 53 | + ) as mock_reply, patch.object( |
| 54 | + con, "OutOfBandManager", mock.MagicMock(return_value=mock_oob_mgr) |
| 55 | + ): |
| 56 | + await receiveinv.handle(context, mock_responder) |
| 57 | + mock_assign.assert_called_once() |
| 58 | + assert connection.accept |
0 commit comments