Files
mcp-proxmox/tests/conftest.py
defiQUG 68f824b17e fix(mcp): harden Proxmox MCP server tools and expand test coverage
Refine VM/cluster/storage tool handlers and auth utilities; add conftest
and extend server/console tests for more reliable operator automation.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:51:35 -07:00

60 lines
1.6 KiB
Python

"""Shared pytest fixtures for proxmox-mcp."""
from __future__ import annotations
import json
import os
from pathlib import Path
from unittest.mock import patch
import pytest
from proxmox_mcp.config.models import AuthConfig, Config, LoggingConfig, ProxmoxConfig
@pytest.fixture
def mock_env_vars():
"""Set up test environment variables."""
env_vars = {
"PROXMOX_HOST": "test.proxmox.com",
"PROXMOX_USER": "test@pve",
"PROXMOX_TOKEN_NAME": "test_token",
"PROXMOX_TOKEN_VALUE": "test_value",
"LOG_LEVEL": "DEBUG",
}
with patch.dict(os.environ, env_vars):
yield env_vars
@pytest.fixture
def test_config() -> Config:
return Config(
proxmox=ProxmoxConfig(host="test.proxmox.com", verify_ssl=False),
auth=AuthConfig(
user="test@pve",
token_name="test_token",
token_value="test_value",
),
logging=LoggingConfig(level="DEBUG"),
)
@pytest.fixture
def mock_proxmox():
"""Mock ProxmoxAPI construction."""
with patch("proxmox_mcp.core.proxmox.ProxmoxAPI") as mock:
mock.return_value.nodes.get.return_value = [
{"node": "node1", "status": "online"},
{"node": "node2", "status": "online"},
]
yield mock
@pytest.fixture
def server(mock_env_vars, mock_proxmox, test_config):
"""Create a ProxmoxMCPServer with mocked config and API."""
with patch("proxmox_mcp.server.load_config", return_value=test_config):
from proxmox_mcp.server import ProxmoxMCPServer
return ProxmoxMCPServer()