# tests/test_response_compressor.py
"""
Unit tests for the response compressor utility.
"""
import pytest
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from fctr_okta_mcp.utils.response_compressor import compress_response
class TestCompressResponse:
"""Tests for response compression."""
def test_returns_same_for_small_response(self):
"""Should return same response if under size limit."""
response = {"status": "success", "data": [{"id": "123"}]}
result = compress_response(response)
assert result == response
def test_handles_none(self):
"""Should handle None input."""
result = compress_response(None)
assert result is None
def test_handles_empty_dict(self):
"""Should handle empty dict."""
result = compress_response({})
assert result == {}
def test_handles_string(self):
"""Should handle string input."""
result = compress_response("test string")
assert result == "test string"
def test_handles_list(self):
"""Should handle list input."""
result = compress_response([1, 2, 3])
assert result == [1, 2, 3]
def test_handles_nested_structure(self):
"""Should handle nested data structures."""
response = {
"status": "success",
"data": [
{
"id": "123",
"profile": {
"firstName": "John",
"lastName": "Doe",
"nested": {
"deep": "value"
}
}
}
]
}
result = compress_response(response)
# Should preserve structure for small responses
assert result["data"][0]["profile"]["nested"]["deep"] == "value"
def test_large_response_truncation(self):
"""Should truncate very large responses."""
# Create a large response that exceeds typical limits
large_data = [{"id": str(i), "data": "x" * 1000} for i in range(1000)]
response = {"status": "success", "data": large_data}
result = compress_response(response)
# Result should be smaller or have truncation indicator
# The exact behavior depends on implementation
assert result is not None