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
+38 -38
View File
@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
pytestmark = pytest.mark.integration
def test_category_change_cleans_up_old_attachments_directory(
async def test_category_change_cleans_up_old_attachments_directory(
nc_client: NextcloudClient,
):
"""
@@ -29,7 +29,7 @@ def test_category_change_cleans_up_old_attachments_directory(
try:
# 1. Create note with initial category
logger.info(f"Creating note '{note_title}' in category '{initial_category}'")
created_note = nc_client.notes_create_note(
created_note = await nc_client.notes_create_note(
title=note_title, content="Initial content", category=initial_category
)
note_id = created_note["id"]
@@ -41,7 +41,7 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.info(
f"Adding attachment '{attachment_filename}' to note {note_id} (in {initial_category})"
)
upload_response = nc_client.add_note_attachment(
upload_response = await nc_client.add_note_attachment(
note_id=note_id,
filename=attachment_filename,
content=attachment_content,
@@ -56,7 +56,7 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.info(
f"Verifying attachment retrieval from initial category '{initial_category}'"
)
retrieved_content1, _ = nc_client.get_note_attachment(
retrieved_content1, _ = await nc_client.get_note_attachment(
note_id=note_id, filename=attachment_filename, category=initial_category
)
assert retrieved_content1 == attachment_content
@@ -72,9 +72,9 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.info(
f"Updating note {note_id} category from '{initial_category}' to '{new_category}'"
)
current_note_data = nc_client.notes_get_note(note_id=note_id)
current_note_data = await nc_client.notes_get_note(note_id=note_id)
current_etag = current_note_data["etag"]
updated_note = nc_client.notes_update_note(
updated_note = await nc_client.notes_update_note(
note_id=note_id,
etag=current_etag,
category=new_category,
@@ -90,7 +90,7 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.info(
f"Verifying attachment retrieval from new category '{new_category}'"
)
retrieved_content2, _ = nc_client.get_note_attachment(
retrieved_content2, _ = await nc_client.get_note_attachment(
note_id=note_id, filename=attachment_filename, category=new_category
)
assert retrieved_content2 == attachment_content
@@ -101,24 +101,24 @@ def test_category_change_cleans_up_old_attachments_directory(
f"Trying to retrieve attachment from old category '{initial_category}' - should fail"
)
try:
nc_client.get_note_attachment(
await nc_client.get_note_attachment(
note_id=note_id, filename=attachment_filename, category=initial_category
)
# If we get here, it means the old directory still exists (a problem)
logger.error(
"ISSUE DETECTED: Was able to retrieve attachment from old category path!"
)
assert False, (
"Old category attachment directory still exists and accessible!"
)
assert (
False
), "Old category attachment directory still exists and accessible!"
except HTTPStatusError as e:
# This is the expected outcome - old directory should be gone
logger.info(
f"Correctly got error accessing old category path: {e.response.status_code}"
)
assert e.response.status_code == 404, (
f"Expected 404, got {e.response.status_code}"
)
assert (
e.response.status_code == 404
), f"Expected 404, got {e.response.status_code}"
logger.info(
"Verified old category attachment directory is not accessible (good!)"
)
@@ -133,7 +133,7 @@ def test_category_change_cleans_up_old_attachments_directory(
)
propfind_headers = {"Depth": "0", "OCS-APIRequest": "true"}
try:
propfind_resp = nc_client._client.request(
propfind_resp = await nc_client._client.request(
"PROPFIND", old_attachment_dir_path, headers=propfind_headers
)
status = propfind_resp.status_code
@@ -144,18 +144,18 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.error(
f"Old attachment directory still exists! PROPFIND returned {status}"
)
assert False, (
f"Expected old attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
)
assert (
False
), f"Expected old attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
# If we got another status code (like 404), it's also good - the directory doesn't exist
logger.info(
f"Verified old attachment directory does not exist (PROPFIND returned {status})"
)
except HTTPStatusError as e:
# 404 is expected - directory should not exist
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 old attachment directory does not exist via PROPFIND (404 received)"
)
@@ -165,14 +165,14 @@ def test_category_change_cleans_up_old_attachments_directory(
if note_id:
logger.info(f"Cleaning up note ID: {note_id}")
try:
nc_client.notes_delete_note(note_id=note_id)
await nc_client.notes_delete_note(note_id=note_id)
logger.info(f"Note {note_id} deleted.")
time.sleep(1)
# 9. Verify both old and new attachment paths are gone
logger.info("Verifying all attachment paths are gone")
with pytest.raises(HTTPStatusError) as excinfo_new:
nc_client.get_note_attachment(
await nc_client.get_note_attachment(
note_id=note_id,
filename=attachment_filename,
category=new_category,
@@ -180,7 +180,7 @@ def test_category_change_cleans_up_old_attachments_directory(
assert excinfo_new.value.response.status_code == 404
with pytest.raises(HTTPStatusError) as excinfo_old:
nc_client.get_note_attachment(
await nc_client.get_note_attachment(
note_id=note_id,
filename=attachment_filename,
category=initial_category,
@@ -199,7 +199,7 @@ def test_category_change_cleans_up_old_attachments_directory(
)
propfind_headers = {"Depth": "0", "OCS-APIRequest": "true"}
try:
propfind_resp = nc_client._client.request(
propfind_resp = await nc_client._client.request(
"PROPFIND", new_attachment_dir_path, headers=propfind_headers
)
status = propfind_resp.status_code
@@ -210,17 +210,17 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.error(
f"New category attachment directory still exists! PROPFIND returned {status}"
)
assert False, (
f"Expected new category attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
)
assert (
False
), f"Expected new category attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
# If we got another status code (like 404), it's also good - the directory doesn't exist
logger.info(
f"Verified new category attachment directory does not exist (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 new category attachment directory is gone via PROPFIND"
)
@@ -230,7 +230,7 @@ def test_category_change_cleans_up_old_attachments_directory(
f"{webdav_base}/Notes/{initial_category}/.attachments.{note_id}"
)
try:
propfind_resp = nc_client._client.request(
propfind_resp = await nc_client._client.request(
"PROPFIND", old_attachment_dir_path, headers=propfind_headers
)
status = propfind_resp.status_code
@@ -241,17 +241,17 @@ def test_category_change_cleans_up_old_attachments_directory(
logger.error(
f"Old category attachment directory still exists! PROPFIND returned {status}"
)
assert False, (
f"Expected old category attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
)
assert (
False
), f"Expected old category attachment directory to be gone, but it still exists (PROPFIND returned {status})!"
# If we got another status code (like 404), it's also good - the directory doesn't exist
logger.info(
f"Verified old category attachment directory does not exist (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 old category attachment directory is gone via PROPFIND"
)