82426b1941
新增侧栏「宝塔面板」菜单、代理 API 与连接配置页;通过 SSH 读写子机 api.json 自动写入凭据,5 分钟后台重试,含审计修复、检测缓存与并发锁。 Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
"""Tests for Baota SSH login helpers."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from server.domain.models import Server
|
|
from server.infrastructure.btpanel.ssh_login import detect_bt_panel_installed
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_detect_bt_panel_installed_uses_status_field():
|
|
server = Server(id=1, name="s", domain="1.2.3.4")
|
|
with patch(
|
|
"server.infrastructure.btpanel.ssh_login.exec_ssh_command",
|
|
new_callable=AsyncMock,
|
|
return_value={"status": "success", "stdout": "BT_OK\n", "stderr": "", "exit_code": 0},
|
|
):
|
|
assert await detect_bt_panel_installed(server) is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_detect_bt_panel_installed_failed_ssh():
|
|
server = Server(id=1, name="s", domain="1.2.3.4")
|
|
with patch(
|
|
"server.infrastructure.btpanel.ssh_login.exec_ssh_command",
|
|
new_callable=AsyncMock,
|
|
return_value={"status": "connection_error", "stdout": "", "stderr": "refused", "exit_code": -1},
|
|
):
|
|
assert await detect_bt_panel_installed(server) is False
|