fix: resolve all Ruff linting errors
- Fix PLW2901: Use different variable name for stripped lines in loop - Fix E721: Use 'is' instead of '==' for type comparisons - Add noqa comments for intentional security warnings (S321, S507, S110, S603) Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -12,9 +12,6 @@ from app.tasks.check_credentials import (
|
||||
get_failure_state,
|
||||
save_failure_state,
|
||||
sync_test_azure_connection,
|
||||
sync_test_dropbox_token,
|
||||
sync_test_google_drive_token,
|
||||
sync_test_onedrive_token,
|
||||
sync_test_openai_connection,
|
||||
unwrap_decorated_function,
|
||||
)
|
||||
|
||||
@@ -449,7 +449,7 @@ class TestFullInfrastructure:
|
||||
|
||||
# Create SFTP client
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # noqa: S507
|
||||
|
||||
# Connect to SFTP server
|
||||
ssh.connect(
|
||||
|
||||
@@ -207,9 +207,10 @@ class TestSecurityHeadersMiddleware:
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_adds_headers_when_enabled(self):
|
||||
"""Test dispatch adds security headers when enabled."""
|
||||
from fastapi import Response
|
||||
|
||||
from app.config import settings
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
if not settings.security_headers_enabled:
|
||||
pytest.skip("Security headers disabled in configuration")
|
||||
@@ -231,10 +232,10 @@ class TestSecurityHeadersMiddleware:
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_skips_headers_when_disabled(self):
|
||||
"""Test dispatch skips headers when disabled."""
|
||||
from app.config import settings
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
# Create a config copy with headers disabled
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = False
|
||||
@@ -254,9 +255,10 @@ class TestSecurityHeadersMiddleware:
|
||||
|
||||
def test_add_security_headers_hsts(self):
|
||||
"""Test _add_security_headers adds HSTS header."""
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = True
|
||||
mock_config.security_header_hsts_enabled = True
|
||||
@@ -275,9 +277,10 @@ class TestSecurityHeadersMiddleware:
|
||||
|
||||
def test_add_security_headers_csp(self):
|
||||
"""Test _add_security_headers adds CSP header."""
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = True
|
||||
mock_config.security_header_hsts_enabled = False
|
||||
@@ -296,9 +299,10 @@ class TestSecurityHeadersMiddleware:
|
||||
|
||||
def test_add_security_headers_x_frame_options(self):
|
||||
"""Test _add_security_headers adds X-Frame-Options header."""
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = True
|
||||
mock_config.security_header_hsts_enabled = False
|
||||
@@ -317,9 +321,10 @@ class TestSecurityHeadersMiddleware:
|
||||
|
||||
def test_add_security_headers_x_content_type_options(self):
|
||||
"""Test _add_security_headers adds X-Content-Type-Options header."""
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = True
|
||||
mock_config.security_header_hsts_enabled = False
|
||||
@@ -337,9 +342,10 @@ class TestSecurityHeadersMiddleware:
|
||||
|
||||
def test_add_all_security_headers(self):
|
||||
"""Test _add_security_headers adds all headers when all enabled."""
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
from fastapi import Response
|
||||
|
||||
from app.middleware.security_headers import SecurityHeadersMiddleware
|
||||
|
||||
mock_config = Mock()
|
||||
mock_config.security_headers_enabled = True
|
||||
mock_config.security_header_hsts_enabled = True
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"""Tests for app/tasks/upload_to_email.py module."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import smtplib
|
||||
import socket
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, Mock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Additional tests for upload_to_ftp task."""
|
||||
|
||||
import ftplib
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -152,7 +152,7 @@ class TestUploadToFtp:
|
||||
mock_settings.ftp_use_tls = True
|
||||
|
||||
mock_ftp = Mock()
|
||||
mock_ftp.cwd.side_effect = [ftplib.error_perm("No such directory"), None]
|
||||
mock_ftp.cwd.side_effect = [ftplib.error_perm("No such directory"), None] # noqa: S321
|
||||
mock_ftp_tls.return_value = mock_ftp
|
||||
|
||||
mock_self = Mock()
|
||||
@@ -248,8 +248,8 @@ class TestUploadToFtp:
|
||||
mock_settings.ftp_use_tls = True
|
||||
|
||||
mock_ftp = Mock()
|
||||
mock_ftp.cwd.side_effect = ftplib.error_perm("Permission denied")
|
||||
mock_ftp.mkd.side_effect = ftplib.error_perm("Cannot create directory")
|
||||
mock_ftp.cwd.side_effect = ftplib.error_perm("Permission denied") # noqa: S321
|
||||
mock_ftp.mkd.side_effect = ftplib.error_perm("Cannot create directory") # noqa: S321
|
||||
mock_ftp_tls.return_value = mock_ftp
|
||||
|
||||
mock_self = Mock()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for app/tasks/upload_to_google_drive.py module."""
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock, Mock, mock_open, patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
from google.auth.exceptions import RefreshError
|
||||
|
||||
@@ -240,7 +240,6 @@ class TestContainerInfoDetection:
|
||||
@patch("builtins.open", new_callable=mock_open, read_data="12:docker:/abc123456789")
|
||||
def test_extracts_container_id(self, mock_file, mock_exists):
|
||||
"""Test extracts container ID from cgroup."""
|
||||
from app.views.status import status_dashboard
|
||||
|
||||
mock_exists.return_value = True
|
||||
|
||||
@@ -250,7 +249,6 @@ class TestContainerInfoDetection:
|
||||
@patch("app.views.status.os.path.exists")
|
||||
def test_handles_missing_cgroup_file(self, mock_exists):
|
||||
"""Test handles missing cgroup file gracefully."""
|
||||
from app.views.status import status_dashboard
|
||||
|
||||
mock_exists.side_effect = [True, False] # Docker env exists, but cgroup doesn't
|
||||
|
||||
@@ -259,7 +257,6 @@ class TestContainerInfoDetection:
|
||||
@patch("app.views.status.settings")
|
||||
def test_includes_runtime_info_when_available(self, mock_settings):
|
||||
"""Test includes runtime info when available."""
|
||||
from app.views.status import status_dashboard
|
||||
|
||||
mock_settings.runtime_info = "Python 3.11.5 on Linux"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user