mirror of
https://github.com/dnlbauer/cordra-mcp.git
synced 2026-09-10 21:55:30 +00:00
fix: cordapy response parsing
This commit is contained in:
@@ -54,9 +54,8 @@ class CordraClient:
|
|||||||
CordraClientError: For other API errors
|
CordraClientError: For other API errors
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Use CordraPy to read the object
|
cordra_obj: dict[str, Any] = cordra.CordraObject.read(
|
||||||
cordra_obj = cordra.CordraObject.read(
|
host=self.config.cordra_url, #type: ignore
|
||||||
host=self.config.cordra_url, # type: ignore
|
|
||||||
obj_id=object_id,
|
obj_id=object_id,
|
||||||
username=self.config.username,
|
username=self.config.username,
|
||||||
password=self.config.password,
|
password=self.config.password,
|
||||||
@@ -66,11 +65,11 @@ class CordraClient:
|
|||||||
|
|
||||||
return DigitalObject(
|
return DigitalObject(
|
||||||
id=object_id,
|
id=object_id,
|
||||||
type=getattr(cordra_obj, 'type', ''),
|
type=cordra_obj['type'],
|
||||||
content=getattr(cordra_obj, 'content', {}),
|
content=cordra_obj['content'],
|
||||||
metadata=getattr(cordra_obj, 'metadata', None),
|
metadata=cordra_obj.get('metadata'),
|
||||||
acl=getattr(cordra_obj, 'acl', None),
|
acl=cordra_obj.get('acl'),
|
||||||
payloads=getattr(cordra_obj, 'payloads', None),
|
payloads=cordra_obj.get('payloads'),
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Unit tests for the Cordra client."""
|
"""Unit tests for the Cordra client."""
|
||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -32,27 +32,27 @@ def client(config):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_cordra_object():
|
def mock_cordra_object():
|
||||||
"""Create a mock CordraObject."""
|
"""Create a mock CordraObject response (dictionary)."""
|
||||||
mock_obj = Mock()
|
return {
|
||||||
mock_obj.type = "TestType"
|
"type": "TestType",
|
||||||
mock_obj.content = {"title": "Test Object", "description": "A test object"}
|
"content": {"title": "Test Object", "description": "A test object"},
|
||||||
mock_obj.metadata = {"created": "2023-01-01", "modified": "2023-01-02"}
|
"metadata": {"created": "2023-01-01", "modified": "2023-01-02"},
|
||||||
mock_obj.acl = {"read": ["public"], "write": ["admin"]}
|
"acl": {"read": ["public"], "write": ["admin"]},
|
||||||
mock_obj.payloads = [
|
"payloads": [
|
||||||
{
|
{
|
||||||
"name": "file1.txt",
|
"name": "file1.txt",
|
||||||
"filename": "file1.txt",
|
"filename": "file1.txt",
|
||||||
"size": 1024,
|
"size": 1024,
|
||||||
"mediaType": "text/plain"
|
"mediaType": "text/plain"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "file2.pdf",
|
"name": "file2.pdf",
|
||||||
"filename": "file2.pdf",
|
"filename": "file2.pdf",
|
||||||
"size": 2048,
|
"size": 2048,
|
||||||
"mediaType": "application/pdf"
|
"mediaType": "application/pdf"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
return mock_obj
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestDigitalObject:
|
class TestDigitalObject:
|
||||||
|
|||||||
Reference in New Issue
Block a user