mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-11 06:05:29 +00:00
feat: add schema listing functionality
- Add find method to CordraClient for querying objects - Implement cordra://schemas resource for listing available type schemas - Add comprehensive unit tests for both client find method and server schema listing - Handle CordraPy response format with results array extraction - Support schema name extraction from returned objects
This commit is contained in:
@@ -156,6 +156,66 @@ class TestCordraClient:
|
||||
|
||||
assert "Failed to retrieve object test/123" in str(exc_info.value)
|
||||
|
||||
@patch('mcp_cordra.client.cordra.CordraObject.find')
|
||||
async def test_find_success(self, mock_find, client):
|
||||
"""Test successful find operation."""
|
||||
mock_response = {
|
||||
"results": [
|
||||
{"name": "User", "identifier": "test/user-schema"},
|
||||
{"name": "Project", "identifier": "test/project-schema"},
|
||||
{"name": "Document", "identifier": "test/doc-schema"}
|
||||
],
|
||||
"size": 3
|
||||
}
|
||||
mock_find.return_value = mock_response
|
||||
|
||||
result = await client.find("type:Schema")
|
||||
|
||||
assert len(result) == 3
|
||||
assert result[0]["name"] == "User"
|
||||
assert result[1]["name"] == "Project"
|
||||
assert result[2]["name"] == "Document"
|
||||
|
||||
mock_find.assert_called_once_with(
|
||||
client.config.cordra_url,
|
||||
"type:Schema"
|
||||
)
|
||||
|
||||
@patch('mcp_cordra.client.cordra.CordraObject.find')
|
||||
async def test_find_empty_results(self, mock_find, client):
|
||||
"""Test find with empty results."""
|
||||
mock_response = {"results": [], "size": 0}
|
||||
mock_find.return_value = mock_response
|
||||
|
||||
result = await client.find("type:NonExistent")
|
||||
|
||||
assert result == []
|
||||
mock_find.assert_called_once_with(
|
||||
client.config.cordra_url,
|
||||
"type:NonExistent"
|
||||
)
|
||||
|
||||
@patch('mcp_cordra.client.cordra.CordraObject.find')
|
||||
async def test_find_no_results_key(self, mock_find, client):
|
||||
"""Test find with response missing results key."""
|
||||
mock_response = {"size": 0} # No results key
|
||||
mock_find.return_value = mock_response
|
||||
|
||||
result = await client.find("type:Schema")
|
||||
|
||||
assert result == []
|
||||
|
||||
@patch('mcp_cordra.client.cordra.CordraObject.find')
|
||||
async def test_find_error(self, mock_find, client):
|
||||
"""Test find error handling."""
|
||||
mock_find.side_effect = Exception("Search failed")
|
||||
|
||||
with pytest.raises(CordraClientError) as exc_info:
|
||||
await client.find("invalid:query")
|
||||
|
||||
assert "Failed to search with query 'invalid:query'" in str(exc_info.value)
|
||||
assert "Search failed" in str(exc_info.value)
|
||||
|
||||
|
||||
class TestCordraConfig:
|
||||
"""Test the CordraConfig class."""
|
||||
|
||||
Reference in New Issue
Block a user