refactor: convert f-string logging to lazy %-style format (G004)
Sweep all 1676 G004 violations across 112 files, converting
`logger.<level>(f"…{x}…")` to `logger.<level>("…%s…", x)`.
Why: ruff rule G004 was added to pyproject.toml to enforce lazy
%-style logging — defers formatting until the log level is enabled
and lets structured log tooling match the unformatted template.
Conversion preserves rendered output byte-for-byte:
- `{x}` → `%s` + `x`
- `{x!r}` / `{x!s}` / `{x!a}` → `%r` / `%s` / `%a`
- Format specs (`{x:.2f}`, `{x:>10}`) → `%s` + `format(x, 'spec')`
(printf-style specs aren't 1:1 with Python format specs, so we
delegate to `format()` to keep identical output)
- Literal `%` → `%%`
- Concatenated f-strings (`f"a {x} " "b"`) flattened
- Trailing kwargs (`exc_info=True`) preserved
Verified:
- `uv run ruff check --select G004` → 0 violations
- `uv run ty check -- nextcloud_mcp_server` → passes
- `uv run pytest tests/unit/` → 1010 passed
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a4e6125d28
commit
665cb9b1eb
@@ -44,29 +44,29 @@ async def temporary_event(nc_client: NextcloudClient, temporary_calendar: str):
|
||||
}
|
||||
|
||||
try:
|
||||
logger.info(f"Creating temporary event in calendar: {calendar_name}")
|
||||
logger.info("Creating temporary event in calendar: %s", calendar_name)
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result.get("uid")
|
||||
|
||||
if not event_uid:
|
||||
pytest.fail("Failed to create temporary event")
|
||||
|
||||
logger.info(f"Created temporary event with UID: {event_uid}")
|
||||
logger.info("Created temporary event with UID: %s", event_uid)
|
||||
yield {"uid": event_uid, "calendar_name": calendar_name, "data": event_data}
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
if event_uid:
|
||||
try:
|
||||
logger.info(f"Cleaning up temporary event: {event_uid}")
|
||||
logger.info("Cleaning up temporary event: %s", event_uid)
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
logger.info(f"Successfully deleted temporary event: {event_uid}")
|
||||
logger.info("Successfully deleted temporary event: %s", event_uid)
|
||||
except HTTPStatusError as e:
|
||||
if e.response.status_code != 404:
|
||||
logger.error(f"Error deleting temporary event {event_uid}: {e}")
|
||||
logger.error("Error deleting temporary event %s: %s", event_uid, e)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Unexpected error deleting temporary event {event_uid}: {e}"
|
||||
"Unexpected error deleting temporary event %s: %s", event_uid, e
|
||||
)
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ async def test_list_calendars(nc_client: NextcloudClient):
|
||||
if not calendars:
|
||||
pytest.skip("No calendars available - Calendar app may not be enabled")
|
||||
|
||||
logger.info(f"Found {len(calendars)} calendars")
|
||||
logger.info("Found %s calendars", len(calendars))
|
||||
|
||||
# Check structure of calendars
|
||||
for calendar in calendars:
|
||||
@@ -90,7 +90,7 @@ async def test_list_calendars(nc_client: NextcloudClient):
|
||||
assert "description" in calendar
|
||||
assert "color" in calendar
|
||||
|
||||
logger.info(f"Calendar: {calendar['name']} - {calendar['display_name']}")
|
||||
logger.info("Calendar: %s - %s", calendar["name"], calendar["display_name"])
|
||||
|
||||
|
||||
async def test_create_and_delete_event(
|
||||
@@ -118,7 +118,7 @@ async def test_create_and_delete_event(
|
||||
assert result["status_code"] in [200, 201, 204]
|
||||
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created event with UID: {event_uid}")
|
||||
logger.info("Created event with UID: %s", event_uid)
|
||||
|
||||
# Verify event was created by retrieving it
|
||||
retrieved_event, etag = await nc_client.calendar.get_event(
|
||||
@@ -132,10 +132,10 @@ async def test_create_and_delete_event(
|
||||
delete_result = await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
assert delete_result["status_code"] in [200, 204, 404]
|
||||
|
||||
logger.info(f"Successfully deleted event: {event_uid}")
|
||||
logger.info("Successfully deleted event: %s", event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Test failed: {e}")
|
||||
logger.error("Test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ async def test_create_all_day_event(
|
||||
try:
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created all-day event with UID: {event_uid}")
|
||||
logger.info("Created all-day event with UID: %s", event_uid)
|
||||
|
||||
# Verify event
|
||||
retrieved_event, _ = await nc_client.calendar.get_event(
|
||||
@@ -170,7 +170,7 @@ async def test_create_all_day_event(
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"All-day event test failed: {e}")
|
||||
logger.error("All-day event test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ async def test_create_recurring_event(
|
||||
try:
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created recurring event with UID: {event_uid}")
|
||||
logger.info("Created recurring event with UID: %s", event_uid)
|
||||
|
||||
# Verify event
|
||||
retrieved_event, _ = await nc_client.calendar.get_event(
|
||||
@@ -207,7 +207,7 @@ async def test_create_recurring_event(
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Recurring event test failed: {e}")
|
||||
logger.error("Recurring event test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ async def test_list_events_in_range(nc_client: NextcloudClient, temporary_event:
|
||||
)
|
||||
|
||||
assert isinstance(events, list)
|
||||
logger.info(f"Found {len(events)} events in date range")
|
||||
logger.info("Found %s events in date range", len(events))
|
||||
|
||||
# Our temporary event should be in the list
|
||||
event_uids = [event.get("uid") for event in events]
|
||||
@@ -266,10 +266,10 @@ async def test_update_event(nc_client: NextcloudClient, temporary_event: dict):
|
||||
assert updated_event["location"] == "Updated Location"
|
||||
assert updated_event["priority"] == 1
|
||||
|
||||
logger.info(f"Successfully updated event: {event_uid}")
|
||||
logger.info("Successfully updated event: %s", event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Event update test failed: {e}")
|
||||
logger.error("Event update test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ async def test_update_event_extended_fields(
|
||||
try:
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created base event for extended fields test: {event_uid}")
|
||||
logger.info("Created base event for extended fields test: %s", event_uid)
|
||||
|
||||
# --- Phase 1: Set all four extended fields ---
|
||||
updated_data = {
|
||||
@@ -343,7 +343,7 @@ async def test_update_event_extended_fields(
|
||||
logger.info("Phase 2 passed: all extended fields cleared correctly")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Extended fields update test failed: {e}")
|
||||
logger.error("Extended fields update test failed: %s", e)
|
||||
raise
|
||||
finally:
|
||||
if event_uid:
|
||||
@@ -374,7 +374,7 @@ async def test_create_event_with_attendees(
|
||||
try:
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created event with attendees, UID: {event_uid}")
|
||||
logger.info("Created event with attendees, UID: %s", event_uid)
|
||||
|
||||
# Verify event
|
||||
retrieved_event, _ = await nc_client.calendar.get_event(
|
||||
@@ -388,7 +388,7 @@ async def test_create_event_with_attendees(
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Event with attendees test failed: {e}")
|
||||
logger.error("Event with attendees test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ async def test_get_nonexistent_event(
|
||||
with pytest.raises(Exception, match="not found"):
|
||||
await nc_client.calendar.get_event(calendar_name, fake_uid)
|
||||
|
||||
logger.info(f"Correctly raised exception for nonexistent event: {fake_uid}")
|
||||
logger.info("Correctly raised exception for nonexistent event: %s", fake_uid)
|
||||
|
||||
|
||||
async def test_delete_nonexistent_event(
|
||||
@@ -415,7 +415,7 @@ async def test_delete_nonexistent_event(
|
||||
|
||||
result = await nc_client.calendar.delete_event(calendar_name, fake_uid)
|
||||
assert result["status_code"] == 404
|
||||
logger.info(f"Correctly got 404 for deleting nonexistent event: {fake_uid}")
|
||||
logger.info("Correctly got 404 for deleting nonexistent event: %s", fake_uid)
|
||||
|
||||
|
||||
async def test_event_with_url_and_categories(
|
||||
@@ -439,7 +439,7 @@ async def test_event_with_url_and_categories(
|
||||
try:
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created event with metadata, UID: {event_uid}")
|
||||
logger.info("Created event with metadata, UID: %s", event_uid)
|
||||
|
||||
# Verify event
|
||||
retrieved_event, _ = await nc_client.calendar.get_event(
|
||||
@@ -456,7 +456,7 @@ async def test_event_with_url_and_categories(
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Event with metadata test failed: {e}")
|
||||
logger.error("Event with metadata test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -485,7 +485,7 @@ async def test_list_events_date_range_filtering(
|
||||
calendar_name, past_event_data
|
||||
)
|
||||
past_uid = result_past["uid"]
|
||||
logger.info(f"Created past event: {past_uid}")
|
||||
logger.info("Created past event: %s", past_uid)
|
||||
|
||||
# Create Event B: 1 day in the future
|
||||
future_date = datetime.now() + timedelta(days=1)
|
||||
@@ -499,7 +499,7 @@ async def test_list_events_date_range_filtering(
|
||||
calendar_name, future_event_data
|
||||
)
|
||||
future_uid = result_future["uid"]
|
||||
logger.info(f"Created future event: {future_uid}")
|
||||
logger.info("Created future event: %s", future_uid)
|
||||
|
||||
# Query with date range: today → 7 days ahead
|
||||
now = datetime.now()
|
||||
@@ -526,8 +526,8 @@ async def test_list_events_date_range_filtering(
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Date range filtering works: {len(events)} events returned, "
|
||||
f"past event correctly excluded"
|
||||
"Date range filtering works: %s events returned, past event correctly excluded",
|
||||
len(events),
|
||||
)
|
||||
|
||||
finally:
|
||||
@@ -537,7 +537,7 @@ async def test_list_events_date_range_filtering(
|
||||
try:
|
||||
await nc_client.calendar.delete_event(calendar_name, uid)
|
||||
except Exception as e:
|
||||
logger.warning(f"Cleanup failed for event {uid}: {e}")
|
||||
logger.warning("Cleanup failed for event %s: %s", uid, e)
|
||||
|
||||
|
||||
async def test_recurring_event_date_range_expansion(
|
||||
@@ -569,7 +569,7 @@ async def test_recurring_event_date_range_expansion(
|
||||
}
|
||||
result = await nc_client.calendar.create_event(calendar_name, event_data)
|
||||
event_uid = result["uid"]
|
||||
logger.info(f"Created daily recurring event: {event_uid}")
|
||||
logger.info("Created daily recurring event: %s", event_uid)
|
||||
|
||||
# Query with date range: today → 3 days ahead
|
||||
query_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
@@ -619,8 +619,8 @@ async def test_recurring_event_date_range_expansion(
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Recurring event expansion works: {len(our_events)} occurrences "
|
||||
f"returned with unique start dates"
|
||||
"Recurring event expansion works: %s occurrences returned with unique start dates",
|
||||
len(our_events),
|
||||
)
|
||||
|
||||
finally:
|
||||
@@ -628,7 +628,9 @@ async def test_recurring_event_date_range_expansion(
|
||||
try:
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
except Exception as e:
|
||||
logger.warning(f"Cleanup failed for recurring event {event_uid}: {e}")
|
||||
logger.warning(
|
||||
"Cleanup failed for recurring event %s: %s", event_uid, e
|
||||
)
|
||||
|
||||
|
||||
async def test_calendar_operations_error_handling(
|
||||
|
||||
@@ -68,7 +68,7 @@ END:VCALENDAR"""
|
||||
event.data = custom_ical
|
||||
await event.save()
|
||||
|
||||
logger.info(f"Injected custom iCal properties into event {event_uid}")
|
||||
logger.info("Injected custom iCal properties into event %s", event_uid)
|
||||
|
||||
# Reload the event to confirm custom fields are present
|
||||
await event.load()
|
||||
@@ -91,7 +91,7 @@ END:VCALENDAR"""
|
||||
}
|
||||
|
||||
await nc_client.calendar.update_event(calendar_name, event_uid, update_data)
|
||||
logger.info(f"Updated event {event_uid} through MCP client")
|
||||
logger.info("Updated event %s through MCP client", event_uid)
|
||||
|
||||
# Reload the event to see if custom fields survived
|
||||
await event.load()
|
||||
@@ -117,7 +117,7 @@ END:VCALENDAR"""
|
||||
try:
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
except Exception as cleanup_error:
|
||||
logger.warning(f"Failed to cleanup event {event_uid}: {cleanup_error}")
|
||||
logger.warning("Failed to cleanup event %s: %s", event_uid, cleanup_error)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -145,7 +145,7 @@ async def test_contact_extended_fields_preservation(nc_client):
|
||||
contact_data=basic_contact_data,
|
||||
)
|
||||
|
||||
logger.info(f"Created basic contact {contact_uid}")
|
||||
logger.info("Created basic contact %s", contact_uid)
|
||||
|
||||
# Now inject a rich vCard with extended fields directly via CardDAV
|
||||
extended_vcard = f"""BEGIN:VCARD
|
||||
@@ -182,7 +182,7 @@ END:VCARD"""
|
||||
headers={"Content-Type": "text/vcard; charset=utf-8"},
|
||||
)
|
||||
|
||||
logger.info(f"Injected extended vCard for contact {contact_uid}")
|
||||
logger.info("Injected extended vCard for contact %s", contact_uid)
|
||||
|
||||
# Retrieve the contact to confirm extended fields are present in raw vCard
|
||||
response = await nc_client.contacts._make_request("GET", contact_path)
|
||||
@@ -232,7 +232,7 @@ END:VCARD"""
|
||||
)
|
||||
logger.info("✓ Contact updated successfully")
|
||||
except Exception as e:
|
||||
logger.error(f"✗ Failed to update contact: {e}")
|
||||
logger.error("✗ Failed to update contact: %s", e)
|
||||
raise
|
||||
|
||||
# Retrieve the contact again to see if extended fields survived
|
||||
@@ -268,9 +268,9 @@ END:VCARD"""
|
||||
all_preserved = True
|
||||
for field_pattern, field_name in extended_field_checks:
|
||||
if field_pattern in updated_addressdata:
|
||||
logger.info(f"✓ {field_name} preserved")
|
||||
logger.info("✓ %s preserved", field_name)
|
||||
else:
|
||||
logger.error(f"✗ {field_name} was lost during update")
|
||||
logger.error("✗ %s was lost during update", field_name)
|
||||
all_preserved = False
|
||||
|
||||
# The test should PASS - field preservation should work
|
||||
@@ -286,7 +286,7 @@ END:VCARD"""
|
||||
await nc_client.contacts.delete_addressbook(name=addressbook_name)
|
||||
except Exception as cleanup_error:
|
||||
logger.warning(
|
||||
f"Failed to cleanup addressbook {addressbook_name}: {cleanup_error}"
|
||||
"Failed to cleanup addressbook %s: %s", addressbook_name, cleanup_error
|
||||
)
|
||||
|
||||
|
||||
@@ -415,9 +415,9 @@ END:VCALENDAR"""
|
||||
else:
|
||||
lost.append(prop)
|
||||
|
||||
logger.info(f"Properties that SURVIVED: {survived}")
|
||||
logger.info("Properties that SURVIVED: %s", survived)
|
||||
if lost:
|
||||
logger.error(f"Properties that were LOST: {lost}")
|
||||
logger.error("Properties that were LOST: %s", lost)
|
||||
|
||||
# Assert that all extended properties were preserved
|
||||
assert len(lost) == 0, (
|
||||
@@ -430,4 +430,4 @@ END:VCALENDAR"""
|
||||
try:
|
||||
await nc_client.calendar.delete_event(calendar_name, event_uid)
|
||||
except Exception as cleanup_error:
|
||||
logger.warning(f"Failed to cleanup event {event_uid}: {cleanup_error}")
|
||||
logger.warning("Failed to cleanup event %s: %s", event_uid, cleanup_error)
|
||||
|
||||
@@ -33,29 +33,29 @@ async def temporary_todo(nc_client: NextcloudClient, temporary_calendar: str):
|
||||
}
|
||||
|
||||
try:
|
||||
logger.info(f"Creating temporary todo in calendar: {calendar_name}")
|
||||
logger.info("Creating temporary todo in calendar: %s", calendar_name)
|
||||
result = await nc_client.calendar.create_todo(calendar_name, todo_data)
|
||||
todo_uid = result.get("uid")
|
||||
|
||||
if not todo_uid:
|
||||
pytest.fail("Failed to create temporary todo")
|
||||
|
||||
logger.info(f"Created temporary todo with UID: {todo_uid}")
|
||||
logger.info("Created temporary todo with UID: %s", todo_uid)
|
||||
yield {"uid": todo_uid, "calendar_name": calendar_name, "data": todo_data}
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
if todo_uid:
|
||||
try:
|
||||
logger.info(f"Cleaning up temporary todo: {todo_uid}")
|
||||
logger.info("Cleaning up temporary todo: %s", todo_uid)
|
||||
await nc_client.calendar.delete_todo(calendar_name, todo_uid)
|
||||
logger.info(f"Successfully deleted temporary todo: {todo_uid}")
|
||||
logger.info("Successfully deleted temporary todo: %s", todo_uid)
|
||||
except HTTPStatusError as e:
|
||||
if e.response.status_code != 404:
|
||||
logger.error(f"Error deleting temporary todo {todo_uid}: {e}")
|
||||
logger.error("Error deleting temporary todo %s: %s", todo_uid, e)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Unexpected error deleting temporary todo {todo_uid}: {e}"
|
||||
"Unexpected error deleting temporary todo %s: %s", todo_uid, e
|
||||
)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ async def test_create_and_delete_todo(
|
||||
assert result["status_code"] in [200, 201, 204]
|
||||
|
||||
todo_uid = result["uid"]
|
||||
logger.info(f"Created todo with UID: {todo_uid}")
|
||||
logger.info("Created todo with UID: %s", todo_uid)
|
||||
|
||||
# Verify todo was created by listing todos
|
||||
todos = await nc_client.calendar.list_todos(calendar_name)
|
||||
@@ -103,10 +103,10 @@ async def test_create_and_delete_todo(
|
||||
delete_result = await nc_client.calendar.delete_todo(calendar_name, todo_uid)
|
||||
assert delete_result["status_code"] in [200, 204, 404]
|
||||
|
||||
logger.info(f"Successfully deleted todo: {todo_uid}")
|
||||
logger.info("Successfully deleted todo: %s", todo_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Test failed: {e}")
|
||||
logger.error("Test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ async def test_list_todos(nc_client: NextcloudClient, temporary_calendar: str):
|
||||
for uid in todo_uids:
|
||||
assert uid in listed_uids
|
||||
|
||||
logger.info(f"Found {len(todos)} todos in calendar")
|
||||
logger.info("Found %s todos in calendar", len(todos))
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
@@ -187,10 +187,10 @@ async def test_update_todo(nc_client: NextcloudClient, temporary_todo: dict):
|
||||
assert updated_todo["priority"] == 1
|
||||
assert updated_todo["percent_complete"] == 50
|
||||
|
||||
logger.info(f"Successfully updated todo: {todo_uid}")
|
||||
logger.info("Successfully updated todo: %s", todo_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Todo update test failed: {e}")
|
||||
logger.error("Todo update test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ async def test_todo_with_dates(nc_client: NextcloudClient, temporary_calendar: s
|
||||
try:
|
||||
result = await nc_client.calendar.create_todo(calendar_name, todo_data)
|
||||
todo_uid = result["uid"]
|
||||
logger.info(f"Created todo with dates, UID: {todo_uid}")
|
||||
logger.info("Created todo with dates, UID: %s", todo_uid)
|
||||
|
||||
# Verify dates
|
||||
todos = await nc_client.calendar.list_todos(calendar_name)
|
||||
@@ -228,7 +228,7 @@ async def test_todo_with_dates(nc_client: NextcloudClient, temporary_calendar: s
|
||||
await nc_client.calendar.delete_todo(calendar_name, todo_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Date handling test failed: {e}")
|
||||
logger.error("Date handling test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ async def test_todo_status_transitions(
|
||||
assert todo["percent_complete"] == 100
|
||||
assert "completed" in todo
|
||||
|
||||
logger.info(f"Successfully transitioned todo through statuses: {todo_uid}")
|
||||
logger.info("Successfully transitioned todo through statuses: %s", todo_uid)
|
||||
|
||||
finally:
|
||||
await nc_client.calendar.delete_todo(calendar_name, todo_uid)
|
||||
@@ -315,7 +315,7 @@ async def test_todo_priority_levels(
|
||||
assert todo is not None
|
||||
assert todo["priority"] == expected_priority
|
||||
|
||||
logger.info(f"Successfully tested priority levels: {priorities}")
|
||||
logger.info("Successfully tested priority levels: %s", priorities)
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
@@ -342,7 +342,7 @@ async def test_todo_with_categories(
|
||||
try:
|
||||
result = await nc_client.calendar.create_todo(calendar_name, todo_data)
|
||||
todo_uid = result["uid"]
|
||||
logger.info(f"Created todo with categories, UID: {todo_uid}")
|
||||
logger.info("Created todo with categories, UID: %s", todo_uid)
|
||||
|
||||
# Verify categories
|
||||
todos = await nc_client.calendar.list_todos(calendar_name)
|
||||
@@ -360,7 +360,7 @@ async def test_todo_with_categories(
|
||||
await nc_client.calendar.delete_todo(calendar_name, todo_uid)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Categories test failed: {e}")
|
||||
logger.error("Categories test failed: %s", e)
|
||||
raise
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ async def test_search_todos_across_calendars(
|
||||
assert todo1["calendar_name"] == cal1_name
|
||||
assert todo2["calendar_name"] == cal2_name
|
||||
|
||||
logger.info(f"Found {len(all_todos)} todos across all calendars")
|
||||
logger.info("Found %s todos across all calendars", len(all_todos))
|
||||
|
||||
finally:
|
||||
# Cleanup: Delete only the todos we created (calendars are reused/built-in)
|
||||
@@ -428,7 +428,7 @@ async def test_get_nonexistent_todo(
|
||||
matching_todos = [t for t in todos if t.get("uid") == fake_uid]
|
||||
assert len(matching_todos) == 0
|
||||
|
||||
logger.info(f"Verified nonexistent todo UID: {fake_uid}")
|
||||
logger.info("Verified nonexistent todo UID: %s", fake_uid)
|
||||
|
||||
|
||||
async def test_delete_nonexistent_todo(
|
||||
@@ -440,7 +440,7 @@ async def test_delete_nonexistent_todo(
|
||||
|
||||
result = await nc_client.calendar.delete_todo(calendar_name, fake_uid)
|
||||
assert result["status_code"] == 404
|
||||
logger.info(f"Correctly got 404 for deleting nonexistent todo: {fake_uid}")
|
||||
logger.info("Correctly got 404 for deleting nonexistent todo: %s", fake_uid)
|
||||
|
||||
|
||||
async def test_list_todos_with_filters(
|
||||
@@ -487,7 +487,7 @@ async def test_list_todos_with_filters(
|
||||
our_todo_uids = [t["uid"] for t in all_todos if t["uid"] in created_uids]
|
||||
assert len(our_todo_uids) == 3
|
||||
|
||||
logger.info(f"Successfully created and listed {len(created_uids)} test todos")
|
||||
logger.info("Successfully created and listed %s test todos", len(created_uids))
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
|
||||
@@ -22,7 +22,7 @@ async def test_list_addressbooks(nc_client: NextcloudClient):
|
||||
if not addressbooks:
|
||||
pytest.skip("No addressbooks available - Contacts app may not be enabled")
|
||||
|
||||
logger.info(f"Found {len(addressbooks)} addressbooks")
|
||||
logger.info("Found %s addressbooks", len(addressbooks))
|
||||
|
||||
# Check structure of addressbooks
|
||||
for addressbook in addressbooks:
|
||||
@@ -31,7 +31,7 @@ async def test_list_addressbooks(nc_client: NextcloudClient):
|
||||
assert "getctag" in addressbook
|
||||
|
||||
logger.info(
|
||||
f"Addressbook: {addressbook['name']} - {addressbook['display_name']}"
|
||||
"Addressbook: %s - %s", addressbook["name"], addressbook["display_name"]
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -27,14 +27,18 @@ async def test_attachments_add_and_get(
|
||||
note_category = note_data.get("category") # Get category from fixture data
|
||||
|
||||
logger.info(
|
||||
f"Attempting to retrieve attachment '{attachment_filename}' added by fixture for note ID: {note_id}"
|
||||
"Attempting to retrieve attachment '%s' added by fixture for note ID: %s",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
)
|
||||
# Pass category to get_note_attachment
|
||||
retrieved_content, retrieved_mime = await nc_client.webdav.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=note_category
|
||||
)
|
||||
logger.info(
|
||||
f"Attachment retrieved. Mime type: {retrieved_mime}, Size: {len(retrieved_content)} bytes"
|
||||
"Attachment retrieved. Mime type: %s, Size: %s bytes",
|
||||
retrieved_mime,
|
||||
len(retrieved_content),
|
||||
)
|
||||
|
||||
assert retrieved_content == attachment_content
|
||||
@@ -55,7 +59,9 @@ async def test_attachments_add_to_note_with_category(
|
||||
note_id = note_data["id"]
|
||||
note_category = note_data["category"]
|
||||
logger.info(
|
||||
f"Using note ID: {note_id} with category '{note_category}' for attachment test."
|
||||
"Using note ID: %s with category '%s' for attachment test.",
|
||||
note_id,
|
||||
note_category,
|
||||
)
|
||||
|
||||
# Add attachment within the test
|
||||
@@ -65,7 +71,7 @@ async def test_attachments_add_to_note_with_category(
|
||||
attachment_mime = "text/plain"
|
||||
|
||||
logger.info(
|
||||
f"Attempting to add attachment '{attachment_filename}' to note ID: {note_id}"
|
||||
"Attempting to add attachment '%s' to note ID: %s", attachment_filename, note_id
|
||||
)
|
||||
# Pass category to add_note_attachment
|
||||
upload_response = await nc_client.webdav.add_note_attachment(
|
||||
@@ -78,13 +84,17 @@ async def test_attachments_add_to_note_with_category(
|
||||
assert upload_response and "status_code" in upload_response
|
||||
assert upload_response["status_code"] in [201, 204]
|
||||
logger.info(
|
||||
f"Attachment '{attachment_filename}' added successfully (Status: {upload_response['status_code']})."
|
||||
"Attachment '%s' added successfully (Status: %s).",
|
||||
attachment_filename,
|
||||
upload_response["status_code"],
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
# Get and Verify Attachment
|
||||
logger.info(
|
||||
f"Attempting to retrieve attachment '{attachment_filename}' from note ID: {note_id}"
|
||||
"Attempting to retrieve attachment '%s' from note ID: %s",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
)
|
||||
# Pass category to get_note_attachment
|
||||
retrieved_content, retrieved_mime = await nc_client.webdav.get_note_attachment(
|
||||
@@ -93,7 +103,9 @@ async def test_attachments_add_to_note_with_category(
|
||||
category=note_category, # Pass the note's category
|
||||
)
|
||||
logger.info(
|
||||
f"Attachment retrieved. Mime type: {retrieved_mime}, Size: {len(retrieved_content)} bytes"
|
||||
"Attachment retrieved. Mime type: %s, Size: %s bytes",
|
||||
retrieved_mime,
|
||||
len(retrieved_content),
|
||||
)
|
||||
|
||||
assert retrieved_content == attachment_content
|
||||
@@ -123,24 +135,28 @@ async def test_attachments_cleanup_on_note_delete(
|
||||
# Instead, we will manually delete the note here and verify the attachment is gone.
|
||||
|
||||
logger.info(
|
||||
f"Attachment '{attachment_filename}' exists for note {note_id} (added by fixture)."
|
||||
"Attachment '%s' exists for note %s (added by fixture).",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
)
|
||||
|
||||
# Manually delete the note
|
||||
logger.info(f"Manually deleting note ID: {note_id} within the test.")
|
||||
logger.info("Manually deleting note ID: %s within the test.", note_id)
|
||||
await nc_client.notes.delete_note(note_id=note_id)
|
||||
logger.info(f"Note ID: {note_id} deleted successfully.")
|
||||
logger.info("Note ID: %s deleted successfully.", note_id)
|
||||
time.sleep(1)
|
||||
|
||||
# Verify Note Is Deleted
|
||||
with pytest.raises(HTTPStatusError) as excinfo_note:
|
||||
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).")
|
||||
logger.info("Verified note %s deletion (404 received).", note_id)
|
||||
|
||||
# Verify Attachment Is Deleted (via 404 on GET)
|
||||
logger.info(
|
||||
f"Verifying attachment '{attachment_filename}' is deleted for note ID: {note_id}"
|
||||
"Verifying attachment '%s' is deleted for note ID: %s",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
)
|
||||
with pytest.raises(HTTPStatusError) as excinfo_attach:
|
||||
# Pass category to get_note_attachment - although it should fail anyway
|
||||
@@ -154,7 +170,8 @@ async def test_attachments_cleanup_on_note_delete(
|
||||
# Expect 404 because the note itself is gone
|
||||
assert excinfo_attach.value.response.status_code == 404
|
||||
logger.info(
|
||||
f"Attachment '{attachment_filename}' correctly not found (404) after note deletion."
|
||||
"Attachment '%s' correctly not found (404) after note deletion.",
|
||||
attachment_filename,
|
||||
)
|
||||
|
||||
# Directly verify attachment directory doesn't exist using WebDAV PROPFIND
|
||||
@@ -172,7 +189,7 @@ async def test_attachments_cleanup_on_note_delete(
|
||||
status = propfind_resp.status_code
|
||||
if status in [200, 207]: # Successful PROPFIND means directory exists
|
||||
logger.error(
|
||||
f"Attachment directory still exists! PROPFIND returned {status}"
|
||||
"Attachment directory still exists! PROPFIND returned %s", status
|
||||
)
|
||||
assert False, (
|
||||
f"Expected attachment directory to be gone, but PROPFIND returned {status}!"
|
||||
@@ -205,18 +222,21 @@ async 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}'")
|
||||
logger.info("Creating note '%s' in category '%s'", note_title, initial_category)
|
||||
created_note = await nc_client.notes.create_note(
|
||||
title=note_title, content="Initial content", category=initial_category
|
||||
)
|
||||
note_id = created_note["id"]
|
||||
etag1 = created_note["etag"]
|
||||
logger.info(f"Note created with ID: {note_id}, Etag: {etag1}")
|
||||
logger.info("Note created with ID: %s, Etag: %s", note_id, etag1)
|
||||
time.sleep(1)
|
||||
|
||||
# 2. Add attachment (passing initial category)
|
||||
logger.info(
|
||||
f"Adding attachment '{attachment_filename}' to note {note_id} (in {initial_category})"
|
||||
"Adding attachment '%s' to note %s (in %s)",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
initial_category,
|
||||
)
|
||||
upload_response = await nc_client.webdav.add_note_attachment(
|
||||
note_id=note_id,
|
||||
@@ -231,7 +251,8 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
|
||||
# 3. Verify attachment retrieval from initial category (passing initial category)
|
||||
logger.info(
|
||||
f"Verifying attachment retrieval from initial category '{initial_category}'"
|
||||
"Verifying attachment retrieval from initial category '%s'",
|
||||
initial_category,
|
||||
)
|
||||
retrieved_content1, _ = await nc_client.webdav.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=initial_category
|
||||
@@ -241,7 +262,10 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
|
||||
# 4. Update note category (with retry for ETag conflicts from background scanner)
|
||||
logger.info(
|
||||
f"Updating note {note_id} category from '{initial_category}' to '{new_category}'"
|
||||
"Updating note %s category from '%s' to '%s'",
|
||||
note_id,
|
||||
initial_category,
|
||||
new_category,
|
||||
)
|
||||
# Retry logic for 412 Precondition Failed (ETag conflict)
|
||||
# This can happen if the background vector scanner touches the note
|
||||
@@ -252,7 +276,10 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
current_note_data = await nc_client.notes.get_note(note_id=note_id)
|
||||
current_etag = current_note_data["etag"]
|
||||
logger.info(
|
||||
f"Update attempt {attempt + 1}/{max_update_attempts}, current etag: {current_etag}"
|
||||
"Update attempt %s/%s, current etag: %s",
|
||||
attempt + 1,
|
||||
max_update_attempts,
|
||||
current_etag,
|
||||
)
|
||||
|
||||
updated_note = await nc_client.notes.update(
|
||||
@@ -264,14 +291,14 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
)
|
||||
etag3 = updated_note["etag"]
|
||||
assert updated_note["category"] == new_category
|
||||
logger.info(f"Note category updated successfully. New Etag: {etag3}")
|
||||
logger.info("Note category updated successfully. New Etag: %s", etag3)
|
||||
break # Success, exit retry loop
|
||||
|
||||
except HTTPStatusError as e:
|
||||
if e.response.status_code == 412 and attempt < max_update_attempts - 1:
|
||||
# ETag conflict (likely from background scanner), retry
|
||||
logger.warning(
|
||||
f"ETag conflict (412) on attempt {attempt + 1}, retrying..."
|
||||
"ETag conflict (412) on attempt %s, retrying...", attempt + 1
|
||||
)
|
||||
time.sleep(1) # Brief delay before retry
|
||||
continue
|
||||
@@ -283,7 +310,7 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
|
||||
# 5. Verify attachment retrieval from *new* category (passing new category)
|
||||
logger.info(
|
||||
f"Verifying attachment retrieval from new category '{new_category}'"
|
||||
"Verifying attachment retrieval from new category '%s'", new_category
|
||||
)
|
||||
retrieved_content2, _ = await nc_client.webdav.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=new_category
|
||||
@@ -305,7 +332,8 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
status = propfind_resp.status_code
|
||||
if status in [200, 207]: # Successful PROPFIND means directory exists
|
||||
logger.error(
|
||||
f"Old attachment directory still exists! PROPFIND returned {status}"
|
||||
"Old attachment directory still exists! PROPFIND returned %s",
|
||||
status,
|
||||
)
|
||||
assert False, (
|
||||
f"Expected old directory to be gone, but PROPFIND returned {status} - directory still exists!"
|
||||
@@ -333,11 +361,13 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
200,
|
||||
], f"Expected PROPFIND to return success (207/200), got {status}"
|
||||
logger.info(
|
||||
f"Verified new attachment directory exists via PROPFIND ({status} received)"
|
||||
"Verified new attachment directory exists via PROPFIND (%s received)",
|
||||
status,
|
||||
)
|
||||
except HTTPStatusError as e:
|
||||
logger.error(
|
||||
f"New attachment directory not found! PROPFIND failed with {e.response.status_code}"
|
||||
"New attachment directory not found! PROPFIND failed with %s",
|
||||
e.response.status_code,
|
||||
)
|
||||
assert False, (
|
||||
f"Expected new attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
|
||||
@@ -347,11 +377,13 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
# 6. Cleanup: Delete the note (client should use the *final* category for cleanup path)
|
||||
if note_id:
|
||||
logger.info(
|
||||
f"Cleaning up note ID: {note_id} (last known category: '{new_category}')"
|
||||
"Cleaning up note ID: %s (last known category: '%s')",
|
||||
note_id,
|
||||
new_category,
|
||||
)
|
||||
try:
|
||||
await nc_client.notes.delete_note(note_id=note_id)
|
||||
logger.info(f"Note {note_id} deleted.")
|
||||
logger.info("Note %s deleted.", note_id)
|
||||
time.sleep(1)
|
||||
# Verify note deletion
|
||||
with pytest.raises(HTTPStatusError) as excinfo_note_del:
|
||||
@@ -424,4 +456,4 @@ async def test_attachments_category_change_handling(nc_client: NextcloudClient):
|
||||
"Verified all attachment directories are properly cleaned up."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during cleanup for note {note_id}: {e}")
|
||||
logger.error("Error during cleanup for note %s: %s", note_id, e)
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_image_data() -> tuple[bytes, str]:
|
||||
img.save(img_byte_arr, format="PNG")
|
||||
image_bytes = img_byte_arr.getvalue()
|
||||
suggested_filename = "test_image.png"
|
||||
logger.info(f"Generated test image data ({len(image_bytes)} bytes).")
|
||||
logger.info("Generated test image data (%s bytes).", len(image_bytes))
|
||||
return image_bytes, suggested_filename
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ async def test_note_with_embedded_image(
|
||||
# 1. Upload the image as an attachment
|
||||
note_category = note_data.get("category") # Get category from fixture data
|
||||
logger.info(
|
||||
f"Uploading image attachment '{attachment_filename}' to note {note_id} (category: '{note_category or ''}')..."
|
||||
"Uploading image attachment '%s' to note %s (category: '%s')...",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
note_category or "",
|
||||
)
|
||||
upload_response = await nc_client.webdav.add_note_attachment(
|
||||
note_id=note_id,
|
||||
@@ -72,7 +75,7 @@ async def test_note_with_embedded_image(
|
||||
)
|
||||
assert upload_response and upload_response.get("status_code") in [201, 204]
|
||||
logger.info(
|
||||
f"Image uploaded successfully (Status: {upload_response.get('status_code')})."
|
||||
"Image uploaded successfully (Status: %s).", upload_response.get("status_code")
|
||||
)
|
||||
time.sleep(1) # Allow potential processing time
|
||||
|
||||
@@ -94,11 +97,12 @@ async def test_note_with_embedded_image(
|
||||
200,
|
||||
], f"Expected PROPFIND to return success (207/200), got {status}"
|
||||
logger.info(
|
||||
f"Verified attachment directory exists via PROPFIND ({status} received)"
|
||||
"Verified attachment directory exists via PROPFIND (%s received)", status
|
||||
)
|
||||
except HTTPStatusError as e:
|
||||
logger.error(
|
||||
f"Attachment directory not found! PROPFIND failed with {e.response.status_code}"
|
||||
"Attachment directory not found! PROPFIND failed with %s",
|
||||
e.response.status_code,
|
||||
)
|
||||
assert False, (
|
||||
f"Expected attachment directory to exist, but PROPFIND failed with {e.response.status_code}"
|
||||
@@ -135,7 +139,9 @@ async def test_note_with_embedded_image(
|
||||
|
||||
# 4. Verify the image attachment can be retrieved
|
||||
logger.info(
|
||||
f"Retrieving image attachment '{attachment_filename}' (category: '{note_category or ''}')..."
|
||||
"Retrieving image attachment '%s' (category: '%s')...",
|
||||
attachment_filename,
|
||||
note_category or "",
|
||||
)
|
||||
# Pass category to get_note_attachment
|
||||
retrieved_img_content, mime_type = await nc_client.webdav.get_note_attachment(
|
||||
@@ -149,17 +155,17 @@ async def test_note_with_embedded_image(
|
||||
|
||||
# 5. Manually trigger deletion to verify cleanup (instead of waiting for fixture teardown)
|
||||
logger.info(
|
||||
f"Manually deleting note ID: {note_id} to verify proper attachment cleanup"
|
||||
"Manually deleting note ID: %s to verify proper attachment cleanup", note_id
|
||||
)
|
||||
await nc_client.notes.delete_note(note_id=note_id)
|
||||
logger.info(f"Note ID: {note_id} deleted successfully.")
|
||||
logger.info("Note ID: %s deleted successfully.", note_id)
|
||||
time.sleep(1)
|
||||
|
||||
# 6. Verify note is deleted
|
||||
with pytest.raises(HTTPStatusError) as excinfo_note:
|
||||
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).")
|
||||
logger.info("Verified note %s deletion (404 received).", note_id)
|
||||
|
||||
# 7. Verify attachment directory is deleted via WebDAV PROPFIND
|
||||
logger.info("Directly verifying attachment directory doesn't exist via PROPFIND")
|
||||
@@ -170,7 +176,7 @@ async def test_note_with_embedded_image(
|
||||
status = propfind_resp.status_code
|
||||
if status in [200, 207]: # Successful PROPFIND means directory exists
|
||||
logger.error(
|
||||
f"Attachment directory still exists! PROPFIND returned {status}"
|
||||
"Attachment directory still exists! PROPFIND returned %s", status
|
||||
)
|
||||
assert False, (
|
||||
f"Expected attachment directory to be gone, but PROPFIND returned {status}!"
|
||||
|
||||
@@ -39,7 +39,7 @@ async def test_create_and_delete_share(nc_client):
|
||||
assert share_data is not None
|
||||
assert "id" in share_data
|
||||
share_id = share_data["id"]
|
||||
logger.info(f"Created share: {share_id}")
|
||||
logger.info("Created share: %s", share_id)
|
||||
|
||||
# Get share info
|
||||
share_info = await nc_client.sharing.get_share(share_id)
|
||||
@@ -56,7 +56,7 @@ async def test_create_and_delete_share(nc_client):
|
||||
# Cleanup
|
||||
if share_id:
|
||||
await nc_client.sharing.delete_share(share_id)
|
||||
logger.info(f"Deleted share: {share_id}")
|
||||
logger.info("Deleted share: %s", share_id)
|
||||
|
||||
await nc_client.webdav.delete_resource(file_path)
|
||||
|
||||
|
||||
@@ -29,18 +29,21 @@ async 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}'")
|
||||
logger.info("Creating note '%s' in category '%s'", note_title, initial_category)
|
||||
created_note = await nc_client.notes.create_note(
|
||||
title=note_title, content="Initial content", category=initial_category
|
||||
)
|
||||
note_id = created_note["id"]
|
||||
etag1 = created_note["etag"]
|
||||
logger.info(f"Note created with ID: {note_id}, Etag: {etag1}")
|
||||
logger.info("Note created with ID: %s, Etag: %s", note_id, etag1)
|
||||
time.sleep(1)
|
||||
|
||||
# 2. Add attachment (passing initial category)
|
||||
logger.info(
|
||||
f"Adding attachment '{attachment_filename}' to note {note_id} (in {initial_category})"
|
||||
"Adding attachment '%s' to note %s (in %s)",
|
||||
attachment_filename,
|
||||
note_id,
|
||||
initial_category,
|
||||
)
|
||||
upload_response = await nc_client.webdav.add_note_attachment(
|
||||
note_id=note_id,
|
||||
@@ -55,7 +58,8 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
|
||||
# 3. Verify attachment retrieval from initial category
|
||||
logger.info(
|
||||
f"Verifying attachment retrieval from initial category '{initial_category}'"
|
||||
"Verifying attachment retrieval from initial category '%s'",
|
||||
initial_category,
|
||||
)
|
||||
retrieved_content1, _ = await nc_client.webdav.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=initial_category
|
||||
@@ -65,13 +69,16 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
|
||||
# 4. Construct and check the WebDAV path for the initial category's attachment directory
|
||||
initial_webdav_path = f"Notes/{initial_category}/.attachments.{note_id}"
|
||||
logger.info(f"Initial WebDAV path for attachments: {initial_webdav_path}")
|
||||
logger.info("Initial WebDAV path for attachments: %s", initial_webdav_path)
|
||||
# Here we would check if the directory exists, but the WebDAV client doesn't directly
|
||||
# expose directory listing functionality, so we'll infer from attachment retrieval success
|
||||
|
||||
# 5. Update note category
|
||||
logger.info(
|
||||
f"Updating note {note_id} category from '{initial_category}' to '{new_category}'"
|
||||
"Updating note %s category from '%s' to '%s'",
|
||||
note_id,
|
||||
initial_category,
|
||||
new_category,
|
||||
)
|
||||
current_note_data = await nc_client.notes.get_note(note_id=note_id)
|
||||
current_etag = current_note_data["etag"]
|
||||
@@ -84,12 +91,12 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
)
|
||||
etag3 = updated_note["etag"]
|
||||
assert updated_note["category"] == new_category
|
||||
logger.info(f"Note category updated successfully. New Etag: {etag3}")
|
||||
logger.info("Note category updated successfully. New Etag: %s", etag3)
|
||||
time.sleep(1)
|
||||
|
||||
# 6. Verify attachment retrieval from new category
|
||||
logger.info(
|
||||
f"Verifying attachment retrieval from new category '{new_category}'"
|
||||
"Verifying attachment retrieval from new category '%s'", new_category
|
||||
)
|
||||
retrieved_content2, _ = await nc_client.webdav.get_note_attachment(
|
||||
note_id=note_id, filename=attachment_filename, category=new_category
|
||||
@@ -99,7 +106,8 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
|
||||
# 7. Try to retrieve from old category - this should fail
|
||||
logger.info(
|
||||
f"Trying to retrieve attachment from old category '{initial_category}' - should fail"
|
||||
"Trying to retrieve attachment from old category '%s' - should fail",
|
||||
initial_category,
|
||||
)
|
||||
try:
|
||||
await nc_client.webdav.get_note_attachment(
|
||||
@@ -115,7 +123,8 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
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}"
|
||||
"Correctly got error accessing old category path: %s",
|
||||
e.response.status_code,
|
||||
)
|
||||
assert e.response.status_code == 404, (
|
||||
f"Expected 404, got {e.response.status_code}"
|
||||
@@ -143,14 +152,16 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
207,
|
||||
]: # Success codes indicate the directory exists (a problem)
|
||||
logger.error(
|
||||
f"Old attachment directory still exists! PROPFIND returned {status}"
|
||||
"Old attachment directory still exists! PROPFIND returned %s",
|
||||
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})"
|
||||
"Verified old attachment directory does not exist (PROPFIND returned %s)",
|
||||
status,
|
||||
)
|
||||
except HTTPStatusError as e:
|
||||
# 404 is expected - directory should not exist
|
||||
@@ -164,10 +175,10 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
finally:
|
||||
# 8. Cleanup: Delete the note
|
||||
if note_id:
|
||||
logger.info(f"Cleaning up note ID: {note_id}")
|
||||
logger.info("Cleaning up note ID: %s", note_id)
|
||||
try:
|
||||
await nc_client.notes.delete_note(note_id=note_id)
|
||||
logger.info(f"Note {note_id} deleted.")
|
||||
logger.info("Note %s deleted.", note_id)
|
||||
time.sleep(1)
|
||||
|
||||
# 9. Verify both old and new attachment paths are gone
|
||||
@@ -209,14 +220,16 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
207,
|
||||
]: # Success codes indicate the directory exists (a problem)
|
||||
logger.error(
|
||||
f"New category attachment directory still exists! PROPFIND returned {status}"
|
||||
"New category attachment directory still exists! PROPFIND returned %s",
|
||||
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})"
|
||||
"Verified new category attachment directory does not exist (PROPFIND returned %s)",
|
||||
status,
|
||||
)
|
||||
except HTTPStatusError as e:
|
||||
assert e.response.status_code == 404, (
|
||||
@@ -240,14 +253,16 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
207,
|
||||
]: # Success codes indicate the directory exists (a problem)
|
||||
logger.error(
|
||||
f"Old category attachment directory still exists! PROPFIND returned {status}"
|
||||
"Old category attachment directory still exists! PROPFIND returned %s",
|
||||
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})"
|
||||
"Verified old category attachment directory does not exist (PROPFIND returned %s)",
|
||||
status,
|
||||
)
|
||||
except HTTPStatusError as e:
|
||||
assert e.response.status_code == 404, (
|
||||
@@ -261,4 +276,4 @@ async def test_category_change_cleans_up_old_attachments_directory(
|
||||
"Verified all attachment directories are properly cleaned up."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during cleanup for note {note_id}: {e}")
|
||||
logger.error("Error during cleanup for note %s: %s", note_id, e)
|
||||
|
||||
@@ -33,7 +33,7 @@ async def test_create_and_delete_directory(
|
||||
# Create directory
|
||||
result = await nc_client.webdav.create_directory(test_dir)
|
||||
assert result["status_code"] == 201 # Created
|
||||
logger.info(f"Created directory: {test_dir}")
|
||||
logger.info("Created directory: %s", test_dir)
|
||||
|
||||
# Verify directory exists by listing parent
|
||||
parent_listing = await nc_client.webdav.list_directory(test_base_path)
|
||||
@@ -43,7 +43,7 @@ async def test_create_and_delete_directory(
|
||||
# Delete directory
|
||||
delete_result = await nc_client.webdav.delete_resource(test_dir)
|
||||
assert delete_result["status_code"] in [204, 404] # No Content or Not Found
|
||||
logger.info(f"Deleted directory: {test_dir}")
|
||||
logger.info("Deleted directory: %s", test_dir)
|
||||
|
||||
finally:
|
||||
# Cleanup: ensure directory is deleted
|
||||
@@ -67,13 +67,13 @@ async def test_write_read_delete_file(nc_client: NextcloudClient, test_base_path
|
||||
test_file, test_content.encode("utf-8"), content_type="text/plain"
|
||||
)
|
||||
assert write_result["status_code"] in [200, 201, 204] # Success codes
|
||||
logger.info(f"Wrote file: {test_file}")
|
||||
logger.info("Wrote file: %s", test_file)
|
||||
|
||||
# Read file back
|
||||
content, content_type = await nc_client.webdav.read_file(test_file)
|
||||
assert content.decode("utf-8") == test_content
|
||||
assert "text/plain" in content_type
|
||||
logger.info(f"Read file: {test_file}")
|
||||
logger.info("Read file: %s", test_file)
|
||||
|
||||
# Verify file appears in directory listing
|
||||
listing = await nc_client.webdav.list_directory(test_base_path)
|
||||
@@ -83,7 +83,7 @@ async def test_write_read_delete_file(nc_client: NextcloudClient, test_base_path
|
||||
# Delete file
|
||||
delete_result = await nc_client.webdav.delete_resource(test_file)
|
||||
assert delete_result["status_code"] in [204, 404] # No Content or Not Found
|
||||
logger.info(f"Deleted file: {test_file}")
|
||||
logger.info("Deleted file: %s", test_file)
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
@@ -106,7 +106,7 @@ async def test_list_directory_empty_and_populated(
|
||||
empty_listing = await nc_client.webdav.list_directory(test_base_path)
|
||||
assert isinstance(empty_listing, list)
|
||||
assert len(empty_listing) == 0
|
||||
logger.info(f"Empty directory listing: {len(empty_listing)} items")
|
||||
logger.info("Empty directory listing: %s items", len(empty_listing))
|
||||
|
||||
# Add some files and directories
|
||||
await nc_client.webdav.create_directory(f"{test_base_path}/subdir1")
|
||||
@@ -140,7 +140,7 @@ async def test_list_directory_empty_and_populated(
|
||||
assert "content_type" in item
|
||||
assert "last_modified" in item
|
||||
|
||||
logger.info(f"Populated directory listing: {len(populated_listing)} items")
|
||||
logger.info("Populated directory listing: %s items", len(populated_listing))
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
@@ -162,7 +162,7 @@ async def test_read_nonexistent_file(nc_client: NextcloudClient):
|
||||
await nc_client.webdav.read_file(nonexistent_file)
|
||||
|
||||
assert exc_info.value.response.status_code == 404
|
||||
logger.info(f"Correctly got 404 for nonexistent file: {nonexistent_file}")
|
||||
logger.info("Correctly got 404 for nonexistent file: %s", nonexistent_file)
|
||||
|
||||
|
||||
async def test_delete_nonexistent_resource(nc_client: NextcloudClient):
|
||||
@@ -171,7 +171,7 @@ async def test_delete_nonexistent_resource(nc_client: NextcloudClient):
|
||||
|
||||
result = await nc_client.webdav.delete_resource(nonexistent_resource)
|
||||
assert result["status_code"] == 404
|
||||
logger.info(f"Correctly got 404 for nonexistent resource: {nonexistent_resource}")
|
||||
logger.info("Correctly got 404 for nonexistent resource: %s", nonexistent_resource)
|
||||
|
||||
|
||||
async def test_create_nested_directories(
|
||||
@@ -200,7 +200,7 @@ async def test_create_nested_directories(
|
||||
assert level2_listing[0]["name"] == "level3"
|
||||
assert level2_listing[0]["is_directory"] is True
|
||||
|
||||
logger.info(f"Created nested directory structure: {nested_path}")
|
||||
logger.info("Created nested directory structure: %s", nested_path)
|
||||
|
||||
finally:
|
||||
# Cleanup - delete from deepest to shallowest
|
||||
@@ -241,7 +241,7 @@ async def test_overwrite_existing_file(nc_client: NextcloudClient, test_base_pat
|
||||
content, _ = await nc_client.webdav.read_file(test_file)
|
||||
assert content.decode("utf-8") == new_content
|
||||
|
||||
logger.info(f"Successfully overwrote file: {test_file}")
|
||||
logger.info("Successfully overwrote file: %s", test_file)
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
@@ -270,4 +270,4 @@ async def test_list_root_directory(nc_client: NextcloudClient):
|
||||
assert "content_type" in item
|
||||
assert "last_modified" in item
|
||||
|
||||
logger.info(f"Root directory contains {len(root_listing)} items")
|
||||
logger.info("Root directory contains %s items", len(root_listing))
|
||||
|
||||
@@ -47,16 +47,16 @@ async def test_search_setup(nc_client: NextcloudClient):
|
||||
for file_path, content, content_type in test_files:
|
||||
await nc_client.webdav.write_file(file_path, content, content_type)
|
||||
|
||||
logger.info(f"Created test directory with {len(test_files)} files: {test_dir}")
|
||||
logger.info("Created test directory with %s files: %s", len(test_files), test_dir)
|
||||
|
||||
yield test_dir
|
||||
|
||||
# Cleanup
|
||||
try:
|
||||
await nc_client.webdav.delete_resource(test_dir)
|
||||
logger.info(f"Cleaned up test directory: {test_dir}")
|
||||
logger.info("Cleaned up test directory: %s", test_dir)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to cleanup test directory {test_dir}: {e}")
|
||||
logger.warning("Failed to cleanup test directory %s: %s", test_dir, e)
|
||||
|
||||
|
||||
async def test_find_by_name_exact(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -69,7 +69,7 @@ async def test_find_by_name_exact(nc_client: NextcloudClient, test_search_setup:
|
||||
readme_files = [r for r in results if r.get("name") == "readme.md"]
|
||||
assert len(readme_files) >= 1, "Should find readme.md"
|
||||
|
||||
logger.info(f"Found {len(results)} files matching 'readme.md'")
|
||||
logger.info("Found %s files matching 'readme.md'", len(results))
|
||||
|
||||
|
||||
async def test_find_by_name_wildcard_extension(
|
||||
@@ -86,7 +86,7 @@ async def test_find_by_name_wildcard_extension(
|
||||
name = result.get("name", "")
|
||||
assert name.endswith(".txt"), f"Expected .txt file, got {name}"
|
||||
|
||||
logger.info(f"Found {len(results)} .txt files")
|
||||
logger.info("Found %s .txt files", len(results))
|
||||
|
||||
|
||||
async def test_find_by_name_wildcard_prefix(
|
||||
@@ -105,7 +105,7 @@ async def test_find_by_name_wildcard_prefix(
|
||||
f"Expected name to start with 'document', got {name}"
|
||||
)
|
||||
|
||||
logger.info(f"Found {len(results)} files starting with 'document'")
|
||||
logger.info("Found %s files starting with 'document'", len(results))
|
||||
|
||||
|
||||
async def test_find_by_type_text(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -122,7 +122,7 @@ async def test_find_by_type_text(nc_client: NextcloudClient, test_search_setup:
|
||||
f"Expected text/* type, got {content_type}"
|
||||
)
|
||||
|
||||
logger.info(f"Found {len(results)} text files")
|
||||
logger.info("Found %s text files", len(results))
|
||||
|
||||
|
||||
async def test_find_by_type_specific(
|
||||
@@ -143,7 +143,7 @@ async def test_find_by_type_specific(
|
||||
f"Expected application/pdf, got {content_type}"
|
||||
)
|
||||
|
||||
logger.info(f"Found {len(results)} PDF files")
|
||||
logger.info("Found %s PDF files", len(results))
|
||||
|
||||
|
||||
async def test_search_with_limit(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -157,7 +157,7 @@ async def test_search_with_limit(nc_client: NextcloudClient, test_search_setup:
|
||||
assert len(results) <= 2, f"Should return at most 2 results, got {len(results)}"
|
||||
assert len(results) > 0, "Should return at least 1 result"
|
||||
|
||||
logger.info(f"Found {len(results)} files with limit=2")
|
||||
logger.info("Found %s files with limit=2", len(results))
|
||||
|
||||
|
||||
async def test_search_files_combined_filters(
|
||||
@@ -198,7 +198,7 @@ async def test_search_files_combined_filters(
|
||||
f"Expected name to start with 'document', got {name}"
|
||||
)
|
||||
|
||||
logger.info(f"Found {len(results)} files matching combined filters")
|
||||
logger.info("Found %s files matching combined filters", len(results))
|
||||
|
||||
|
||||
async def test_search_empty_scope(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -210,7 +210,7 @@ async def test_search_empty_scope(nc_client: NextcloudClient, test_search_setup:
|
||||
# Should find at least the one we created
|
||||
assert len(results) >= 1, f"Should find at least 1 file named {unique_name}"
|
||||
|
||||
logger.info(f"Found {len(results)} files in root scope")
|
||||
logger.info("Found %s files in root scope", len(results))
|
||||
|
||||
|
||||
async def test_search_subdirectory(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -226,7 +226,7 @@ async def test_search_subdirectory(nc_client: NextcloudClient, test_search_setup
|
||||
nested_file = results[0]
|
||||
assert "nested.txt" in nested_file.get("name", ""), "Should find nested.txt"
|
||||
|
||||
logger.info(f"Found file in subdirectory: {nested_file.get('name')}")
|
||||
logger.info("Found file in subdirectory: %s", nested_file.get("name"))
|
||||
|
||||
|
||||
async def test_search_no_results(nc_client: NextcloudClient, test_search_setup: str):
|
||||
@@ -259,10 +259,10 @@ async def test_search_properties_returned(
|
||||
|
||||
# Optional properties that may be present
|
||||
optional_props = ["size", "content_type", "last_modified", "etag"]
|
||||
logger.info(f"Result properties: {list(result.keys())}")
|
||||
logger.info("Result properties: %s", list(result.keys()))
|
||||
|
||||
# At least some optional properties should be present
|
||||
present_optional = [prop for prop in optional_props if prop in result]
|
||||
assert len(present_optional) > 0, f"Should have at least one of {optional_props}"
|
||||
|
||||
logger.info(f"Search returned properties: {list(result.keys())}")
|
||||
logger.info("Search returned properties: %s", list(result.keys()))
|
||||
|
||||
Reference in New Issue
Block a user