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:
@@ -11,15 +11,14 @@ Tests cover:
|
||||
- Edge cases and error handling
|
||||
"""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock, AsyncMock, MagicMock, patch
|
||||
from fastapi import Request
|
||||
|
||||
from middleware.theme_context import (
|
||||
ThemeContextManager,
|
||||
ThemeContextMiddleware,
|
||||
get_current_theme,
|
||||
)
|
||||
from middleware.theme_context import (ThemeContextManager,
|
||||
ThemeContextMiddleware,
|
||||
get_current_theme)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -42,7 +41,14 @@ class TestThemeContextManager:
|
||||
"""Test default theme has all required colors."""
|
||||
theme = ThemeContextManager.get_default_theme()
|
||||
|
||||
required_colors = ["primary", "secondary", "accent", "background", "text", "border"]
|
||||
required_colors = [
|
||||
"primary",
|
||||
"secondary",
|
||||
"accent",
|
||||
"background",
|
||||
"text",
|
||||
"border",
|
||||
]
|
||||
for color in required_colors:
|
||||
assert color in theme["colors"]
|
||||
assert theme["colors"][color].startswith("#")
|
||||
@@ -79,10 +85,7 @@ class TestThemeContextManager:
|
||||
mock_theme = Mock()
|
||||
|
||||
# Mock to_dict to return actual dictionary
|
||||
custom_theme_dict = {
|
||||
"theme_name": "custom",
|
||||
"colors": {"primary": "#ff0000"}
|
||||
}
|
||||
custom_theme_dict = {"theme_name": "custom", "colors": {"primary": "#ff0000"}}
|
||||
mock_theme.to_dict.return_value = custom_theme_dict
|
||||
|
||||
# Correct filter chain: query().filter().first()
|
||||
@@ -141,8 +144,11 @@ class TestThemeContextMiddleware:
|
||||
mock_db = MagicMock()
|
||||
mock_theme = {"theme_name": "test_theme"}
|
||||
|
||||
with patch('middleware.theme_context.get_db', return_value=iter([mock_db])), \
|
||||
patch.object(ThemeContextManager, 'get_vendor_theme', return_value=mock_theme):
|
||||
with patch(
|
||||
"middleware.theme_context.get_db", return_value=iter([mock_db])
|
||||
), patch.object(
|
||||
ThemeContextManager, "get_vendor_theme", return_value=mock_theme
|
||||
):
|
||||
|
||||
await middleware.dispatch(request, call_next)
|
||||
|
||||
@@ -161,7 +167,7 @@ class TestThemeContextMiddleware:
|
||||
|
||||
await middleware.dispatch(request, call_next)
|
||||
|
||||
assert hasattr(request.state, 'theme')
|
||||
assert hasattr(request.state, "theme")
|
||||
assert request.state.theme["theme_name"] == "default"
|
||||
call_next.assert_called_once()
|
||||
|
||||
@@ -178,8 +184,11 @@ class TestThemeContextMiddleware:
|
||||
|
||||
mock_db = MagicMock()
|
||||
|
||||
with patch('middleware.theme_context.get_db', return_value=iter([mock_db])), \
|
||||
patch.object(ThemeContextManager, 'get_vendor_theme', side_effect=Exception("DB Error")):
|
||||
with patch(
|
||||
"middleware.theme_context.get_db", return_value=iter([mock_db])
|
||||
), patch.object(
|
||||
ThemeContextManager, "get_vendor_theme", side_effect=Exception("DB Error")
|
||||
):
|
||||
|
||||
await middleware.dispatch(request, call_next)
|
||||
|
||||
@@ -224,7 +233,7 @@ class TestThemeEdgeCases:
|
||||
|
||||
mock_db = MagicMock()
|
||||
|
||||
with patch('middleware.theme_context.get_db', return_value=iter([mock_db])):
|
||||
with patch("middleware.theme_context.get_db", return_value=iter([mock_db])):
|
||||
await middleware.dispatch(request, call_next)
|
||||
|
||||
# Verify database was closed
|
||||
|
||||
Reference in New Issue
Block a user