import os import pytest from teamlandkarte_mcp.azure.openai_client import AzureOpenAIClient from teamlandkarte_mcp.config import load_config # Allow these smoke tests to access the real Azure OpenAI endpoint when the # required env/config is present. pytestmark = [pytest.mark.integration, pytest.mark.allow_network] @pytest.mark.asyncio async def test_azure_openai_chat_completion_smoke() -> None: """Smoke test against a real Azure OpenAI resource (chat completion).""" cfg = load_config("config.toml") endpoint = (cfg.azure_openai.endpoint or "").strip() llm_key = os.getenv("AZURE_OPENAI_LLM_API_KEY", "").strip() if not endpoint: pytest.skip("Azure OpenAI endpoint missing in config.toml") if "YOUR-RESOURCE" in endpoint.upper(): pytest.skip("Azure OpenAI endpoint in config.toml is still a placeholder") if not endpoint.startswith("https://"): pytest.skip("Azure OpenAI endpoint must start with https://") if not llm_key: pytest.skip("AZURE_OPENAI_LLM_API_KEY is not set") if not cfg.azure_openai.chat_deployment: pytest.skip("chat_deployment not configured") client = AzureOpenAIClient( endpoint=endpoint, api_version=cfg.azure_openai.api_version, chat_deployment=cfg.azure_openai.chat_deployment, llm_api_key=llm_key, ) result = await client.chat_completion( system="You are a test assistant. Respond with JSON: {\"status\": \"ok\"}", user="ping", ) assert isinstance(result, str) assert "ok" in result