style: apply black and isort formatting across entire codebase

- Standardize quote style (single to double quotes)
- Reorder and group imports alphabetically
- Fix line breaks and indentation for consistency
- Apply PEP 8 formatting standards

Also updated Makefile to exclude both venv and .venv from code quality checks.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 19:30:17 +01:00
parent 13f0094743
commit 21c13ca39b
236 changed files with 8450 additions and 6545 deletions

View File

@@ -11,9 +11,10 @@ Tests cover:
- Edge cases (missing client info, etc.)
"""
import pytest
import asyncio
from unittest.mock import Mock, AsyncMock, patch
from unittest.mock import AsyncMock, Mock, patch
import pytest
from fastapi import Request
from middleware.logging import LoggingMiddleware
@@ -40,7 +41,7 @@ class TestLoggingMiddleware:
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger') as mock_logger:
with patch("middleware.logging.logger") as mock_logger:
await middleware.dispatch(request, call_next)
# Verify request was logged
@@ -65,7 +66,7 @@ class TestLoggingMiddleware:
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger') as mock_logger:
with patch("middleware.logging.logger") as mock_logger:
result = await middleware.dispatch(request, call_next)
# Verify response was logged
@@ -89,7 +90,7 @@ class TestLoggingMiddleware:
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger'):
with patch("middleware.logging.logger"):
result = await middleware.dispatch(request, call_next)
assert "X-Process-Time" in response.headers
@@ -113,11 +114,13 @@ class TestLoggingMiddleware:
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger') as mock_logger:
with patch("middleware.logging.logger") as mock_logger:
await middleware.dispatch(request, call_next)
# Should log "unknown" for client
assert any("unknown" in str(call) for call in mock_logger.info.call_args_list)
assert any(
"unknown" in str(call) for call in mock_logger.info.call_args_list
)
@pytest.mark.asyncio
async def test_middleware_logs_exceptions(self):
@@ -131,8 +134,9 @@ class TestLoggingMiddleware:
call_next = AsyncMock(side_effect=Exception("Test error"))
with patch('middleware.logging.logger') as mock_logger, \
pytest.raises(Exception):
with patch("middleware.logging.logger") as mock_logger, pytest.raises(
Exception
):
await middleware.dispatch(request, call_next)
# Verify error was logged
@@ -156,7 +160,7 @@ class TestLoggingMiddleware:
call_next = slow_call_next
with patch('middleware.logging.logger'):
with patch("middleware.logging.logger"):
result = await middleware.dispatch(request, call_next)
process_time = float(result.headers["X-Process-Time"])
@@ -181,7 +185,7 @@ class TestLoggingEdgeCases:
response = Mock(status_code=200, headers={})
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger'):
with patch("middleware.logging.logger"):
result = await middleware.dispatch(request, call_next)
# Should still have process time, even if very small
@@ -205,11 +209,13 @@ class TestLoggingEdgeCases:
response = Mock(status_code=200, headers={})
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger') as mock_logger:
with patch("middleware.logging.logger") as mock_logger:
await middleware.dispatch(request, call_next)
# Verify method was logged
assert any(method in str(call) for call in mock_logger.info.call_args_list)
assert any(
method in str(call) for call in mock_logger.info.call_args_list
)
@pytest.mark.asyncio
async def test_middleware_logs_different_status_codes(self):
@@ -227,8 +233,11 @@ class TestLoggingEdgeCases:
response = Mock(status_code=status_code, headers={})
call_next = AsyncMock(return_value=response)
with patch('middleware.logging.logger') as mock_logger:
with patch("middleware.logging.logger") as mock_logger:
await middleware.dispatch(request, call_next)
# Verify status code was logged
assert any(str(status_code) in str(call) for call in mock_logger.info.call_args_list)
assert any(
str(status_code) in str(call)
for call in mock_logger.info.call_args_list
)