"""Tests for crmeb target_path detection.""" from __future__ import annotations import pytest CRMEB_FIND_CMD = "find /www/wwwroot -iname 'crmeb' -type d -print -quit 2>/dev/null" @pytest.mark.asyncio async def test_detect_and_save_target_path_finds_crmeb(monkeypatch): from server.application.server_batch_common import detect_and_save_target_path from server.domain.models import Server server = Server(id=7, name="t", domain="shop.example.com", username="root", target_path="") captured: dict[str, str] = {} async def fake_exec(srv, cmd, timeout=30): captured["cmd"] = cmd return { "exit_code": 0, "stdout": "/www/wwwroot/shop.example.com/crmeb\n", "stderr": "", } async def fake_update(sid, path): captured["sid"] = sid captured["path"] = path monkeypatch.setattr( "server.infrastructure.ssh.asyncssh_pool.exec_ssh_command", fake_exec, ) monkeypatch.setattr( "server.application.server_batch_common.update_server_target_path", fake_update, ) outcome = await detect_and_save_target_path(server) assert outcome["success"] is True assert outcome["target_dir"] == "/www/wwwroot/shop.example.com/crmeb" assert CRMEB_FIND_CMD in captured["cmd"] assert captured["path"] == "/www/wwwroot/shop.example.com/crmeb" @pytest.mark.asyncio async def test_detect_and_save_target_path_not_found(monkeypatch): from server.application.server_batch_common import detect_and_save_target_path from server.domain.models import Server server = Server(id=9, name="t", domain="missing.example.com", username="root") async def fake_exec(srv, cmd, timeout=30): return {"exit_code": 0, "stdout": "", "stderr": ""} monkeypatch.setattr( "server.infrastructure.ssh.asyncssh_pool.exec_ssh_command", fake_exec, ) outcome = await detect_and_save_target_path(server) assert outcome["success"] is False assert "crmeb" in str(outcome["error"])