style: apply ruff auto-fix
- Auto-formatted code with ruff format - Applied ruff linting fixes with --fix Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -371,7 +371,6 @@ class TestAzureTestConnectionIntegration:
|
||||
data = response.json()
|
||||
assert "status" in data
|
||||
|
||||
|
||||
@patch("app.api.azure.settings")
|
||||
@patch("app.api.azure.logger")
|
||||
@pytest.mark.asyncio
|
||||
@@ -388,7 +387,7 @@ class TestAzureTestConnectionIntegration:
|
||||
# Verify warning was logged
|
||||
mock_logger.warning.assert_called_once()
|
||||
assert "configuration is incomplete" in mock_logger.warning.call_args[0][0].lower()
|
||||
|
||||
|
||||
assert result["status"] == "error"
|
||||
|
||||
@patch("app.api.azure.DocumentIntelligenceAdministrationClient")
|
||||
@@ -518,6 +517,7 @@ class TestAzureTestConnectionIntegration:
|
||||
async def test_azure_connection_logs_outer_exception(self, mock_logger, mock_settings):
|
||||
"""Test that exceptions in outer try block are logged with exception()."""
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
from app.api.azure import test_azure_connection
|
||||
|
||||
# Trigger an exception in the outer try block
|
||||
@@ -531,7 +531,7 @@ class TestAzureTestConnectionIntegration:
|
||||
# Should catch the exception and return error
|
||||
assert result["status"] == "error"
|
||||
assert "unexpected error" in result["message"].lower()
|
||||
|
||||
|
||||
# Verify exception was logged with logger.exception
|
||||
mock_logger.exception.assert_called_once()
|
||||
|
||||
@@ -545,6 +545,7 @@ class TestAzureTestConnectionIntegration:
|
||||
):
|
||||
"""Test that warning is logged when operations parsing fails."""
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
from app.api.azure import test_azure_connection
|
||||
|
||||
mock_settings.azure_endpoint = "https://test.cognitiveservices.azure.com/"
|
||||
@@ -575,12 +576,13 @@ class TestAzureTestConnectionIntegration:
|
||||
async def test_azure_connection_outer_exception_handler(self, mock_settings):
|
||||
"""Test the outer exception handler catches unexpected errors."""
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
from app.api.azure import test_azure_connection
|
||||
|
||||
# Create a mock that raises exception when azure_endpoint is accessed using PropertyMock
|
||||
type(mock_settings).azure_endpoint = PropertyMock(side_effect=RuntimeError("Outer error"))
|
||||
type(mock_settings).azure_ai_key = PropertyMock(return_value="test-key")
|
||||
|
||||
|
||||
mock_request = Mock()
|
||||
result = await test_azure_connection(mock_request)
|
||||
|
||||
|
||||
+31
-21
@@ -280,7 +280,7 @@ class TestTaskLogCollector:
|
||||
|
||||
collector = TaskLogCollector()
|
||||
# Don't set a formatter to trigger an edge case
|
||||
|
||||
|
||||
logger = logging.getLogger("test_exception")
|
||||
logger.addHandler(collector)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -292,7 +292,7 @@ class TestTaskLogCollector:
|
||||
# Should handle gracefully
|
||||
except Exception:
|
||||
pytest.fail("Collector should handle exceptions gracefully")
|
||||
|
||||
|
||||
logger.removeHandler(collector)
|
||||
|
||||
|
||||
@@ -313,16 +313,18 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
# Setup mocks
|
||||
mock_db = MagicMock()
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
|
||||
# No existing step record
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = None
|
||||
|
||||
|
||||
# Mock datetime
|
||||
from datetime import datetime as dt, timezone
|
||||
from datetime import datetime as dt
|
||||
from datetime import timezone
|
||||
|
||||
mock_now = dt(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
|
||||
mock_datetime.now.return_value = mock_now
|
||||
mock_datetime.timezone = timezone
|
||||
|
||||
|
||||
# Mock FileProcessingStep creation
|
||||
mock_step = Mock()
|
||||
mock_file_step.return_value = mock_step
|
||||
@@ -356,14 +358,16 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = None
|
||||
|
||||
from datetime import datetime as dt, timezone
|
||||
|
||||
from datetime import datetime as dt
|
||||
from datetime import timezone
|
||||
|
||||
mock_now = dt(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
|
||||
mock_datetime.now.return_value = mock_now
|
||||
mock_datetime.timezone = timezone
|
||||
|
||||
|
||||
mock_step = Mock()
|
||||
mock_file_step.return_value = mock_step
|
||||
|
||||
@@ -393,14 +397,16 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = None
|
||||
|
||||
from datetime import datetime as dt, timezone
|
||||
|
||||
from datetime import datetime as dt
|
||||
from datetime import timezone
|
||||
|
||||
mock_now = dt(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
|
||||
mock_datetime.now.return_value = mock_now
|
||||
mock_datetime.timezone = timezone
|
||||
|
||||
|
||||
mock_step = Mock()
|
||||
mock_file_step.return_value = mock_step
|
||||
|
||||
@@ -428,13 +434,15 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
|
||||
# Existing step without started_at
|
||||
mock_existing_step = Mock()
|
||||
mock_existing_step.started_at = None
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = mock_existing_step
|
||||
|
||||
from datetime import datetime as dt, timezone
|
||||
|
||||
from datetime import datetime as dt
|
||||
from datetime import timezone
|
||||
|
||||
mock_now = dt(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
|
||||
mock_datetime.now.return_value = mock_now
|
||||
mock_datetime.timezone = timezone
|
||||
@@ -462,12 +470,14 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_session_local.return_value.__enter__.return_value = mock_db
|
||||
|
||||
|
||||
mock_existing_step = Mock()
|
||||
mock_existing_step.started_at = None
|
||||
mock_db.query.return_value.filter.return_value.first.return_value = mock_existing_step
|
||||
|
||||
from datetime import datetime as dt, timezone
|
||||
|
||||
from datetime import datetime as dt
|
||||
from datetime import timezone
|
||||
|
||||
mock_now = dt(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
|
||||
mock_datetime.now.return_value = mock_now
|
||||
mock_datetime.timezone = timezone
|
||||
@@ -511,7 +521,7 @@ class TestLogTaskProgressWithFileProcessingStep:
|
||||
# Verify collector was used
|
||||
mock_ensure.assert_called_once()
|
||||
mock_collector.drain.assert_called_once_with("task-with-logs")
|
||||
|
||||
|
||||
# Verify detail was set from collected logs
|
||||
call_kwargs = mock_processing_log.call_args[1]
|
||||
assert call_kwargs["detail"] == "Buffered log line 1\nBuffered log line 2"
|
||||
|
||||
Reference in New Issue
Block a user