mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-11 14:15:31 +00:00
fix: typing errors in tests
This commit is contained in:
@@ -61,6 +61,7 @@ ignore = ["E501"]
|
|||||||
python_version = "3.11"
|
python_version = "3.11"
|
||||||
strict = true
|
strict = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
|
files = ["src", "tests"]
|
||||||
|
|
||||||
[[tool.mypy.overrides]]
|
[[tool.mypy.overrides]]
|
||||||
module = ["cordra.*"]
|
module = ["cordra.*"]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Unit tests for the Cordra client."""
|
"""Unit tests for the Cordra client."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -15,7 +16,7 @@ from cordra_mcp.config import CordraConfig
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config():
|
def config() -> CordraConfig:
|
||||||
"""Create a test configuration."""
|
"""Create a test configuration."""
|
||||||
return CordraConfig(
|
return CordraConfig(
|
||||||
base_url="https://test.example.com",
|
base_url="https://test.example.com",
|
||||||
@@ -26,13 +27,13 @@ def config():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client(config):
|
def client(config: CordraConfig) -> CordraClient:
|
||||||
"""Create a test client."""
|
"""Create a test client."""
|
||||||
return CordraClient(config)
|
return CordraClient(config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_cordra_object():
|
def mock_cordra_object() -> dict[str, Any]:
|
||||||
"""Create a mock CordraObject response (dictionary)."""
|
"""Create a mock CordraObject response (dictionary)."""
|
||||||
return {
|
return {
|
||||||
"type": "TestType",
|
"type": "TestType",
|
||||||
@@ -59,7 +60,7 @@ def mock_cordra_object():
|
|||||||
class TestDigitalObject:
|
class TestDigitalObject:
|
||||||
"""Test the DigitalObject model."""
|
"""Test the DigitalObject model."""
|
||||||
|
|
||||||
def test_digital_object_creation(self):
|
def test_digital_object_creation(self) -> None:
|
||||||
"""Test creating a DigitalObject."""
|
"""Test creating a DigitalObject."""
|
||||||
obj = DigitalObject(
|
obj = DigitalObject(
|
||||||
id="test/123",
|
id="test/123",
|
||||||
@@ -89,7 +90,7 @@ class TestDigitalObject:
|
|||||||
assert payload["size"] == 1024
|
assert payload["size"] == 1024
|
||||||
assert payload["filename"] == "file1.txt"
|
assert payload["filename"] == "file1.txt"
|
||||||
|
|
||||||
def test_digital_object_optional_fields(self):
|
def test_digital_object_optional_fields(self) -> None:
|
||||||
"""Test DigitalObject with only required fields."""
|
"""Test DigitalObject with only required fields."""
|
||||||
obj = DigitalObject(id="test/123", type="TestType", content={"title": "Test"})
|
obj = DigitalObject(id="test/123", type="TestType", content={"title": "Test"})
|
||||||
|
|
||||||
@@ -104,13 +105,13 @@ class TestDigitalObject:
|
|||||||
class TestCordraClient:
|
class TestCordraClient:
|
||||||
"""Test the CordraClient class."""
|
"""Test the CordraClient class."""
|
||||||
|
|
||||||
def test_client_initialization(self, config):
|
def test_client_initialization(self, config: CordraConfig) -> None:
|
||||||
"""Test client initialization."""
|
"""Test client initialization."""
|
||||||
client = CordraClient(config)
|
client = CordraClient(config)
|
||||||
assert client.config == config
|
assert client.config == config
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_object_success(self, mock_get, client, mock_cordra_object):
|
async def test_get_object_success(self, mock_get: Any, client: CordraClient, mock_cordra_object: dict[str, Any]) -> None:
|
||||||
"""Test successful object retrieval."""
|
"""Test successful object retrieval."""
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
mock_response.status_code = 200
|
mock_response.status_code = 200
|
||||||
@@ -137,7 +138,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_object_not_found(self, mock_get, client):
|
async def test_get_object_not_found(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test object not found exception."""
|
"""Test object not found exception."""
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
@@ -149,7 +150,7 @@ class TestCordraClient:
|
|||||||
assert "Resource not found" in str(exc_info.value)
|
assert "Resource not found" in str(exc_info.value)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_object_general_error(self, mock_get, client):
|
async def test_get_object_general_error(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test general error handling."""
|
"""Test general error handling."""
|
||||||
from requests import RequestException
|
from requests import RequestException
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ class TestCordraClient:
|
|||||||
assert "Failed to retrieve object test/123" in str(exc_info.value)
|
assert "Failed to retrieve object test/123" in str(exc_info.value)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_success(self, mock_get, client):
|
async def test_find_success(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test successful find operation."""
|
"""Test successful find operation."""
|
||||||
mock_response_data = {
|
mock_response_data = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -196,7 +197,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_empty_results(self, mock_get, client):
|
async def test_find_empty_results(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find with empty results."""
|
"""Test find with empty results."""
|
||||||
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -218,7 +219,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_error(self, mock_get, client):
|
async def test_find_error(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find error handling."""
|
"""Test find error handling."""
|
||||||
from requests import RequestException
|
from requests import RequestException
|
||||||
|
|
||||||
@@ -231,7 +232,7 @@ class TestCordraClient:
|
|||||||
assert "Search failed" in str(exc_info.value)
|
assert "Search failed" in str(exc_info.value)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_with_type_filter(self, mock_get, client):
|
async def test_find_with_type_filter(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with type filter constructs correct query."""
|
"""Test find operation with type filter constructs correct query."""
|
||||||
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -248,7 +249,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_with_page_size(self, mock_get, client):
|
async def test_find_with_page_size(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with custom page size."""
|
"""Test find operation with custom page size."""
|
||||||
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 50}
|
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 50}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -265,7 +266,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_with_type_and_page_size(self, mock_get, client):
|
async def test_find_with_type_and_page_size(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with both type filter and page size."""
|
"""Test find operation with both type filter and page size."""
|
||||||
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 25}
|
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 25}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -282,7 +283,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_default_params(self, mock_get, client):
|
async def test_find_default_params(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with default parameters."""
|
"""Test find operation with default parameters."""
|
||||||
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
mock_response_data = {"results": [], "size": 0, "pageNum": 0, "pageSize": 20}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -299,7 +300,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_with_page_num(self, mock_get, client):
|
async def test_find_with_page_num(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with specific page number."""
|
"""Test find operation with specific page number."""
|
||||||
mock_response_data = {"results": [], "size": 100, "pageNum": 2, "pageSize": 20}
|
mock_response_data = {"results": [], "size": 100, "pageNum": 2, "pageSize": 20}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -319,7 +320,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_find_with_custom_page_size_and_num(self, mock_get, client):
|
async def test_find_with_custom_page_size_and_num(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test find operation with custom page size and page number."""
|
"""Test find operation with custom page size and page number."""
|
||||||
mock_response_data = {"results": [], "size": 500, "pageNum": 5, "pageSize": 10}
|
mock_response_data = {"results": [], "size": 500, "pageNum": 5, "pageSize": 10}
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
@@ -339,7 +340,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_design_success(self, mock_get, client):
|
async def test_get_design_success(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test successful design object retrieval."""
|
"""Test successful design object retrieval."""
|
||||||
mock_design_data = {
|
mock_design_data = {
|
||||||
"type": "CordraDesign",
|
"type": "CordraDesign",
|
||||||
@@ -368,7 +369,7 @@ class TestCordraClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_design_authentication_error(self, mock_get, client):
|
async def test_get_design_authentication_error(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test design object retrieval with authentication error."""
|
"""Test design object retrieval with authentication error."""
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
mock_response.status_code = 403
|
mock_response.status_code = 403
|
||||||
@@ -380,7 +381,7 @@ class TestCordraClient:
|
|||||||
assert "Authentication failed" in str(exc_info.value)
|
assert "Authentication failed" in str(exc_info.value)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_design_not_found(self, mock_get, client):
|
async def test_get_design_not_found(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test design object retrieval with not found error."""
|
"""Test design object retrieval with not found error."""
|
||||||
mock_response = mock_get.return_value
|
mock_response = mock_get.return_value
|
||||||
mock_response.status_code = 404
|
mock_response.status_code = 404
|
||||||
@@ -392,7 +393,7 @@ class TestCordraClient:
|
|||||||
assert "Resource not found" in str(exc_info.value)
|
assert "Resource not found" in str(exc_info.value)
|
||||||
|
|
||||||
@patch("cordra_mcp.client.requests.Session.get")
|
@patch("cordra_mcp.client.requests.Session.get")
|
||||||
async def test_get_design_request_error(self, mock_get, client):
|
async def test_get_design_request_error(self, mock_get: Any, client: CordraClient) -> None:
|
||||||
"""Test design object retrieval with request error."""
|
"""Test design object retrieval with request error."""
|
||||||
from requests import RequestException
|
from requests import RequestException
|
||||||
|
|
||||||
@@ -407,7 +408,7 @@ class TestCordraClient:
|
|||||||
class TestCordraConfig:
|
class TestCordraConfig:
|
||||||
"""Test the CordraConfig class."""
|
"""Test the CordraConfig class."""
|
||||||
|
|
||||||
def test_default_config(self):
|
def test_default_config(self) -> None:
|
||||||
"""Test default configuration values."""
|
"""Test default configuration values."""
|
||||||
config = CordraConfig()
|
config = CordraConfig()
|
||||||
assert config.base_url == "https://localhost:8443"
|
assert config.base_url == "https://localhost:8443"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Unit tests for the MCP server."""
|
"""Unit tests for the MCP server."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -20,7 +21,7 @@ from cordra_mcp.server import (
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_digital_object():
|
def sample_digital_object() -> DigitalObject:
|
||||||
"""Create a sample DigitalObject for testing."""
|
"""Create a sample DigitalObject for testing."""
|
||||||
return DigitalObject(
|
return DigitalObject(
|
||||||
id="people/john-doe-123",
|
id="people/john-doe-123",
|
||||||
@@ -47,7 +48,9 @@ class TestGetCordraObject:
|
|||||||
"""Test the get_cordra_object resource handler."""
|
"""Test the get_cordra_object resource handler."""
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_object_success(self, mock_client, sample_digital_object):
|
async def test_get_object_success(
|
||||||
|
self, mock_client: Any, sample_digital_object: DigitalObject
|
||||||
|
) -> None:
|
||||||
"""Test successful object retrieval."""
|
"""Test successful object retrieval."""
|
||||||
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
||||||
|
|
||||||
@@ -67,7 +70,7 @@ class TestGetCordraObject:
|
|||||||
mock_client.get_object.assert_called_once_with("people/john-doe-123")
|
mock_client.get_object.assert_called_once_with("people/john-doe-123")
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_object_not_found(self, mock_client):
|
async def test_get_object_not_found(self, mock_client: Any) -> None:
|
||||||
"""Test object not found exception."""
|
"""Test object not found exception."""
|
||||||
mock_client.get_object = AsyncMock(
|
mock_client.get_object = AsyncMock(
|
||||||
side_effect=CordraNotFoundError("Object not found: people/nonexistent")
|
side_effect=CordraNotFoundError("Object not found: people/nonexistent")
|
||||||
@@ -80,7 +83,7 @@ class TestGetCordraObject:
|
|||||||
mock_client.get_object.assert_called_once_with("people/nonexistent")
|
mock_client.get_object.assert_called_once_with("people/nonexistent")
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_object_client_error(self, mock_client):
|
async def test_get_object_client_error(self, mock_client: Any) -> None:
|
||||||
"""Test general client error handling."""
|
"""Test general client error handling."""
|
||||||
mock_client.get_object = AsyncMock(
|
mock_client.get_object = AsyncMock(
|
||||||
side_effect=CordraClientError("Connection failed")
|
side_effect=CordraClientError("Connection failed")
|
||||||
@@ -94,7 +97,9 @@ class TestGetCordraObject:
|
|||||||
mock_client.get_object.assert_called_once_with("people/john-doe-123")
|
mock_client.get_object.assert_called_once_with("people/john-doe-123")
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_object_id_construction(self, mock_client, sample_digital_object):
|
async def test_object_id_construction(
|
||||||
|
self, mock_client: Any, sample_digital_object: DigitalObject
|
||||||
|
) -> None:
|
||||||
"""Test that object ID is correctly constructed from prefix and suffix."""
|
"""Test that object ID is correctly constructed from prefix and suffix."""
|
||||||
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
||||||
|
|
||||||
@@ -110,7 +115,9 @@ class TestGetCordraObject:
|
|||||||
mock_client.get_object.assert_called_with(expected_id)
|
mock_client.get_object.assert_called_with(expected_id)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_json_formatting(self, mock_client, sample_digital_object):
|
async def test_json_formatting(
|
||||||
|
self, mock_client: Any, sample_digital_object: DigitalObject
|
||||||
|
) -> None:
|
||||||
"""Test that the returned JSON is properly formatted."""
|
"""Test that the returned JSON is properly formatted."""
|
||||||
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
mock_client.get_object = AsyncMock(return_value=sample_digital_object)
|
||||||
|
|
||||||
@@ -132,7 +139,7 @@ class TestGetCordraObject:
|
|||||||
assert "payloads" in parsed_result
|
assert "payloads" in parsed_result
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_minimal_object(self, mock_client):
|
async def test_minimal_object(self, mock_client: Any) -> None:
|
||||||
"""Test handling of object with minimal data."""
|
"""Test handling of object with minimal data."""
|
||||||
minimal_object = DigitalObject(
|
minimal_object = DigitalObject(
|
||||||
id="test/minimal",
|
id="test/minimal",
|
||||||
@@ -159,7 +166,7 @@ class TestSchemaResourceFunctions:
|
|||||||
"""Test the schema resource functions."""
|
"""Test the schema resource functions."""
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_create_schema_resource_success(self, mock_client):
|
async def test_create_schema_resource_success(self, mock_client: Any) -> None:
|
||||||
"""Test successful schema resource creation."""
|
"""Test successful schema resource creation."""
|
||||||
mock_schema = DigitalObject(
|
mock_schema = DigitalObject(
|
||||||
id="test/user-schema",
|
id="test/user-schema",
|
||||||
@@ -182,7 +189,7 @@ class TestSchemaResourceFunctions:
|
|||||||
mock_client.get_schema.assert_called_once_with("User")
|
mock_client.get_schema.assert_called_once_with("User")
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_create_schema_resource_not_found(self, mock_client):
|
async def test_create_schema_resource_not_found(self, mock_client: Any) -> None:
|
||||||
"""Test schema resource creation with schema not found."""
|
"""Test schema resource creation with schema not found."""
|
||||||
mock_client.get_schema = AsyncMock(
|
mock_client.get_schema = AsyncMock(
|
||||||
side_effect=CordraNotFoundError("Schema not found")
|
side_effect=CordraNotFoundError("Schema not found")
|
||||||
@@ -197,7 +204,7 @@ class TestSchemaResourceFunctions:
|
|||||||
mock_client.get_schema.assert_called_once_with("NonExistent")
|
mock_client.get_schema.assert_called_once_with("NonExistent")
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_register_schema_resources_success(self, mock_client):
|
async def test_register_schema_resources_success(self, mock_client: Any) -> None:
|
||||||
"""Test successful schema resource registration."""
|
"""Test successful schema resource registration."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -226,7 +233,9 @@ class TestSchemaResourceFunctions:
|
|||||||
assert mock_mcp.add_resource.call_count == 3
|
assert mock_mcp.add_resource.call_count == 3
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_register_schema_resources_missing_name(self, mock_client):
|
async def test_register_schema_resources_missing_name(
|
||||||
|
self, mock_client: Any
|
||||||
|
) -> None:
|
||||||
"""Test schema resource registration with objects missing name field."""
|
"""Test schema resource registration with objects missing name field."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -249,7 +258,9 @@ class TestSchemaResourceFunctions:
|
|||||||
assert mock_mcp.add_resource.call_count == 2
|
assert mock_mcp.add_resource.call_count == 2
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_register_schema_resources_client_error(self, mock_client):
|
async def test_register_schema_resources_client_error(
|
||||||
|
self, mock_client: Any
|
||||||
|
) -> None:
|
||||||
"""Test schema resource registration with client error."""
|
"""Test schema resource registration with client error."""
|
||||||
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
||||||
|
|
||||||
@@ -263,7 +274,7 @@ class TestSchemaResourceFunctions:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_register_schema_resources_pagination(self, mock_client):
|
async def test_register_schema_resources_pagination(self, mock_client: Any) -> None:
|
||||||
"""Test schema resource registration with pagination."""
|
"""Test schema resource registration with pagination."""
|
||||||
# Mock multiple pages of results
|
# Mock multiple pages of results
|
||||||
# First page with full 20 results (simulating more schemas)
|
# First page with full 20 results (simulating more schemas)
|
||||||
@@ -309,7 +320,7 @@ class TestSearchObjects:
|
|||||||
"""Test the search_objects tool."""
|
"""Test the search_objects tool."""
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_success(self, mock_client):
|
async def test_search_objects_success(self, mock_client: Any) -> None:
|
||||||
"""Test successful object search."""
|
"""Test successful object search."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -345,7 +356,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_with_type_filter(self, mock_client):
|
async def test_search_objects_with_type_filter(self, mock_client: Any) -> None:
|
||||||
"""Test object search with type filter."""
|
"""Test object search with type filter."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -374,7 +385,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_with_limit(self, mock_client):
|
async def test_search_objects_with_limit(self, mock_client: Any) -> None:
|
||||||
"""Test object search with custom limit."""
|
"""Test object search with custom limit."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -403,7 +414,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_with_all_parameters(self, mock_client):
|
async def test_search_objects_with_all_parameters(self, mock_client: Any) -> None:
|
||||||
"""Test object search with all parameters."""
|
"""Test object search with all parameters."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -432,7 +443,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_empty_results(self, mock_client):
|
async def test_search_objects_empty_results(self, mock_client: Any) -> None:
|
||||||
"""Test object search with no results."""
|
"""Test object search with no results."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [],
|
"results": [],
|
||||||
@@ -454,7 +465,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_client_error(self, mock_client):
|
async def test_search_objects_client_error(self, mock_client: Any) -> None:
|
||||||
"""Test object search with client error."""
|
"""Test object search with client error."""
|
||||||
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
||||||
|
|
||||||
@@ -467,7 +478,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_value_error(self, mock_client):
|
async def test_search_objects_value_error(self, mock_client: Any) -> None:
|
||||||
"""Test object search with value error."""
|
"""Test object search with value error."""
|
||||||
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
||||||
|
|
||||||
@@ -480,7 +491,7 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_json_formatting(self, mock_client):
|
async def test_search_objects_json_formatting(self, mock_client: Any) -> None:
|
||||||
"""Test that search results are properly formatted as JSON."""
|
"""Test that search results are properly formatted as JSON."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -506,7 +517,7 @@ class TestSearchObjects:
|
|||||||
assert parsed_result["total_count"] == 1
|
assert parsed_result["total_count"] == 1
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_with_page_num(self, mock_client):
|
async def test_search_objects_with_page_num(self, mock_client: Any) -> None:
|
||||||
"""Test object search with page number parameter."""
|
"""Test object search with page number parameter."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -530,7 +541,9 @@ class TestSearchObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_search_objects_with_all_pagination_params(self, mock_client):
|
async def test_search_objects_with_all_pagination_params(
|
||||||
|
self, mock_client: Any
|
||||||
|
) -> None:
|
||||||
"""Test object search with all pagination parameters."""
|
"""Test object search with all pagination parameters."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [
|
"results": [
|
||||||
@@ -558,7 +571,7 @@ class TestGetCordraDesign:
|
|||||||
"""Test the get_cordra_design resource handler."""
|
"""Test the get_cordra_design resource handler."""
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_design_success(self, mock_client):
|
async def test_get_design_success(self, mock_client: Any) -> None:
|
||||||
"""Test successful design object retrieval."""
|
"""Test successful design object retrieval."""
|
||||||
mock_design = DigitalObject(
|
mock_design = DigitalObject(
|
||||||
id="design",
|
id="design",
|
||||||
@@ -586,7 +599,7 @@ class TestGetCordraDesign:
|
|||||||
mock_client.get_design.assert_called_once()
|
mock_client.get_design.assert_called_once()
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_design_not_found(self, mock_client):
|
async def test_get_design_not_found(self, mock_client: Any) -> None:
|
||||||
"""Test design object not found exception."""
|
"""Test design object not found exception."""
|
||||||
mock_client.get_design = AsyncMock(
|
mock_client.get_design = AsyncMock(
|
||||||
side_effect=CordraNotFoundError("Design object not found")
|
side_effect=CordraNotFoundError("Design object not found")
|
||||||
@@ -599,7 +612,7 @@ class TestGetCordraDesign:
|
|||||||
mock_client.get_design.assert_called_once()
|
mock_client.get_design.assert_called_once()
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_design_authentication_error(self, mock_client):
|
async def test_get_design_authentication_error(self, mock_client: Any) -> None:
|
||||||
"""Test design object authentication error."""
|
"""Test design object authentication error."""
|
||||||
mock_client.get_design = AsyncMock(
|
mock_client.get_design = AsyncMock(
|
||||||
side_effect=CordraAuthenticationError("Authentication failed")
|
side_effect=CordraAuthenticationError("Authentication failed")
|
||||||
@@ -612,7 +625,7 @@ class TestGetCordraDesign:
|
|||||||
mock_client.get_design.assert_called_once()
|
mock_client.get_design.assert_called_once()
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_design_client_error(self, mock_client):
|
async def test_get_design_client_error(self, mock_client: Any) -> None:
|
||||||
"""Test design object general client error."""
|
"""Test design object general client error."""
|
||||||
mock_client.get_design = AsyncMock(
|
mock_client.get_design = AsyncMock(
|
||||||
side_effect=CordraClientError("Connection failed")
|
side_effect=CordraClientError("Connection failed")
|
||||||
@@ -626,7 +639,7 @@ class TestGetCordraDesign:
|
|||||||
mock_client.get_design.assert_called_once()
|
mock_client.get_design.assert_called_once()
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_get_design_json_formatting(self, mock_client):
|
async def test_get_design_json_formatting(self, mock_client: Any) -> None:
|
||||||
"""Test that the design object is properly formatted as JSON."""
|
"""Test that the design object is properly formatted as JSON."""
|
||||||
mock_design = DigitalObject(
|
mock_design = DigitalObject(
|
||||||
id="design",
|
id="design",
|
||||||
@@ -656,7 +669,7 @@ class TestCountObjects:
|
|||||||
"""Test the count_objects tool."""
|
"""Test the count_objects tool."""
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_success(self, mock_client):
|
async def test_count_objects_success(self, mock_client: Any) -> None:
|
||||||
"""Test successful object count."""
|
"""Test successful object count."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [{"id": "people/john-doe", "type": "Person"}],
|
"results": [{"id": "people/john-doe", "type": "Person"}],
|
||||||
@@ -677,7 +690,7 @@ class TestCountObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_with_type_filter(self, mock_client):
|
async def test_count_objects_with_type_filter(self, mock_client: Any) -> None:
|
||||||
"""Test object count with type filter."""
|
"""Test object count with type filter."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [{"id": "people/john-doe", "type": "Person"}],
|
"results": [{"id": "people/john-doe", "type": "Person"}],
|
||||||
@@ -698,7 +711,7 @@ class TestCountObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_zero_results(self, mock_client):
|
async def test_count_objects_zero_results(self, mock_client: Any) -> None:
|
||||||
"""Test object count with zero results."""
|
"""Test object count with zero results."""
|
||||||
mock_search_result = {
|
mock_search_result = {
|
||||||
"results": [],
|
"results": [],
|
||||||
@@ -718,7 +731,7 @@ class TestCountObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_client_error(self, mock_client):
|
async def test_count_objects_client_error(self, mock_client: Any) -> None:
|
||||||
"""Test object count with client error."""
|
"""Test object count with client error."""
|
||||||
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
mock_client.find = AsyncMock(side_effect=CordraClientError("Search failed"))
|
||||||
|
|
||||||
@@ -731,7 +744,7 @@ class TestCountObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_value_error(self, mock_client):
|
async def test_count_objects_value_error(self, mock_client: Any) -> None:
|
||||||
"""Test object count with value error."""
|
"""Test object count with value error."""
|
||||||
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
mock_client.find = AsyncMock(side_effect=ValueError("Invalid query"))
|
||||||
|
|
||||||
@@ -744,7 +757,7 @@ class TestCountObjects:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("cordra_mcp.server.cordra_client")
|
@patch("cordra_mcp.server.cordra_client")
|
||||||
async def test_count_objects_authentication_error(self, mock_client):
|
async def test_count_objects_authentication_error(self, mock_client: Any) -> None:
|
||||||
"""Test object count with authentication error."""
|
"""Test object count with authentication error."""
|
||||||
mock_client.find = AsyncMock(
|
mock_client.find = AsyncMock(
|
||||||
side_effect=CordraAuthenticationError("Authentication failed")
|
side_effect=CordraAuthenticationError("Authentication failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user