fix: apply ruff formatting to test_webdav_operations.py

- Fix quote style from single to double quotes
- Improve line breaks and spacing for better readability
- Address CI formatting requirements

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Neovasky
2025-07-26 02:33:21 -04:00
co-authored by Claude
parent bf5879d408
commit 50c1215676
+59 -57
View File
@@ -19,26 +19,28 @@ def test_base_path():
return f"mcp_test_{uuid.uuid4().hex[:8]}" return f"mcp_test_{uuid.uuid4().hex[:8]}"
async def test_create_and_delete_directory(nc_client: NextcloudClient, test_base_path: str): async def test_create_and_delete_directory(
nc_client: NextcloudClient, test_base_path: str
):
"""Test creating and deleting directories.""" """Test creating and deleting directories."""
test_dir = f"{test_base_path}/test_directory" test_dir = f"{test_base_path}/test_directory"
try: try:
# Create directory # Create directory
result = await nc_client.webdav.create_directory(test_dir) result = await nc_client.webdav.create_directory(test_dir)
assert result["status_code"] == 201 # Created assert result["status_code"] == 201 # Created
logger.info(f"Created directory: {test_dir}") logger.info(f"Created directory: {test_dir}")
# Verify directory exists by listing parent # Verify directory exists by listing parent
parent_listing = await nc_client.webdav.list_directory(test_base_path) parent_listing = await nc_client.webdav.list_directory(test_base_path)
dir_names = [item["name"] for item in parent_listing] dir_names = [item["name"] for item in parent_listing]
assert "test_directory" in dir_names assert "test_directory" in dir_names
# Delete directory # Delete directory
delete_result = await nc_client.webdav.delete_resource(test_dir) delete_result = await nc_client.webdav.delete_resource(test_dir)
assert delete_result["status_code"] in [204, 404] # No Content or Not Found assert delete_result["status_code"] in [204, 404] # No Content or Not Found
logger.info(f"Deleted directory: {test_dir}") logger.info(f"Deleted directory: {test_dir}")
finally: finally:
# Cleanup: ensure directory is deleted # Cleanup: ensure directory is deleted
try: try:
@@ -52,36 +54,34 @@ async def test_write_read_delete_file(nc_client: NextcloudClient, test_base_path
"""Test writing, reading, and deleting files.""" """Test writing, reading, and deleting files."""
test_file = f"{test_base_path}/test_file.txt" test_file = f"{test_base_path}/test_file.txt"
test_content = f"Test content {uuid.uuid4().hex}" test_content = f"Test content {uuid.uuid4().hex}"
try: try:
# Create base directory first # Create base directory first
await nc_client.webdav.create_directory(test_base_path) await nc_client.webdav.create_directory(test_base_path)
# Write file # Write file
write_result = await nc_client.webdav.write_file( write_result = await nc_client.webdav.write_file(
test_file, test_file, test_content.encode("utf-8"), content_type="text/plain"
test_content.encode('utf-8'),
content_type="text/plain"
) )
assert write_result["status_code"] in [200, 201, 204] # Success codes assert write_result["status_code"] in [200, 201, 204] # Success codes
logger.info(f"Wrote file: {test_file}") logger.info(f"Wrote file: {test_file}")
# Read file back # Read file back
content, content_type = await nc_client.webdav.read_file(test_file) content, content_type = await nc_client.webdav.read_file(test_file)
assert content.decode('utf-8') == test_content assert content.decode("utf-8") == test_content
assert content_type == "text/plain" assert content_type == "text/plain"
logger.info(f"Read file: {test_file}") logger.info(f"Read file: {test_file}")
# Verify file appears in directory listing # Verify file appears in directory listing
listing = await nc_client.webdav.list_directory(test_base_path) listing = await nc_client.webdav.list_directory(test_base_path)
file_names = [item["name"] for item in listing] file_names = [item["name"] for item in listing]
assert "test_file.txt" in file_names assert "test_file.txt" in file_names
# Delete file # Delete file
delete_result = await nc_client.webdav.delete_resource(test_file) delete_result = await nc_client.webdav.delete_resource(test_file)
assert delete_result["status_code"] in [204, 404] # No Content or Not Found assert delete_result["status_code"] in [204, 404] # No Content or Not Found
logger.info(f"Deleted file: {test_file}") logger.info(f"Deleted file: {test_file}")
finally: finally:
# Cleanup # Cleanup
try: try:
@@ -91,43 +91,43 @@ async def test_write_read_delete_file(nc_client: NextcloudClient, test_base_path
pass pass
async def test_list_directory_empty_and_populated(nc_client: NextcloudClient, test_base_path: str): async def test_list_directory_empty_and_populated(
nc_client: NextcloudClient, test_base_path: str
):
"""Test listing empty and populated directories.""" """Test listing empty and populated directories."""
try: try:
# Create base directory # Create base directory
await nc_client.webdav.create_directory(test_base_path) await nc_client.webdav.create_directory(test_base_path)
# List empty directory # List empty directory
empty_listing = await nc_client.webdav.list_directory(test_base_path) empty_listing = await nc_client.webdav.list_directory(test_base_path)
assert isinstance(empty_listing, list) assert isinstance(empty_listing, list)
assert len(empty_listing) == 0 assert len(empty_listing) == 0
logger.info(f"Empty directory listing: {len(empty_listing)} items") logger.info(f"Empty directory listing: {len(empty_listing)} items")
# Add some files and directories # Add some files and directories
await nc_client.webdav.create_directory(f"{test_base_path}/subdir1") await nc_client.webdav.create_directory(f"{test_base_path}/subdir1")
await nc_client.webdav.create_directory(f"{test_base_path}/subdir2") await nc_client.webdav.create_directory(f"{test_base_path}/subdir2")
await nc_client.webdav.write_file( await nc_client.webdav.write_file(
f"{test_base_path}/file1.txt", f"{test_base_path}/file1.txt", b"content1", content_type="text/plain"
b"content1",
content_type="text/plain"
) )
await nc_client.webdav.write_file( await nc_client.webdav.write_file(
f"{test_base_path}/file2.md", f"{test_base_path}/file2.md",
b"# Markdown content", b"# Markdown content",
content_type="text/markdown" content_type="text/markdown",
) )
# List populated directory # List populated directory
populated_listing = await nc_client.webdav.list_directory(test_base_path) populated_listing = await nc_client.webdav.list_directory(test_base_path)
assert len(populated_listing) == 4 # 2 dirs + 2 files assert len(populated_listing) == 4 # 2 dirs + 2 files
# Check that we have both files and directories # Check that we have both files and directories
names = [item["name"] for item in populated_listing] names = [item["name"] for item in populated_listing]
assert "subdir1" in names assert "subdir1" in names
assert "subdir2" in names assert "subdir2" in names
assert "file1.txt" in names assert "file1.txt" in names
assert "file2.md" in names assert "file2.md" in names
# Check metadata is present # Check metadata is present
for item in populated_listing: for item in populated_listing:
assert "name" in item assert "name" in item
@@ -136,9 +136,9 @@ async def test_list_directory_empty_and_populated(nc_client: NextcloudClient, te
assert "size" in item assert "size" in item
assert "content_type" in item assert "content_type" in item
assert "last_modified" in item assert "last_modified" in item
logger.info(f"Populated directory listing: {len(populated_listing)} items") logger.info(f"Populated directory listing: {len(populated_listing)} items")
finally: finally:
# Cleanup # Cleanup
try: try:
@@ -154,10 +154,10 @@ async def test_list_directory_empty_and_populated(nc_client: NextcloudClient, te
async def test_read_nonexistent_file(nc_client: NextcloudClient): async def test_read_nonexistent_file(nc_client: NextcloudClient):
"""Test reading a file that doesn't exist.""" """Test reading a file that doesn't exist."""
nonexistent_file = f"nonexistent_{uuid.uuid4().hex}.txt" nonexistent_file = f"nonexistent_{uuid.uuid4().hex}.txt"
with pytest.raises(HTTPStatusError) as exc_info: with pytest.raises(HTTPStatusError) as exc_info:
await nc_client.webdav.read_file(nonexistent_file) await nc_client.webdav.read_file(nonexistent_file)
assert exc_info.value.response.status_code == 404 assert exc_info.value.response.status_code == 404
logger.info(f"Correctly got 404 for nonexistent file: {nonexistent_file}") logger.info(f"Correctly got 404 for nonexistent file: {nonexistent_file}")
@@ -165,34 +165,40 @@ async def test_read_nonexistent_file(nc_client: NextcloudClient):
async def test_delete_nonexistent_resource(nc_client: NextcloudClient): async def test_delete_nonexistent_resource(nc_client: NextcloudClient):
"""Test deleting a resource that doesn't exist.""" """Test deleting a resource that doesn't exist."""
nonexistent_resource = f"nonexistent_{uuid.uuid4().hex}" nonexistent_resource = f"nonexistent_{uuid.uuid4().hex}"
result = await nc_client.webdav.delete_resource(nonexistent_resource) result = await nc_client.webdav.delete_resource(nonexistent_resource)
assert result["status_code"] == 404 assert result["status_code"] == 404
logger.info(f"Correctly got 404 for nonexistent resource: {nonexistent_resource}") logger.info(f"Correctly got 404 for nonexistent resource: {nonexistent_resource}")
async def test_create_nested_directories(nc_client: NextcloudClient, test_base_path: str): async def test_create_nested_directories(
nc_client: NextcloudClient, test_base_path: str
):
"""Test creating nested directory structures.""" """Test creating nested directory structures."""
nested_path = f"{test_base_path}/level1/level2/level3" nested_path = f"{test_base_path}/level1/level2/level3"
try: try:
# Create nested directories (should create parent directories automatically) # Create nested directories (should create parent directories automatically)
result = await nc_client.webdav.create_directory(nested_path) result = await nc_client.webdav.create_directory(nested_path)
assert result["status_code"] == 201 assert result["status_code"] == 201
# Verify the structure was created # Verify the structure was created
level1_listing = await nc_client.webdav.list_directory(f"{test_base_path}/level1") level1_listing = await nc_client.webdav.list_directory(
f"{test_base_path}/level1"
)
assert len(level1_listing) == 1 assert len(level1_listing) == 1
assert level1_listing[0]["name"] == "level2" assert level1_listing[0]["name"] == "level2"
assert level1_listing[0]["is_directory"] is True assert level1_listing[0]["is_directory"] is True
level2_listing = await nc_client.webdav.list_directory(f"{test_base_path}/level1/level2") level2_listing = await nc_client.webdav.list_directory(
f"{test_base_path}/level1/level2"
)
assert len(level2_listing) == 1 assert len(level2_listing) == 1
assert level2_listing[0]["name"] == "level3" assert level2_listing[0]["name"] == "level3"
assert level2_listing[0]["is_directory"] is True assert level2_listing[0]["is_directory"] is True
logger.info(f"Created nested directory structure: {nested_path}") logger.info(f"Created nested directory structure: {nested_path}")
finally: finally:
# Cleanup - delete from deepest to shallowest # Cleanup - delete from deepest to shallowest
try: try:
@@ -209,36 +215,32 @@ async def test_overwrite_existing_file(nc_client: NextcloudClient, test_base_pat
test_file = f"{test_base_path}/overwrite_test.txt" test_file = f"{test_base_path}/overwrite_test.txt"
original_content = "Original content" original_content = "Original content"
new_content = "New content after overwrite" new_content = "New content after overwrite"
try: try:
# Create base directory # Create base directory
await nc_client.webdav.create_directory(test_base_path) await nc_client.webdav.create_directory(test_base_path)
# Write original file # Write original file
await nc_client.webdav.write_file( await nc_client.webdav.write_file(
test_file, test_file, original_content.encode("utf-8"), content_type="text/plain"
original_content.encode('utf-8'),
content_type="text/plain"
) )
# Verify original content # Verify original content
content, _ = await nc_client.webdav.read_file(test_file) content, _ = await nc_client.webdav.read_file(test_file)
assert content.decode('utf-8') == original_content assert content.decode("utf-8") == original_content
# Overwrite with new content # Overwrite with new content
overwrite_result = await nc_client.webdav.write_file( overwrite_result = await nc_client.webdav.write_file(
test_file, test_file, new_content.encode("utf-8"), content_type="text/plain"
new_content.encode('utf-8'),
content_type="text/plain"
) )
assert overwrite_result["status_code"] in [200, 204] # OK or No Content assert overwrite_result["status_code"] in [200, 204] # OK or No Content
# Verify new content # Verify new content
content, _ = await nc_client.webdav.read_file(test_file) content, _ = await nc_client.webdav.read_file(test_file)
assert content.decode('utf-8') == new_content assert content.decode("utf-8") == new_content
logger.info(f"Successfully overwrote file: {test_file}") logger.info(f"Successfully overwrote file: {test_file}")
finally: finally:
# Cleanup # Cleanup
try: try:
@@ -251,12 +253,12 @@ async def test_overwrite_existing_file(nc_client: NextcloudClient, test_base_pat
async def test_list_root_directory(nc_client: NextcloudClient): async def test_list_root_directory(nc_client: NextcloudClient):
"""Test listing the root directory.""" """Test listing the root directory."""
root_listing = await nc_client.webdav.list_directory("") root_listing = await nc_client.webdav.list_directory("")
# Root directory should exist and be listable # Root directory should exist and be listable
assert isinstance(root_listing, list) assert isinstance(root_listing, list)
# Should have at least some default folders/files # Should have at least some default folders/files
assert len(root_listing) >= 0 assert len(root_listing) >= 0
# Check structure of items # Check structure of items
for item in root_listing: for item in root_listing:
assert "name" in item assert "name" in item
@@ -265,5 +267,5 @@ async def test_list_root_directory(nc_client: NextcloudClient):
assert "size" in item assert "size" in item
assert "content_type" in item assert "content_type" in item
assert "last_modified" in item assert "last_modified" in item
logger.info(f"Root directory contains {len(root_listing)} items") logger.info(f"Root directory contains {len(root_listing)} items")