Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,43 @@

import pytest

from mcp_acp.server import (
_format_bulk_result,
_format_clusters,
_format_logs,
_format_result,
_format_sessions_list,
_format_whoami,
call_tool,
list_tools,
from mcp_acp.formatters import (
format_bulk_result,
format_clusters,
format_logs,
format_result,
format_sessions_list,
format_whoami,
)
from mcp_acp.server import call_tool, list_tools


class TestServerFormatters:
"""Tests for server formatting functions."""

def test_format_result_dry_run(self) -> None:
def testformat_result_dry_run(self) -> None:
"""Test formatting dry run results."""
result = {
"dry_run": True,
"message": "Would delete session",
"session_info": {"name": "test-session", "status": "running"},
}

output = _format_result(result)
output = format_result(result)

assert "DRY RUN MODE" in output
assert "Would delete session" in output
assert "test-session" in output

def test_format_result_normal(self) -> None:
def testformat_result_normal(self) -> None:
"""Test formatting normal results."""
result = {"deleted": True, "message": "Successfully deleted session"}

output = _format_result(result)
output = format_result(result)

assert "Successfully deleted session" in output

def test_format_sessions_list(self) -> None:
def testformat_sessions_list(self) -> None:
"""Test formatting sessions list."""
result = {
"total": 2,
Expand All @@ -66,15 +65,15 @@ def test_format_sessions_list(self) -> None:
],
}

output = _format_sessions_list(result)
output = format_sessions_list(result)

assert "Found 2 session(s)" in output
assert "session-1" in output
assert "Test Session" in output
assert "session-2" in output
assert "running" in output

def test_format_bulk_result_delete_dry_run(self) -> None:
def testformat_bulk_result_delete_dry_run(self) -> None:
"""Test formatting bulk delete dry run."""
result = {
"dry_run": True,
Expand All @@ -87,7 +86,7 @@ def test_format_bulk_result_delete_dry_run(self) -> None:
},
}

output = _format_bulk_result(result, "delete")
output = format_bulk_result(result, "delete")

assert "DRY RUN MODE" in output
assert "Would delete 2 session(s)" in output
Expand All @@ -96,14 +95,14 @@ def test_format_bulk_result_delete_dry_run(self) -> None:
assert "Not found" in output
assert "session-3" in output

def test_format_bulk_result_delete_normal(self) -> None:
def testformat_bulk_result_delete_normal(self) -> None:
"""Test formatting bulk delete normal mode."""
result = {
"deleted": ["session-1", "session-2"],
"failed": [{"session": "session-3", "error": "Not found"}],
}

output = _format_bulk_result(result, "delete")
output = format_bulk_result(result, "delete")

assert "Successfully deleted 2 session(s)" in output
assert "session-1" in output
Expand All @@ -112,7 +111,7 @@ def test_format_bulk_result_delete_normal(self) -> None:
assert "session-3" in output
assert "Not found" in output

def test_format_bulk_result_stop_dry_run(self) -> None:
def testformat_bulk_result_stop_dry_run(self) -> None:
"""Test formatting bulk stop dry run."""
result = {
"dry_run": True,
Expand All @@ -126,38 +125,38 @@ def test_format_bulk_result_stop_dry_run(self) -> None:
},
}

output = _format_bulk_result(result, "stop")
output = format_bulk_result(result, "stop")

assert "DRY RUN MODE" in output
assert "Would stop 1 session(s)" in output
assert "session-1" in output
assert "Not running" in output
assert "session-2" in output

def test_format_logs(self) -> None:
def testformat_logs(self) -> None:
"""Test formatting logs."""
result = {
"logs": "2024-01-20 10:00:00 INFO Starting\n2024-01-20 10:00:01 INFO Ready\n",
"container": "runner",
"lines": 3,
}

output = _format_logs(result)
output = format_logs(result)

assert "container 'runner'" in output
assert "3 lines" in output
assert "Starting" in output
assert "Ready" in output

def test_format_logs_error(self) -> None:
def testformat_logs_error(self) -> None:
"""Test formatting logs with error."""
result = {"error": "Pod not found"}

output = _format_logs(result)
output = format_logs(result)

assert "Error: Pod not found" in output

def test_format_clusters(self) -> None:
def testformat_clusters(self) -> None:
"""Test formatting clusters list."""
result = {
"clusters": [
Expand All @@ -179,23 +178,23 @@ def test_format_clusters(self) -> None:
"default_cluster": "test-cluster",
}

output = _format_clusters(result)
output = format_clusters(result)

assert "test-cluster [DEFAULT]" in output
assert "prod-cluster" in output
assert "Test Cluster" in output
assert "Production Cluster" in output
assert "https://api.test.example.com:443" in output

def test_format_clusters_empty(self) -> None:
def testformat_clusters_empty(self) -> None:
"""Test formatting empty clusters list."""
result = {"clusters": [], "default_cluster": None}

output = _format_clusters(result)
output = format_clusters(result)

assert "No clusters configured" in output

def test_format_whoami_authenticated(self) -> None:
def testformat_whoami_authenticated(self) -> None:
"""Test formatting whoami when authenticated."""
result = {
"authenticated": True,
Expand All @@ -205,15 +204,15 @@ def test_format_whoami_authenticated(self) -> None:
"token_valid": True,
}

output = _format_whoami(result)
output = format_whoami(result)

assert "Authenticated: Yes" in output
assert "User: testuser" in output
assert "Server: https://api.test.example.com:443" in output
assert "Project: test-workspace" in output
assert "Token Valid: Yes" in output

def test_format_whoami_not_authenticated(self) -> None:
def testformat_whoami_not_authenticated(self) -> None:
"""Test formatting whoami when not authenticated."""
result = {
"authenticated": False,
Expand All @@ -223,7 +222,7 @@ def test_format_whoami_not_authenticated(self) -> None:
"token_valid": False,
}

output = _format_whoami(result)
output = format_whoami(result)

assert "Authenticated: No" in output
assert "not authenticated" in output
Expand Down
Loading