Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download tests/test_api_database_url.py from CommunityOne/open-navigator: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/CommunityOne/open-navigator/resolve/main/tests/test_api_database_url.py
- Command line
-
hf download hf://spaces/CommunityOne/open-navigator/tests/test_api_database_url.py
-
curl -L -o test_api_database_url.py https://huggingface.co/spaces/CommunityOne/open-navigator/resolve/main/tests/test_api_database_url.py
1.82 kB
| """The ORM engine names the psycopg2 driver explicitly (#282). | |
| SQLAlchemy 2.1 made ``postgresql://`` mean psycopg 3, which isn't installed, so an | |
| implicit driver stopped ``api.main`` importing and took the live API down. | |
| """ | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| import pytest | |
| from api.database import sqlalchemy_url | |
| REPO = Path(__file__).resolve().parents[1] | |
| def test_sqlalchemy_url_names_psycopg2(given: str, expected: str) -> None: | |
| assert sqlalchemy_url(given) == expected | |
| def test_api_imports_with_a_postgres_url() -> None: | |
| """The failure on the Space: importing the app with a plain postgresql:// URL.""" | |
| pytest.importorskip("psycopg2") | |
| env = {k: v for k, v in os.environ.items() if not k.startswith(("NEON_DATABASE_URL", "DATABASE_URL"))} | |
| env.update( | |
| NEON_DATABASE_URL="postgresql://u:p@127.0.0.1:1/db", | |
| JWT_SECRET_KEY="test-only", | |
| PYTHONPATH=os.pathsep.join([str(REPO), env.get("PYTHONPATH", "")]), | |
| ) | |
| result = subprocess.run( | |
| [sys.executable, "-c", "import api.database as d; print(d.engine.dialect.driver)"], | |
| cwd=REPO, env=env, capture_output=True, text=True, timeout=120, check=False, | |
| ) | |
| assert result.returncode == 0, result.stderr[-2000:] | |
| assert result.stdout.strip().splitlines()[-1] == "psycopg2" | |