import os import pytest def test_settings_load_from_env(monkeypatch): monkeypatch.setenv("DATABASE_URL", "postgresql+asyncpg://u:p@localhost/db") monkeypatch.setenv("S3_ENDPOINT_URL", "http://localhost:9000") monkeypatch.setenv("S3_BUCKET_NAME", "test-bucket") monkeypatch.setenv("S3_ACCESS_KEY_ID", "key") monkeypatch.setenv("S3_SECRET_ACCESS_KEY", "secret") monkeypatch.setenv("S3_REGION", "us-east-1") monkeypatch.setenv("API_BASE_URL", "http://localhost:8000") # Import inside test to pick up monkeypatched env import importlib import app.config as config_module importlib.reload(config_module) s = config_module.Settings() assert s.database_url == "postgresql+asyncpg://u:p@localhost/db" assert s.s3_bucket_name == "test-bucket" assert s.max_upload_bytes == 52428800 # default def test_settings_max_upload_bytes_override(monkeypatch): monkeypatch.setenv("DATABASE_URL", "postgresql+asyncpg://u:p@localhost/db") monkeypatch.setenv("S3_ENDPOINT_URL", "http://localhost:9000") monkeypatch.setenv("S3_BUCKET_NAME", "test-bucket") monkeypatch.setenv("S3_ACCESS_KEY_ID", "key") monkeypatch.setenv("S3_SECRET_ACCESS_KEY", "secret") monkeypatch.setenv("S3_REGION", "us-east-1") monkeypatch.setenv("API_BASE_URL", "http://localhost:8000") monkeypatch.setenv("MAX_UPLOAD_BYTES", "10485760") import importlib import app.config as config_module importlib.reload(config_module) s = config_module.Settings() assert s.max_upload_bytes == 10485760