test: Update tests with async

This commit is contained in:
Chris Coutinho
2025-06-06 19:10:10 +02:00
parent 110df3d7b9
commit 5ee9435741
7 changed files with 116 additions and 113 deletions
+18 -18
View File
@@ -40,7 +40,7 @@ def test_image_data() -> tuple[bytes, str]:
return image_bytes, suggested_filename
def test_note_with_embedded_image(
async def test_note_with_embedded_image(
nc_client: NextcloudClient, temporary_note: dict, test_image_data: tuple
):
"""
@@ -62,7 +62,7 @@ def test_note_with_embedded_image(
logger.info(
f"Uploading image attachment '{attachment_filename}' to note {note_id} (category: '{note_category or ''}')..."
)
upload_response = nc_client.add_note_attachment(
upload_response = await nc_client.add_note_attachment(
note_id=note_id,
filename=attachment_filename,
content=image_content,
@@ -84,7 +84,7 @@ def test_note_with_embedded_image(
)
propfind_headers = {"Depth": "0", "OCS-APIRequest": "true"}
try:
propfind_resp = nc_client._client.request(
propfind_resp = await nc_client._client.request(
"PROPFIND", attachment_dir_path, headers=propfind_headers
)
status = propfind_resp.status_code
@@ -99,9 +99,9 @@ def test_note_with_embedded_image(
logger.error(
f"Attachment directory not found! PROPFIND failed with {e.response.status_code}"
)
assert False, (
f"Expected attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
)
assert (
False
), f"Expected attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
# 2. Update the note content to include the embedded image references
updated_content = f"""{note_data["content"]}
@@ -115,7 +115,7 @@ def test_note_with_embedded_image(
<img src=".attachments.{note_id}/{attachment_filename}" alt="Test Image HTML" width="150" />
"""
logger.info("Updating note content with image references...")
updated_note = nc_client.notes_update_note(
updated_note = await nc_client.notes_update_note(
note_id=note_id,
etag=note_etag, # Use etag from the created note
content=updated_content,
@@ -128,7 +128,7 @@ def test_note_with_embedded_image(
time.sleep(1)
# 3. Verify the updated note content
retrieved_note = nc_client.notes_get_note(note_id=note_id)
retrieved_note = await nc_client.notes_get_note(note_id=note_id)
assert f".attachments.{note_id}/{attachment_filename}" in retrieved_note["content"]
logger.info("Verified image reference exists in updated note content.")
@@ -137,7 +137,7 @@ def test_note_with_embedded_image(
f"Retrieving image attachment '{attachment_filename}' (category: '{note_category or ''}')..."
)
# Pass category to get_note_attachment
retrieved_img_content, mime_type = nc_client.get_note_attachment(
retrieved_img_content, mime_type = await nc_client.get_note_attachment(
note_id=note_id, filename=attachment_filename, category=note_category
)
assert retrieved_img_content == image_content
@@ -150,20 +150,20 @@ def test_note_with_embedded_image(
logger.info(
f"Manually deleting note ID: {note_id} to verify proper attachment cleanup"
)
nc_client.notes_delete_note(note_id=note_id)
await nc_client.notes_delete_note(note_id=note_id)
logger.info(f"Note ID: {note_id} deleted successfully.")
time.sleep(1)
# 6. Verify note is deleted
with pytest.raises(HTTPStatusError) as excinfo_note:
nc_client.notes_get_note(note_id=note_id)
await nc_client.notes_get_note(note_id=note_id)
assert excinfo_note.value.response.status_code == 404
logger.info(f"Verified note {note_id} deletion (404 received).")
# 7. Verify attachment directory is deleted via WebDAV PROPFIND
logger.info("Directly verifying attachment directory doesn't exist via PROPFIND")
try:
propfind_resp = nc_client._client.request(
propfind_resp = await nc_client._client.request(
"PROPFIND", attachment_dir_path, headers=propfind_headers
)
status = propfind_resp.status_code
@@ -171,13 +171,13 @@ def test_note_with_embedded_image(
logger.error(
f"Attachment directory still exists! PROPFIND returned {status}"
)
assert False, (
f"Expected attachment directory to be gone, but PROPFIND returned {status}!"
)
assert (
False
), f"Expected attachment directory to be gone, but PROPFIND returned {status}!"
except HTTPStatusError as e:
assert e.response.status_code == 404, (
f"Expected PROPFIND to fail with 404, got {e.response.status_code}"
)
assert (
e.response.status_code == 404
), f"Expected PROPFIND to fail with 404, got {e.response.status_code}"
logger.info(
"Verified attachment directory does not exist via PROPFIND (404 received)"
)