bcbef88803
- Add backend/conftest.py that inserts the backend directory into sys.path, fixing ModuleNotFoundError when pytest runs from the backend/ directory (as CI does with `cd backend && pytest tests/`) - Run black formatter on all 28 backend files that needed reformatting - All 53 tests pass with both `pytest tests/` and `python -m pytest tests/` Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/pop_puller_to_gmail/sessions/beb47db2-da25-416a-8fb0-c1452a3b22a7
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
"""
|
|
Unit tests for configuration module.
|
|
"""
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from app.core.config import Settings
|
|
|
|
|
|
class TestConfigValidation:
|
|
"""Test configuration validation"""
|
|
|
|
def test_default_secret_key_rejected(self):
|
|
"""Test that default SECRET_KEY is rejected"""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
Settings(
|
|
SECRET_KEY="change-this-to-a-secure-random-secret-key-in-production",
|
|
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-testing",
|
|
)
|
|
|
|
assert "SECRET_KEY must be changed from default" in str(exc_info.value)
|
|
|
|
def test_short_secret_key_rejected(self):
|
|
"""Test that short SECRET_KEY is rejected"""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
Settings(
|
|
SECRET_KEY="short",
|
|
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-testing",
|
|
)
|
|
|
|
assert "at least 32 characters" in str(exc_info.value)
|
|
|
|
def test_default_encryption_key_rejected(self):
|
|
"""Test that default ENCRYPTION_KEY is rejected"""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
Settings(
|
|
SECRET_KEY="this-is-a-secure-32-character-key-for-testing",
|
|
ENCRYPTION_KEY="change-this-to-a-secure-encryption-key",
|
|
)
|
|
|
|
assert "ENCRYPTION_KEY must be changed from default" in str(exc_info.value)
|
|
|
|
def test_short_encryption_key_rejected(self):
|
|
"""Test that short ENCRYPTION_KEY is rejected"""
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
Settings(
|
|
SECRET_KEY="this-is-a-secure-32-character-key-for-testing",
|
|
ENCRYPTION_KEY="short",
|
|
)
|
|
|
|
assert "at least 32 characters" in str(exc_info.value)
|
|
|
|
def test_valid_keys_accepted(self):
|
|
"""Test that valid keys are accepted"""
|
|
settings = Settings(
|
|
SECRET_KEY="this-is-a-secure-32-character-key-for-testing-secret",
|
|
ENCRYPTION_KEY="this-is-a-secure-32-character-key-for-encryption",
|
|
)
|
|
|
|
assert (
|
|
settings.SECRET_KEY
|
|
== "this-is-a-secure-32-character-key-for-testing-secret"
|
|
)
|
|
assert (
|
|
settings.ENCRYPTION_KEY
|
|
== "this-is-a-secure-32-character-key-for-encryption"
|
|
)
|