wip: tests

This commit is contained in:
Chris Coutinho
2025-05-06 14:45:41 +02:00
parent 04e4a8e0a8
commit e1de793af8
6 changed files with 113 additions and 125 deletions
+14 -11
View File
@@ -1,10 +1,13 @@
import pytest
import os
import time
import logging
import uuid
from httpx import HTTPStatusError
from nextcloud_mcp_server.client import NextcloudClient
logger = logging.getLogger(__name__)
# Tests assume NEXTCLOUD_HOST, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD env vars are set
@pytest.fixture(scope="module")
@@ -34,7 +37,7 @@ def test_attachment_remains_after_note_deletion(nc_client: NextcloudClient):
try:
# Create the note
print(f"Creating note: {note_title}")
logger.info(f"Creating note: {note_title}")
created_note = nc_client.notes_create_note(
title=note_title,
content=note_content,
@@ -42,7 +45,7 @@ def test_attachment_remains_after_note_deletion(nc_client: NextcloudClient):
)
assert created_note and "id" in created_note
note_id = created_note["id"]
print(f"Note created with ID: {note_id}")
logger.info(f"Note created with ID: {note_id}")
time.sleep(1)
# Create a simple text attachment
@@ -50,7 +53,7 @@ def test_attachment_remains_after_note_deletion(nc_client: NextcloudClient):
attachment_content = f"This is a test attachment for note {note_id}".encode('utf-8')
# Attach the file to the note
print(f"Attaching text file to note {note_id}...")
logger.info(f"Attaching text file to note {note_id}...")
upload_response = nc_client.add_note_attachment(
note_id=note_id,
filename=attachment_filename,
@@ -59,7 +62,7 @@ def test_attachment_remains_after_note_deletion(nc_client: NextcloudClient):
)
assert upload_response["status_code"] in [201, 204]
print(f"Attachment added successfully (Status: {upload_response['status_code']}).")
logger.info(f"Attachment added successfully (Status: {upload_response['status_code']}).")
time.sleep(1)
# Verify the attachment exists
@@ -69,30 +72,30 @@ def test_attachment_remains_after_note_deletion(nc_client: NextcloudClient):
)
assert content == attachment_content, "Attachment content mismatch"
print("Attachment verified")
logger.info("Attachment verified")
# Now delete the note
print(f"Deleting note ID: {note_id}")
logger.info(f"Deleting note ID: {note_id}")
nc_client.notes_delete_note(note_id=note_id)
print(f"Note deleted successfully.")
logger.info(f"Note deleted successfully.")
time.sleep(1)
# Verify the note is deleted
with pytest.raises(HTTPStatusError) as excinfo:
nc_client.notes_get_note(note_id=note_id)
assert excinfo.value.response.status_code == 404
print(f"Verified note deletion (404 Not Found)")
logger.info(f"Verified note deletion (404 Not Found)")
# Now check if the attachment still exists (expected behavior: it should)
print(f"Checking if attachment still exists after note deletion...")
logger.info(f"Checking if attachment still exists after note deletion...")
orphaned_content, orphaned_mime = nc_client.get_note_attachment(
note_id=note_id,
filename=attachment_filename
)
# If we get here without an exception, the attachment still exists
print("CONFIRMED: Attachment still exists after note deletion")
print("This is the expected behavior of the Nextcloud Notes app")
logger.info("CONFIRMED: Attachment still exists after note deletion")
logger.info("This is the expected behavior of the Nextcloud Notes app")
assert orphaned_content == attachment_content, "Orphaned attachment content mismatch"
finally: