fix: resolve DeepSource issues in test files
- Use lazy % formatting in logging (PYL-W1203) in test_external_integrations.py - Add @staticmethod to 3 methods not using self (PYL-R0201) - Remove unused mock_media and mock_smtp variables (PYL-W0612) - Remove redundant local reimports of upload_to_webdav (PYL-W0404) Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -323,7 +323,7 @@ class TestS3Integration:
|
|||||||
try:
|
try:
|
||||||
s3_client.delete_object(Bucket=bucket, Key=s3_key)
|
s3_client.delete_object(Bucket=bucket, Key=s3_key)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"Failed to clean up S3 test object {s3_key}: {exc}")
|
logger.warning("Failed to clean up S3 test object %s: %s", s3_key, exc)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -383,7 +383,7 @@ class TestDropboxIntegration:
|
|||||||
try:
|
try:
|
||||||
dbx.files_delete_v2(remote_path)
|
dbx.files_delete_v2(remote_path)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"Failed to clean up Dropbox test file {remote_path}: {exc}")
|
logger.warning("Failed to clean up Dropbox test file %s: %s", remote_path, exc)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -474,7 +474,7 @@ class TestOneDriveIntegration:
|
|||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"Failed to clean up OneDrive test file {filename}: {exc}")
|
logger.warning("Failed to clean up OneDrive test file %s: %s", filename, exc)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -488,7 +488,8 @@ class TestOneDriveIntegration:
|
|||||||
class TestAuthentikIntegration:
|
class TestAuthentikIntegration:
|
||||||
"""Verify Authentik / OpenID Connect discovery endpoint is reachable."""
|
"""Verify Authentik / OpenID Connect discovery endpoint is reachable."""
|
||||||
|
|
||||||
def test_oidc_discovery_endpoint(self, original_env: dict) -> None:
|
@staticmethod
|
||||||
|
def test_oidc_discovery_endpoint(original_env: dict) -> None:
|
||||||
"""Validate that the OIDC discovery URL returns a valid JSON document."""
|
"""Validate that the OIDC discovery URL returns a valid JSON document."""
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@@ -502,7 +503,8 @@ class TestAuthentikIntegration:
|
|||||||
assert "authorization_endpoint" in data, "OIDC response missing 'authorization_endpoint'"
|
assert "authorization_endpoint" in data, "OIDC response missing 'authorization_endpoint'"
|
||||||
assert "token_endpoint" in data, "OIDC response missing 'token_endpoint'"
|
assert "token_endpoint" in data, "OIDC response missing 'token_endpoint'"
|
||||||
|
|
||||||
def test_authentik_client_credentials_present(self, original_env: dict) -> None:
|
@staticmethod
|
||||||
|
def test_authentik_client_credentials_present(original_env: dict) -> None:
|
||||||
"""Validate that Authentik client credentials are configured alongside the config URL."""
|
"""Validate that Authentik client credentials are configured alongside the config URL."""
|
||||||
client_id = original_env.get("AUTHENTIK_CLIENT_ID")
|
client_id = original_env.get("AUTHENTIK_CLIENT_ID")
|
||||||
client_secret = original_env.get("AUTHENTIK_CLIENT_SECRET")
|
client_secret = original_env.get("AUTHENTIK_CLIENT_SECRET")
|
||||||
@@ -529,7 +531,8 @@ class TestFullOCRMetadataPipeline:
|
|||||||
Celery or Redis, by calling the service APIs directly.
|
Celery or Redis, by calling the service APIs directly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_ocr_then_metadata_extraction(self, original_env: dict) -> None:
|
@staticmethod
|
||||||
|
def test_ocr_then_metadata_extraction(original_env: dict) -> None:
|
||||||
"""Generate a PDF, OCR it with Azure, then extract metadata with OpenAI."""
|
"""Generate a PDF, OCR it with Azure, then extract metadata with OpenAI."""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ def test_upload_to_google_drive_accepts_file_id(sample_text_file):
|
|||||||
"""Test that upload_to_google_drive accepts file_id parameter."""
|
"""Test that upload_to_google_drive accepts file_id parameter."""
|
||||||
with (
|
with (
|
||||||
patch("app.tasks.upload_to_google_drive.get_google_drive_service") as mock_service,
|
patch("app.tasks.upload_to_google_drive.get_google_drive_service") as mock_service,
|
||||||
patch("app.tasks.upload_to_google_drive.MediaFileUpload") as mock_media,
|
patch("app.tasks.upload_to_google_drive.MediaFileUpload"),
|
||||||
patch("app.tasks.upload_to_google_drive.extract_metadata_from_file") as mock_metadata,
|
patch("app.tasks.upload_to_google_drive.extract_metadata_from_file") as mock_metadata,
|
||||||
patch("app.tasks.upload_to_google_drive.settings") as mock_settings,
|
patch("app.tasks.upload_to_google_drive.settings") as mock_settings,
|
||||||
patch("app.tasks.upload_to_google_drive.log_task_progress"),
|
patch("app.tasks.upload_to_google_drive.log_task_progress"),
|
||||||
@@ -364,7 +364,7 @@ def test_upload_to_email_accepts_file_id(sample_text_file):
|
|||||||
"""Test that upload_to_email accepts file_id parameter."""
|
"""Test that upload_to_email accepts file_id parameter."""
|
||||||
with (
|
with (
|
||||||
patch("app.tasks.upload_to_email.settings") as mock_settings,
|
patch("app.tasks.upload_to_email.settings") as mock_settings,
|
||||||
patch("app.tasks.upload_to_email.smtplib.SMTP") as mock_smtp,
|
patch("app.tasks.upload_to_email.smtplib.SMTP"),
|
||||||
patch("app.tasks.upload_to_email.get_email_template") as mock_template,
|
patch("app.tasks.upload_to_email.get_email_template") as mock_template,
|
||||||
patch("app.tasks.upload_to_email.extract_metadata_from_file") as mock_metadata,
|
patch("app.tasks.upload_to_email.extract_metadata_from_file") as mock_metadata,
|
||||||
patch("app.tasks.upload_to_email.log_task_progress"),
|
patch("app.tasks.upload_to_email.log_task_progress"),
|
||||||
|
|||||||
@@ -532,14 +532,10 @@ class TestUploadToWebDAV:
|
|||||||
|
|
||||||
def test_module_importable(self):
|
def test_module_importable(self):
|
||||||
"""Test that upload_to_webdav module is importable."""
|
"""Test that upload_to_webdav module is importable."""
|
||||||
from app.tasks.upload_to_webdav import upload_to_webdav
|
|
||||||
|
|
||||||
assert callable(upload_to_webdav)
|
assert callable(upload_to_webdav)
|
||||||
|
|
||||||
def test_task_has_retry_configuration(self):
|
def test_task_has_retry_configuration(self):
|
||||||
"""Test that the task has retry configuration from BaseTaskWithRetry."""
|
"""Test that the task has retry configuration from BaseTaskWithRetry."""
|
||||||
from app.tasks.upload_to_webdav import upload_to_webdav
|
|
||||||
|
|
||||||
# BaseTaskWithRetry should provide retry configuration
|
# BaseTaskWithRetry should provide retry configuration
|
||||||
assert hasattr(upload_to_webdav, "max_retries")
|
assert hasattr(upload_to_webdav, "max_retries")
|
||||||
# BaseTaskWithRetry configures 3 retries
|
# BaseTaskWithRetry configures 3 retries
|
||||||
|
|||||||
Reference in New Issue
Block a user