test: upgrade backend test suite, implement unit tests, and modernize CRUD patterns
Build Backend / build (push) Successful in 6m39s
Build Backend / build (push) Successful in 6m39s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
from app.config import Settings
|
||||
|
||||
def test_settings_defaults():
|
||||
"""Test that default settings are correctly loaded."""
|
||||
# We instantiate a new Settings object to test the class directly,
|
||||
# rather than using the already-initialized 'settings' instance in app.config.
|
||||
s = Settings(_env_file=None)
|
||||
assert s.DATABASE_URL == "sqlite+aiosqlite:///./data/sleep.db"
|
||||
assert s.CORS_ORIGINS == "http://localhost:5173"
|
||||
assert s.LOG_LEVEL == "info"
|
||||
|
||||
def test_settings_env_overrides(monkeypatch):
|
||||
"""Test that environment variables correctly override defaults."""
|
||||
# Set environment variables using monkeypatch
|
||||
monkeypatch.setenv("DATABASE_URL", "postgresql+asyncpg://testuser:testpass@localhost/testdb")
|
||||
monkeypatch.setenv("CORS_ORIGINS", "http://example.com")
|
||||
monkeypatch.setenv("LOG_LEVEL", "debug")
|
||||
|
||||
# Re-instantiate Settings to pick up the new environment variables
|
||||
s = Settings(_env_file=None)
|
||||
|
||||
assert s.DATABASE_URL == "postgresql+asyncpg://testuser:testpass@localhost/testdb"
|
||||
assert s.CORS_ORIGINS == "http://example.com"
|
||||
assert s.LOG_LEVEL == "debug"
|
||||
|
||||
def test_settings_partial_override(monkeypatch):
|
||||
"""Test that overriding only some environment variables works correctly."""
|
||||
monkeypatch.setenv("LOG_LEVEL", "warning")
|
||||
|
||||
s = Settings(_env_file=None)
|
||||
|
||||
# Overridden value
|
||||
assert s.LOG_LEVEL == "warning"
|
||||
# Default values should remain
|
||||
assert s.DATABASE_URL == "sqlite+aiosqlite:///./data/sleep.db"
|
||||
assert s.CORS_ORIGINS == "http://localhost:5173"
|
||||
Reference in New Issue
Block a user