Skip to content

Commit

Permalink
✅ Modify log assertion to be more robust
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Nov 7, 2024
1 parent 8779f4a commit 25cbc79
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions acapy_agent/core/tests/test_conductor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from unittest import IsolatedAsyncioTestCase
from unittest.mock import call

import pytest

Expand Down Expand Up @@ -1202,29 +1202,56 @@ async def test_print_invite_connection(self):

test_profile = await create_test_profile(None, await builder.build_context())

# Define expected invitation URLs
expected_oob_url = "http://localhost?oob=test_oob_invite"
expected_ci_url = "http://localhost?c_i=test_ci_invite"

# Mock the InvitationRecord returned by create_invitation for OOB
mock_oob_invitation = mock.MagicMock()
mock_oob_invitation.invitation.to_url.return_value = expected_oob_url

# Mock the InvitationRecord returned by create_invitation for Connections Protocol
mock_ci_invitation = mock.MagicMock()
mock_ci_invitation.to_url.return_value = expected_ci_url

with mock.patch.object(
test_module,
"wallet_config",
return_value=(
test_profile,
DIDInfo("did", "verkey", metadata={}, method=SOV, key_type=ED25519),
),
), self.assertLogs(
"acapy_agent.core.conductor", level="INFO"
) as captured, mock.patch.object(
), mock.patch.object(
test_module, "OutboundTransportManager", autospec=True
) as mock_outbound_mgr:
) as mock_outbound_mgr, mock.patch.object(
test_module, "OutOfBandManager"
) as oob_mgr, mock.patch.object(
test_module, "ConnectionManager"
) as conn_mgr, mock.patch.object(test_module.LOGGER, "info") as mock_logger_info:
mock_outbound_mgr.return_value.registered_transports = {
"test": mock.MagicMock(schemes=["http"])
}

# Configure create_invitation to return the mocked invitations
oob_mgr.return_value.create_invitation = mock.CoroutineMock(
return_value=mock_oob_invitation
)
conn_mgr.return_value.create_invitation = mock.CoroutineMock(
return_value=(None, mock_ci_invitation)
)

# Execute the conductor lifecycle
await conductor.setup()

await conductor.start()
await conductor.stop()
await asyncio.sleep(0.1) # Allow log handlers to flush
value = captured.output
assert any("http://localhost?oob=" in msg for msg in value)
assert any("http://localhost?c_i=" in msg for msg in value)

# Assert that LOGGER.info was called twice with the expected URLs
expected_calls = [
call(f"Invitation URL:\n{expected_oob_url}"),
call(f"Invitation URL (Connections protocol):\n{expected_ci_url}"),
]
mock_logger_info.assert_has_calls(expected_calls, any_order=True)

async def test_clear_default_mediator(self):
builder: ContextBuilder = StubContextBuilder(self.test_settings)
Expand Down

0 comments on commit 25cbc79

Please sign in to comment.