Spaces:
Runtime error
Runtime error
Greg
Claude Sonnet 4.6
feat(config): switch DATABASE_URL to PostgreSQL with env override support
0461579 Download backend/tests/test_config_database_url.py from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/tests/test_config_database_url.py
- Command line
-
hf download hf://spaces/Talosware/talos-access/backend/tests/test_config_database_url.py
-
curl -L -o test_config_database_url.py https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/tests/test_config_database_url.py
1.58 kB
| import os | |
| from unittest.mock import patch | |
| def test_database_url_uses_postgres_scheme_by_default(): | |
| """When no DATABASE_URL is set, config builds a postgresql:// URL from POSTGRES_* vars.""" | |
| with patch.dict(os.environ, { | |
| "POSTGRES_HOST": "localhost", | |
| "POSTGRES_PORT": "5432", | |
| "POSTGRES_USER": "talos", | |
| "POSTGRES_PASSWORD": "secret", | |
| "POSTGRES_DB": "talos_access", | |
| "DATABASE_URL": "", | |
| }, clear=False): | |
| # Force a fresh Settings instance picking up the patched env | |
| from app.core.config import Settings | |
| s = Settings() | |
| assert s.DATABASE_URL == "postgresql+psycopg2://talos:secret@localhost:5432/talos_access" | |
| def test_database_url_env_override_takes_precedence(): | |
| """When DATABASE_URL is set in env, it is used verbatim (Supabase case).""" | |
| supabase_url = "postgresql://postgres.abc:pass@aws-0-us-east-1.pooler.supabase.com:6543/postgres" | |
| with patch.dict(os.environ, {"DATABASE_URL": supabase_url}, clear=False): | |
| from app.core.config import Settings | |
| s = Settings() | |
| assert s.DATABASE_URL == supabase_url | |
| def test_database_url_never_returns_mysql_scheme(): | |
| """Regression guard: no code path should produce a mysql:// URL.""" | |
| # Clear any DATABASE_URL override and ensure default path produces postgres | |
| with patch.dict(os.environ, {"DATABASE_URL": ""}, clear=False): | |
| from app.core.config import Settings | |
| s = Settings() | |
| assert "mysql" not in s.DATABASE_URL.lower() | |
| assert "pymysql" not in s.DATABASE_URL.lower() | |