test: Update tests with async
This commit is contained in:
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
def test_attachments_add_and_get(
|
||||
async def test_attachments_add_and_get(
|
||||
nc_client: NextcloudClient, temporary_note_with_attachment: tuple
|
||||
):
|
||||
"""
|
||||
@@ -29,7 +29,7 @@ def test_attachments_add_and_get(
|
||||
f"Attempting to retrieve attachment '{attachment_filename}' added by fixture for note ID: {note_id}"
|
||||
)
|
||||
# Pass category to get_note_attachment
|
||||
retrieved_content, retrieved_mime = nc_client.get_note_attachment(
|
||||
retrieved_content, retrieved_mime = await nc_client.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=note_category
|
||||
)
|
||||
logger.info(
|
||||
@@ -41,7 +41,7 @@ def test_attachments_add_and_get(
|
||||
logger.info("Retrieved attachment content and mime type verified successfully.")
|
||||
|
||||
|
||||
def test_attachments_add_to_note_with_category(
|
||||
async def test_attachments_add_to_note_with_category(
|
||||
nc_client: NextcloudClient, temporary_note: dict
|
||||
):
|
||||
"""
|
||||
@@ -67,7 +67,7 @@ def test_attachments_add_to_note_with_category(
|
||||
f"Attempting to add attachment '{attachment_filename}' to note ID: {note_id}"
|
||||
)
|
||||
# Pass category to add_note_attachment
|
||||
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,
|
||||
@@ -86,7 +86,7 @@ def test_attachments_add_to_note_with_category(
|
||||
f"Attempting to retrieve attachment '{attachment_filename}' from note ID: {note_id}"
|
||||
)
|
||||
# Pass category to get_note_attachment
|
||||
retrieved_content, retrieved_mime = nc_client.get_note_attachment(
|
||||
retrieved_content, retrieved_mime = await nc_client.get_note_attachment(
|
||||
note_id=note_id,
|
||||
filename=attachment_filename,
|
||||
category=note_category, # Pass the note's category
|
||||
@@ -103,7 +103,7 @@ def test_attachments_add_to_note_with_category(
|
||||
# Cleanup is handled by the temporary_note fixture
|
||||
|
||||
|
||||
def test_attachments_cleanup_on_note_delete(
|
||||
async def test_attachments_cleanup_on_note_delete(
|
||||
nc_client: NextcloudClient, temporary_note_with_attachment: tuple
|
||||
):
|
||||
"""
|
||||
@@ -127,13 +127,13 @@ def test_attachments_cleanup_on_note_delete(
|
||||
|
||||
# Manually delete the note
|
||||
logger.info(f"Manually deleting note ID: {note_id} within the test.")
|
||||
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)
|
||||
|
||||
# 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).")
|
||||
|
||||
@@ -145,7 +145,7 @@ def test_attachments_cleanup_on_note_delete(
|
||||
# Pass category to get_note_attachment - although it should fail anyway
|
||||
# because the note (and thus details) are gone.
|
||||
# The client method will raise 404 from the initial notes_get_note call.
|
||||
nc_client.get_note_attachment(
|
||||
await nc_client.get_note_attachment(
|
||||
note_id=note_id,
|
||||
filename=attachment_filename,
|
||||
category=note_category, # Pass category, though note fetch should fail first
|
||||
@@ -165,7 +165,7 @@ def test_attachments_cleanup_on_note_delete(
|
||||
)
|
||||
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
|
||||
@@ -173,13 +173,13 @@ def test_attachments_cleanup_on_note_delete(
|
||||
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)"
|
||||
)
|
||||
@@ -188,7 +188,7 @@ def test_attachments_cleanup_on_note_delete(
|
||||
# but it will find the note already deleted (404) and handle it gracefully.
|
||||
|
||||
|
||||
def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
"""
|
||||
Tests attachment handling when a note's category is changed.
|
||||
Verifies attachment retrieval works before and after category change,
|
||||
@@ -205,7 +205,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
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"]
|
||||
@@ -217,7 +217,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
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,
|
||||
@@ -232,7 +232,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
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
|
||||
@@ -243,9 +243,9 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
f"Updating note {note_id} category from '{initial_category}' to '{new_category}'"
|
||||
)
|
||||
# Need to fetch the latest etag after attachment add (WebDAV ops don't update note etag)
|
||||
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,
|
||||
@@ -261,7 +261,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
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
|
||||
@@ -275,7 +275,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
)
|
||||
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
|
||||
@@ -283,13 +283,13 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
logger.error(
|
||||
f"Old attachment directory still exists! PROPFIND returned {status}"
|
||||
)
|
||||
assert False, (
|
||||
f"Expected old directory to be gone, but PROPFIND returned {status} - directory still exists!"
|
||||
)
|
||||
assert (
|
||||
False
|
||||
), f"Expected old directory to be gone, but PROPFIND returned {status} - directory still exists!"
|
||||
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 attachment directory does not exist via PROPFIND (404 received)"
|
||||
)
|
||||
@@ -300,7 +300,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
f"{webdav_base}/Notes/{new_category}/.attachments.{note_id}"
|
||||
)
|
||||
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
|
||||
@@ -315,9 +315,9 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
logger.error(
|
||||
f"New attachment directory not found! PROPFIND failed with {e.response.status_code}"
|
||||
)
|
||||
assert False, (
|
||||
f"Expected new attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
|
||||
)
|
||||
assert (
|
||||
False
|
||||
), f"Expected new attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
|
||||
|
||||
finally:
|
||||
# 6. Cleanup: Delete the note (client should use the *final* category for cleanup path)
|
||||
@@ -326,18 +326,18 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
f"Cleaning up note ID: {note_id} (last known category: '{new_category}')"
|
||||
)
|
||||
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)
|
||||
# Verify note deletion
|
||||
with pytest.raises(HTTPStatusError) as excinfo_note_del:
|
||||
nc_client.notes_get_note(note_id=note_id)
|
||||
await nc_client.notes_get_note(note_id=note_id)
|
||||
assert excinfo_note_del.value.response.status_code == 404
|
||||
logger.info("Verified note deleted (404).")
|
||||
# Verify attachment deletion (should fail with 404 on the initial note fetch)
|
||||
with pytest.raises(HTTPStatusError) as excinfo_attach_del:
|
||||
# Pass the *last known* category, although the note fetch should fail first
|
||||
nc_client.get_note_attachment(
|
||||
await nc_client.get_note_attachment(
|
||||
note_id=note_id,
|
||||
filename=attachment_filename,
|
||||
category=new_category,
|
||||
@@ -359,7 +359,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
)
|
||||
propfind_headers = {"Depth": "0", "OCS-APIRequest": "true"}
|
||||
try:
|
||||
resp = nc_client._client.request(
|
||||
resp = await nc_client._client.request(
|
||||
"PROPFIND", new_attachment_dir_path, headers=propfind_headers
|
||||
)
|
||||
if resp.status_code in [
|
||||
@@ -368,9 +368,9 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
]: # Successful PROPFIND means directory exists
|
||||
assert False, "New category attachment directory still exists!"
|
||||
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"
|
||||
)
|
||||
@@ -380,7 +380,7 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
f"{webdav_base}/Notes/{initial_category}/.attachments.{note_id}"
|
||||
)
|
||||
try:
|
||||
resp = nc_client._client.request(
|
||||
resp = await nc_client._client.request(
|
||||
"PROPFIND", old_attachment_dir_path, headers=propfind_headers
|
||||
)
|
||||
if resp.status_code in [
|
||||
@@ -389,9 +389,9 @@ def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
]: # Successful PROPFIND means directory exists
|
||||
assert False, "Old category attachment directory still exists!"
|
||||
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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user