fix: address PR review feedback for Collectives support
- Validate OCS envelope status before unwrapping data (raise OCSError on statuscode >= 400) - Fix test data: filePath should be "" for root-level pages, not filename - Catch specific exceptions (HTTPStatusError, OSError) instead of bare Exception in WebDAV content fetch, include error in log message - Return updated resource data from update_collective, move_page, and set_page_emoji instead of discarding API responses - Fix create_page docstring to mention collectivePath/filePath/fileName - Remove unused additional_headers parameter from _get_ocs_headers - Add unit test for OCS error status validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
32f5a0fe52
commit
e5ad625a66
@@ -3,7 +3,7 @@
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from nextcloud_mcp_server.client.collectives import CollectivesClient
|
||||
from nextcloud_mcp_server.client.collectives import CollectivesClient, OCSError
|
||||
from tests.client.conftest import create_mock_response
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
@@ -46,7 +46,7 @@ def _sample_page(
|
||||
"title": title,
|
||||
"emoji": None,
|
||||
"fileName": f"{title}.md",
|
||||
"filePath": f"{title}.md",
|
||||
"filePath": "",
|
||||
"collectivePath": collective_path,
|
||||
"parentId": parent_id,
|
||||
"timestamp": 1700000000,
|
||||
@@ -327,6 +327,28 @@ async def test_restore_page(mocker):
|
||||
# --- Error Handling ---
|
||||
|
||||
|
||||
async def test_ocs_error_status_raises(mocker):
|
||||
"""Test that OCS envelope with error statuscode raises OCSError."""
|
||||
mock_response = create_mock_response(
|
||||
status_code=200,
|
||||
json_data={
|
||||
"ocs": {
|
||||
"meta": {
|
||||
"status": "failure",
|
||||
"statuscode": 403,
|
||||
"message": "Not permitted",
|
||||
},
|
||||
"data": {},
|
||||
}
|
||||
},
|
||||
)
|
||||
mocker.patch.object(CollectivesClient, "_make_request", return_value=mock_response)
|
||||
|
||||
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
|
||||
with pytest.raises(OCSError, match="Not permitted"):
|
||||
await client.get_collectives()
|
||||
|
||||
|
||||
async def test_get_collectives_403(mocker):
|
||||
"""Test 403 response raises HTTPStatusError."""
|
||||
mock_response = create_mock_response(
|
||||
|
||||
Reference in New Issue
Block a user