Initial commit: WealthWise financial analytics platform
This commit is contained in:
55
backend/tests/test_config.py
Normal file
55
backend/tests/test_config.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Tests for core configuration module."""
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.config import Settings, get_settings
|
||||
|
||||
|
||||
class TestSettings:
|
||||
"""Test cases for Settings configuration."""
|
||||
|
||||
def test_default_values(self):
|
||||
"""Test that default values are set correctly."""
|
||||
settings = Settings()
|
||||
|
||||
assert settings.PROJECT_NAME == "WealthWise"
|
||||
assert settings.API_V1_STR == "/api/v1"
|
||||
assert settings.VERSION == "1.0.0"
|
||||
assert settings.DB_POOL_SIZE == 20
|
||||
assert settings.DB_MAX_OVERFLOW == 10
|
||||
assert settings.DEBUG is False
|
||||
|
||||
def test_database_url_validation(self):
|
||||
"""Test that database URL is validated and converted to asyncpg."""
|
||||
# Test conversion from postgresql:// to postgresql+asyncpg://
|
||||
settings = Settings(DATABASE_URL="postgresql://user:pass@localhost:5432/db")
|
||||
assert settings.DATABASE_URL.startswith("postgresql+asyncpg://")
|
||||
|
||||
# Test that asyncpg URL is preserved
|
||||
asyncpg_url = "postgresql+asyncpg://user:pass@localhost:6543/postgres"
|
||||
settings2 = Settings(DATABASE_URL=asyncpg_url)
|
||||
assert settings2.DATABASE_URL == asyncpg_url
|
||||
|
||||
def test_cors_origins_parsing(self):
|
||||
"""Test CORS origins parsing from string."""
|
||||
settings = Settings(CORS_ORIGINS="http://localhost:5173,https://example.com")
|
||||
assert "http://localhost:5173" in settings.CORS_ORIGINS
|
||||
assert "https://example.com" in settings.CORS_ORIGINS
|
||||
|
||||
# Test list input
|
||||
settings2 = Settings(CORS_ORIGINS=["http://localhost:3000"])
|
||||
assert settings2.CORS_ORIGINS == ["http://localhost:3000"]
|
||||
|
||||
|
||||
class TestGetSettings:
|
||||
"""Test cases for get_settings function."""
|
||||
|
||||
def test_get_settings_returns_singleton(self):
|
||||
"""Test that get_settings returns a cached singleton."""
|
||||
settings1 = get_settings()
|
||||
settings2 = get_settings()
|
||||
|
||||
# Should be the same object (cached)
|
||||
assert settings1 is settings2
|
||||
Reference in New Issue
Block a user