import pytest import time import sys import os import requests # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) from api_hook_client import ApiHookClient def test_client_wait_for_server(live_gui): """Verifies that the client can wait for the server to become ready.""" client = ApiHookClient() assert client.wait_for_server(timeout=5) is True def test_client_get_performance_retry(live_gui): """Verifies that the client can retrieve metrics correctly.""" client = ApiHookClient() perf = client.get_performance() assert "performance" in perf def test_client_connection_error(): """Verifies that the client raises a Connection or Timeout error when the server is down.""" # Use a port that is unlikely to be in use and not intercepted client = ApiHookClient(base_url="http://127.0.0.1:9998", max_retries=1, retry_delay=0.1) with pytest.raises((requests.exceptions.ConnectionError, requests.exceptions.Timeout)): client.get_project()