Rev gateway tests

This commit is contained in:
Cyber MacGeddon 2025-07-12 22:00:37 +01:00
parent 200506e555
commit 40253998fc

View file

@ -119,20 +119,20 @@ class TestReverseGateway:
@patch('trustgraph.rev_gateway.service.ConfigReceiver') @patch('trustgraph.rev_gateway.service.ConfigReceiver')
@patch('trustgraph.rev_gateway.service.MessageDispatcher') @patch('trustgraph.rev_gateway.service.MessageDispatcher')
@patch('pulsar.Client') @patch('pulsar.Client')
@patch('aiohttp.ClientSession')
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_reverse_gateway_connect_success(self, mock_pulsar_client, mock_dispatcher, mock_config_receiver): async def test_reverse_gateway_connect_success(self, mock_session_class, mock_pulsar_client, mock_dispatcher, mock_config_receiver):
"""Test ReverseGateway successful connection""" """Test ReverseGateway successful connection"""
mock_client_instance = MagicMock() mock_client_instance = MagicMock()
mock_pulsar_client.return_value = mock_client_instance mock_pulsar_client.return_value = mock_client_instance
gateway = ReverseGateway()
with patch('aiohttp.ClientSession') as mock_session_class:
mock_session = AsyncMock() mock_session = AsyncMock()
mock_ws = AsyncMock() mock_ws = AsyncMock()
mock_session.ws_connect.return_value = mock_ws mock_session.ws_connect.return_value = mock_ws
mock_session_class.return_value = mock_session mock_session_class.return_value = mock_session
gateway = ReverseGateway()
result = await gateway.connect() result = await gateway.connect()
assert result is True assert result is True
@ -143,19 +143,19 @@ class TestReverseGateway:
@patch('trustgraph.rev_gateway.service.ConfigReceiver') @patch('trustgraph.rev_gateway.service.ConfigReceiver')
@patch('trustgraph.rev_gateway.service.MessageDispatcher') @patch('trustgraph.rev_gateway.service.MessageDispatcher')
@patch('pulsar.Client') @patch('pulsar.Client')
@patch('aiohttp.ClientSession')
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_reverse_gateway_connect_failure(self, mock_pulsar_client, mock_dispatcher, mock_config_receiver): async def test_reverse_gateway_connect_failure(self, mock_session_class, mock_pulsar_client, mock_dispatcher, mock_config_receiver):
"""Test ReverseGateway connection failure""" """Test ReverseGateway connection failure"""
mock_client_instance = MagicMock() mock_client_instance = MagicMock()
mock_pulsar_client.return_value = mock_client_instance mock_pulsar_client.return_value = mock_client_instance
gateway = ReverseGateway()
with patch('aiohttp.ClientSession') as mock_session_class:
mock_session = AsyncMock() mock_session = AsyncMock()
mock_session.ws_connect.side_effect = Exception("Connection failed") mock_session.ws_connect.side_effect = Exception("Connection failed")
mock_session_class.return_value = mock_session mock_session_class.return_value = mock_session
gateway = ReverseGateway()
result = await gateway.connect() result = await gateway.connect()
assert result is False assert result is False