style: format test files with black and isort, remove unused imports
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
+5
-3
@@ -1,9 +1,9 @@
|
|||||||
"""Tests for app/auth.py module."""
|
"""Tests for app/auth.py module."""
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import MagicMock, AsyncMock, patch
|
|
||||||
from starlette.testclient import TestClient
|
|
||||||
from fastapi import Request, status
|
from fastapi import Request, status
|
||||||
from starlette.responses import RedirectResponse
|
from starlette.responses import RedirectResponse
|
||||||
|
|
||||||
@@ -66,6 +66,7 @@ class TestRequireLogin:
|
|||||||
|
|
||||||
def test_noop_when_auth_disabled(self):
|
def test_noop_when_auth_disabled(self):
|
||||||
"""Test that require_login is a no-op when AUTH_ENABLED is False."""
|
"""Test that require_login is a no-op when AUTH_ENABLED is False."""
|
||||||
|
|
||||||
# AUTH_ENABLED is False in test environment
|
# AUTH_ENABLED is False in test environment
|
||||||
def my_func():
|
def my_func():
|
||||||
return "hello"
|
return "hello"
|
||||||
@@ -166,6 +167,7 @@ class TestRequireLogin:
|
|||||||
|
|
||||||
# Call the decorated sync function
|
# Call the decorated sync function
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
result = asyncio.run(sync_endpoint(request=mock_request, param="test_value"))
|
result = asyncio.run(sync_endpoint(request=mock_request, param="test_value"))
|
||||||
|
|
||||||
assert result["message"] == "sync"
|
assert result["message"] == "sync"
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ Tests for app/utils/encryption.py
|
|||||||
Tests encryption/decryption functionality for sensitive settings.
|
Tests encryption/decryption functionality for sensitive settings.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import Mock, patch, MagicMock
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
@@ -205,7 +206,7 @@ class TestEncryptionIntegration:
|
|||||||
@patch("app.utils.encryption._get_cipher_suite")
|
@patch("app.utils.encryption._get_cipher_suite")
|
||||||
def test_encrypt_decrypt_cycle(self, mock_cipher):
|
def test_encrypt_decrypt_cycle(self, mock_cipher):
|
||||||
"""Test that encrypting and then decrypting returns original value"""
|
"""Test that encrypting and then decrypting returns original value"""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value
|
from app.utils.encryption import decrypt_value, encrypt_value
|
||||||
|
|
||||||
# Mock a simple reversible encryption
|
# Mock a simple reversible encryption
|
||||||
mock_fernet = Mock()
|
mock_fernet = Mock()
|
||||||
@@ -232,7 +233,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_real_encryption_round_trip(self):
|
def test_real_encryption_round_trip(self):
|
||||||
"""Test actual encryption/decryption with real cryptography library."""
|
"""Test actual encryption/decryption with real cryptography library."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
# Skip if encryption is not available
|
# Skip if encryption is not available
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
@@ -253,7 +254,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_encryption_with_special_characters(self):
|
def test_encryption_with_special_characters(self):
|
||||||
"""Test encryption with special characters and symbols."""
|
"""Test encryption with special characters and symbols."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
pytest.skip("Encryption not available")
|
pytest.skip("Encryption not available")
|
||||||
@@ -266,7 +267,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_encryption_with_unicode(self):
|
def test_encryption_with_unicode(self):
|
||||||
"""Test encryption with unicode characters."""
|
"""Test encryption with unicode characters."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
pytest.skip("Encryption not available")
|
pytest.skip("Encryption not available")
|
||||||
@@ -279,7 +280,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_encryption_with_long_string(self):
|
def test_encryption_with_long_string(self):
|
||||||
"""Test encryption with very long strings."""
|
"""Test encryption with very long strings."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
pytest.skip("Encryption not available")
|
pytest.skip("Encryption not available")
|
||||||
@@ -294,7 +295,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_encryption_with_newlines_and_whitespace(self):
|
def test_encryption_with_newlines_and_whitespace(self):
|
||||||
"""Test encryption preserves newlines and whitespace."""
|
"""Test encryption preserves newlines and whitespace."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
pytest.skip("Encryption not available")
|
pytest.skip("Encryption not available")
|
||||||
@@ -307,7 +308,7 @@ class TestEncryptionIntegration:
|
|||||||
|
|
||||||
def test_encryption_with_json_string(self):
|
def test_encryption_with_json_string(self):
|
||||||
"""Test encryption with JSON string."""
|
"""Test encryption with JSON string."""
|
||||||
from app.utils.encryption import encrypt_value, decrypt_value, is_encryption_available
|
from app.utils.encryption import decrypt_value, encrypt_value, is_encryption_available
|
||||||
|
|
||||||
if not is_encryption_available():
|
if not is_encryption_available():
|
||||||
pytest.skip("Encryption not available")
|
pytest.skip("Encryption not available")
|
||||||
@@ -337,5 +338,6 @@ class TestEncryptionIntegration:
|
|||||||
# (depending on timing). This test documents the behavior.
|
# (depending on timing). This test documents the behavior.
|
||||||
# We'll just verify both decrypt correctly
|
# We'll just verify both decrypt correctly
|
||||||
from app.utils.encryption import decrypt_value
|
from app.utils.encryption import decrypt_value
|
||||||
|
|
||||||
assert decrypt_value(encrypted1) == original
|
assert decrypt_value(encrypted1) == original
|
||||||
assert decrypt_value(encrypted2) == original
|
assert decrypt_value(encrypted2) == original
|
||||||
|
|||||||
Reference in New Issue
Block a user