Rev gateway tests

This commit is contained in:
Cyber MacGeddon 2025-07-13 19:51:17 +01:00
parent eed008530d
commit 808cdfa64d

View file

@ -312,32 +312,35 @@ class TestConfigReceiver:
"flow2": {"name": "test_flow_2", "steps": []} "flow2": {"name": "test_flow_2", "steps": []}
} }
# Mock the flow methods # Mock the flow methods using patch.object to avoid coroutine creation during assignment
config_receiver.start_flow = AsyncMock() start_flow_mock = AsyncMock()
config_receiver.stop_flow = AsyncMock() stop_flow_mock = AsyncMock()
# Create mock message with flow1 removed and flow3 added with patch.object(config_receiver, 'start_flow', start_flow_mock), \
mock_msg = Mock() patch.object(config_receiver, 'stop_flow', stop_flow_mock):
mock_msg.value.return_value = Mock(
version="1.0", # Create mock message with flow1 removed and flow3 added
config={ mock_msg = Mock()
"flows": { mock_msg.value.return_value = Mock(
"flow2": '{"name": "test_flow_2", "steps": []}', version="1.0",
"flow3": '{"name": "test_flow_3", "steps": []}' config={
"flows": {
"flow2": '{"name": "test_flow_2", "steps": []}',
"flow3": '{"name": "test_flow_3", "steps": []}'
}
} }
} )
)
await config_receiver.on_config(mock_msg, None, None)
await config_receiver.on_config(mock_msg, None, None)
# Verify final state
# Verify final state assert "flow1" not in config_receiver.flows
assert "flow1" not in config_receiver.flows assert "flow2" in config_receiver.flows
assert "flow2" in config_receiver.flows assert "flow3" in config_receiver.flows
assert "flow3" in config_receiver.flows
# Verify operations
# Verify operations start_flow_mock.assert_called_once_with("flow3", {"name": "test_flow_3", "steps": []})
config_receiver.start_flow.assert_called_once_with("flow3", {"name": "test_flow_3", "steps": []}) stop_flow_mock.assert_called_once_with("flow1", {"name": "test_flow_1", "steps": []})
config_receiver.stop_flow.assert_called_once_with("flow1", {"name": "test_flow_1", "steps": []})
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_on_config_invalid_json_flow_data(self): async def test_on_config_invalid_json_flow_data(self):