fix: apply ruff formatting to 6 test files
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -110,7 +110,9 @@ class TestAzureTestConnectionEndpoint:
|
|||||||
@patch("app.api.azure.AzureKeyCredential")
|
@patch("app.api.azure.AzureKeyCredential")
|
||||||
@patch("app.api.azure.settings")
|
@patch("app.api.azure.settings")
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_azure_connection_service_request_error(self, mock_settings, mock_credential, mock_admin_client_class):
|
async def test_azure_connection_service_request_error(
|
||||||
|
self, mock_settings, mock_credential, mock_admin_client_class
|
||||||
|
):
|
||||||
"""Test connection with service request error."""
|
"""Test connection with service request error."""
|
||||||
from app.api.azure import test_azure_connection
|
from app.api.azure import test_azure_connection
|
||||||
|
|
||||||
@@ -196,7 +198,9 @@ class TestAzureTestConnectionEndpoint:
|
|||||||
@patch("app.api.azure.AzureKeyCredential")
|
@patch("app.api.azure.AzureKeyCredential")
|
||||||
@patch("app.api.azure.settings")
|
@patch("app.api.azure.settings")
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_azure_connection_with_empty_operations(self, mock_settings, mock_credential, mock_admin_client_class):
|
async def test_azure_connection_with_empty_operations(
|
||||||
|
self, mock_settings, mock_credential, mock_admin_client_class
|
||||||
|
):
|
||||||
"""Test connection returning empty operations list."""
|
"""Test connection returning empty operations list."""
|
||||||
from app.api.azure import test_azure_connection
|
from app.api.azure import test_azure_connection
|
||||||
|
|
||||||
@@ -325,7 +329,9 @@ class TestAzureTestConnectionEndpoint:
|
|||||||
@patch("app.api.azure.AzureKeyCredential")
|
@patch("app.api.azure.AzureKeyCredential")
|
||||||
@patch("app.api.azure.settings")
|
@patch("app.api.azure.settings")
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_azure_connection_uses_credential(self, mock_settings, mock_credential_class, mock_admin_client_class):
|
async def test_azure_connection_uses_credential(
|
||||||
|
self, mock_settings, mock_credential_class, mock_admin_client_class
|
||||||
|
):
|
||||||
"""Test that AzureKeyCredential is used correctly."""
|
"""Test that AzureKeyCredential is used correctly."""
|
||||||
from app.api.azure import test_azure_connection
|
from app.api.azure import test_azure_connection
|
||||||
|
|
||||||
|
|||||||
@@ -244,9 +244,9 @@ class TestAzureDocumentIntelligenceIntegration:
|
|||||||
assert len(result.content) > 10, f"OCR text too short: {result.content[:50]}"
|
assert len(result.content) > 10, f"OCR text too short: {result.content[:50]}"
|
||||||
|
|
||||||
# Verify the generated text is recognizable
|
# Verify the generated text is recognizable
|
||||||
assert (
|
assert "Acme" in result.content or "Invoice" in result.content, (
|
||||||
"Acme" in result.content or "Invoice" in result.content
|
f"OCR text does not contain expected keywords: {result.content[:200]}"
|
||||||
), f"OCR text does not contain expected keywords: {result.content[:200]}"
|
)
|
||||||
|
|
||||||
# Retrieve the searchable PDF output
|
# Retrieve the searchable PDF output
|
||||||
operation_id = poller.details["operation_id"]
|
operation_id = poller.details["operation_id"]
|
||||||
@@ -602,9 +602,9 @@ class TestFullOCRMetadataPipeline:
|
|||||||
|
|
||||||
# The generated invoice should be classified reasonably
|
# The generated invoice should be classified reasonably
|
||||||
doc_type = metadata["document_type"].lower()
|
doc_type = metadata["document_type"].lower()
|
||||||
assert any(
|
assert any(kw in doc_type for kw in ("invoice", "rechnung", "bill")), (
|
||||||
kw in doc_type for kw in ("invoice", "rechnung", "bill")
|
f"Unexpected document_type: {metadata['document_type']}"
|
||||||
), f"Unexpected document_type: {metadata['document_type']}"
|
)
|
||||||
finally:
|
finally:
|
||||||
os.unlink(pdf_path)
|
os.unlink(pdf_path)
|
||||||
|
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ class TestSplitPdfBySize:
|
|||||||
# that can cause files to exceed the target size by ~20-50%. We allow 1.5x (50%) margin.
|
# that can cause files to exceed the target size by ~20-50%. We allow 1.5x (50%) margin.
|
||||||
PDF_OVERHEAD_MULTIPLIER = 1.5
|
PDF_OVERHEAD_MULTIPLIER = 1.5
|
||||||
for split_file in split_files:
|
for split_file in split_files:
|
||||||
assert (
|
assert os.path.getsize(split_file) <= max_size * PDF_OVERHEAD_MULTIPLIER, (
|
||||||
os.path.getsize(split_file) <= max_size * PDF_OVERHEAD_MULTIPLIER
|
f"Split file {split_file} should respect size limit (with PDF overhead allowance)"
|
||||||
), f"Split file {split_file} should respect size limit (with PDF overhead allowance)"
|
)
|
||||||
|
|
||||||
# Cleanup split files
|
# Cleanup split files
|
||||||
for split_file in split_files:
|
for split_file in split_files:
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ def test_x_frame_options_valid_value(client):
|
|||||||
x_frame_value = response.headers["X-Frame-Options"]
|
x_frame_value = response.headers["X-Frame-Options"]
|
||||||
valid_values = ["DENY", "SAMEORIGIN"]
|
valid_values = ["DENY", "SAMEORIGIN"]
|
||||||
# Note: ALLOW-FROM is deprecated in modern browsers; use CSP frame-ancestors instead
|
# Note: ALLOW-FROM is deprecated in modern browsers; use CSP frame-ancestors instead
|
||||||
assert x_frame_value in valid_values or x_frame_value.startswith(
|
assert x_frame_value in valid_values or x_frame_value.startswith("ALLOW-FROM"), (
|
||||||
"ALLOW-FROM"
|
f"Invalid X-Frame-Options value: {x_frame_value}"
|
||||||
), f"Invalid X-Frame-Options value: {x_frame_value}"
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ class TestUploadToFtp:
|
|||||||
@patch("app.tasks.upload_to_ftp.os.path.exists")
|
@patch("app.tasks.upload_to_ftp.os.path.exists")
|
||||||
@patch("app.tasks.upload_to_ftp.settings")
|
@patch("app.tasks.upload_to_ftp.settings")
|
||||||
@patch("builtins.open", create=True)
|
@patch("builtins.open", create=True)
|
||||||
def test_uploads_file_with_ftps(
|
def test_uploads_file_with_ftps(self, mock_open, mock_settings, mock_exists, mock_log, mock_ftp_tls, mock_basename):
|
||||||
self, mock_open, mock_settings, mock_exists, mock_log, mock_ftp_tls, mock_basename
|
|
||||||
):
|
|
||||||
"""Test uploads file using FTPS (FTP with TLS)."""
|
"""Test uploads file using FTPS (FTP with TLS)."""
|
||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
mock_basename.return_value = "test.pdf"
|
mock_basename.return_value = "test.pdf"
|
||||||
|
|||||||
@@ -305,9 +305,9 @@ class TestWebDAVIntegration:
|
|||||||
response = requests.get(file_url, auth=(webdav_server["username"], webdav_server["password"]), timeout=10)
|
response = requests.get(file_url, auth=(webdav_server["username"], webdav_server["password"]), timeout=10)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert (
|
assert len(response.content) == 1024 * 1024, (
|
||||||
len(response.content) == 1024 * 1024
|
f"File size mismatch: expected 1MB, got {len(response.content)} bytes"
|
||||||
), f"File size mismatch: expected 1MB, got {len(response.content)} bytes"
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|||||||
Reference in New Issue
Block a user