|  | 
|  | 1 | +import pytest | 
|  | 2 | + | 
|  | 3 | +from mcp_clickhouse.mcp_env import ClickHouseConfig | 
|  | 4 | + | 
|  | 5 | + | 
|  | 6 | +def test_interface_http_when_secure_false(monkeypatch: pytest.MonkeyPatch): | 
|  | 7 | +    """Test that interface is set to 'http' when CLICKHOUSE_SECURE=false.""" | 
|  | 8 | +    monkeypatch.setenv("CLICKHOUSE_HOST", "localhost") | 
|  | 9 | +    monkeypatch.setenv("CLICKHOUSE_USER", "test") | 
|  | 10 | +    monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") | 
|  | 11 | +    monkeypatch.setenv("CLICKHOUSE_SECURE", "false") | 
|  | 12 | +    monkeypatch.setenv("CLICKHOUSE_PORT", "8123") | 
|  | 13 | + | 
|  | 14 | +    config = ClickHouseConfig() | 
|  | 15 | +    client_config = config.get_client_config() | 
|  | 16 | + | 
|  | 17 | +    assert client_config["interface"] == "http" | 
|  | 18 | +    assert client_config["secure"] is False | 
|  | 19 | +    assert client_config["port"] == 8123 | 
|  | 20 | + | 
|  | 21 | + | 
|  | 22 | +def test_interface_https_when_secure_true(monkeypatch: pytest.MonkeyPatch): | 
|  | 23 | +    """Test that interface is set to 'https' when CLICKHOUSE_SECURE=true.""" | 
|  | 24 | +    monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") | 
|  | 25 | +    monkeypatch.setenv("CLICKHOUSE_USER", "test") | 
|  | 26 | +    monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") | 
|  | 27 | +    monkeypatch.setenv("CLICKHOUSE_SECURE", "true") | 
|  | 28 | +    monkeypatch.setenv("CLICKHOUSE_PORT", "8443") | 
|  | 29 | + | 
|  | 30 | +    config = ClickHouseConfig() | 
|  | 31 | +    client_config = config.get_client_config() | 
|  | 32 | + | 
|  | 33 | +    assert client_config["interface"] == "https" | 
|  | 34 | +    assert client_config["secure"] is True | 
|  | 35 | +    assert client_config["port"] == 8443 | 
|  | 36 | + | 
|  | 37 | + | 
|  | 38 | +def test_interface_https_by_default(monkeypatch: pytest.MonkeyPatch): | 
|  | 39 | +    """Test that interface defaults to 'https' when CLICKHOUSE_SECURE is not set.""" | 
|  | 40 | +    monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") | 
|  | 41 | +    monkeypatch.setenv("CLICKHOUSE_USER", "test") | 
|  | 42 | +    monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") | 
|  | 43 | +    monkeypatch.delenv("CLICKHOUSE_SECURE", raising=False) | 
|  | 44 | +    monkeypatch.delenv("CLICKHOUSE_PORT", raising=False) | 
|  | 45 | + | 
|  | 46 | +    config = ClickHouseConfig() | 
|  | 47 | +    client_config = config.get_client_config() | 
|  | 48 | + | 
|  | 49 | +    assert client_config["interface"] == "https" | 
|  | 50 | +    assert client_config["secure"] is True | 
|  | 51 | +    assert client_config["port"] == 8443 | 
|  | 52 | + | 
|  | 53 | + | 
|  | 54 | +def test_interface_http_with_custom_port(monkeypatch: pytest.MonkeyPatch): | 
|  | 55 | +    """Test that interface is 'http' with custom port when CLICKHOUSE_SECURE=false.""" | 
|  | 56 | +    monkeypatch.setenv("CLICKHOUSE_HOST", "localhost") | 
|  | 57 | +    monkeypatch.setenv("CLICKHOUSE_USER", "test") | 
|  | 58 | +    monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") | 
|  | 59 | +    monkeypatch.setenv("CLICKHOUSE_SECURE", "false") | 
|  | 60 | +    monkeypatch.setenv("CLICKHOUSE_PORT", "9000") | 
|  | 61 | + | 
|  | 62 | +    config = ClickHouseConfig() | 
|  | 63 | +    client_config = config.get_client_config() | 
|  | 64 | + | 
|  | 65 | +    assert client_config["interface"] == "http" | 
|  | 66 | +    assert client_config["secure"] is False | 
|  | 67 | +    assert client_config["port"] == 9000 | 
|  | 68 | + | 
|  | 69 | + | 
|  | 70 | +def test_interface_https_with_custom_port(monkeypatch: pytest.MonkeyPatch): | 
|  | 71 | +    """Test that interface is 'https' with custom port when CLICKHOUSE_SECURE=true.""" | 
|  | 72 | +    monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") | 
|  | 73 | +    monkeypatch.setenv("CLICKHOUSE_USER", "test") | 
|  | 74 | +    monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") | 
|  | 75 | +    monkeypatch.setenv("CLICKHOUSE_SECURE", "true") | 
|  | 76 | +    monkeypatch.setenv("CLICKHOUSE_PORT", "9443") | 
|  | 77 | + | 
|  | 78 | +    config = ClickHouseConfig() | 
|  | 79 | +    client_config = config.get_client_config() | 
|  | 80 | + | 
|  | 81 | +    assert client_config["interface"] == "https" | 
|  | 82 | +    assert client_config["secure"] is True | 
|  | 83 | +    assert client_config["port"] == 9443 | 
0 commit comments