feat: Add CI workflow for running tests and update database URL handling
Some checks failed
Build and Push Docker Image / build-and-push (push) Successful in 1m8s
Deploy to Server / deploy (push) Failing after 2s
Run Tests / test (push) Failing after 9m32s

This commit is contained in:
2025-10-24 19:19:24 +02:00
parent 28fea1f3fe
commit f35607fedc
6 changed files with 28 additions and 18 deletions

View File

@@ -18,7 +18,18 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
- name: Cache pip test dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-test-${{ hashFiles('requirements-test.txt') }}
restore-keys: |
${{ runner.os }}-pip-test-
${{ runner.os }}-pip-test-${{ hashFiles('requirements-test.txt') }}
- name: Install dependencies
run: pip install -r requirements.txt
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run tests
run: pytest

View File

@@ -1,5 +1,4 @@
from sqlalchemy import create_engine
from sqlalchemy.engine import URL
from sqlalchemy.orm import declarative_base, sessionmaker
import os
from dotenv import load_dotenv
@@ -14,8 +13,8 @@ def _build_database_url() -> str:
Falls back to `DATABASE_URL` for backward compatibility.
"""
legacy_url = os.environ.get("DATABASE_URL")
if legacy_url:
legacy_url = os.environ.get("DATABASE_URL", "")
if legacy_url and legacy_url.strip() != "":
return legacy_url
driver = os.environ.get("DATABASE_DRIVER", "postgresql")
@@ -42,17 +41,12 @@ def _build_database_url() -> str:
f"granular variables ({', '.join(missing)})"
)
url = URL.create(
drivername=driver,
username=user,
password=password,
host=host,
port=int(port) if port else None,
database=database,
)
url = f"{driver}://{user}:{password}@{host}"
if port:
url += f":{port}"
url += f"/{database}"
if schema:
url = url.set(query={"options": f"-csearch_path={schema}"})
url += f"?options=-csearch_path={schema}"
return str(url)

5
requirements-test.txt Normal file
View File

@@ -0,0 +1,5 @@
pytest
pytest-cov
pytest-httpx
playwright
pytest-playwright

View File

@@ -7,7 +7,3 @@ httpx
jinja2
pandas
numpy
pytest
pytest-cov
pytest-httpx
playwright

View File

@@ -14,4 +14,6 @@ def list_currencies(db: Session = Depends(get_db)):
results = []
for c in db.query(Currency).filter_by(is_active=True).order_by(Currency.code).all():
results.append({"id": c.code, "name": f"{c.name} ({c.code})", "symbol": c.symbol})
if not results:
results.append({"id": "USD", "name": "US Dollar (USD)", "symbol": "$"})
return results

View File

@@ -148,6 +148,8 @@ def _load_currencies(db: Session) -> Dict[str, Any]:
for c in db.query(Currency).filter_by(is_active=True).order_by(Currency.code).all():
items.append(
{"id": c.code, "name": f"{c.name} ({c.code})", "symbol": c.symbol})
if not items:
items.append({"id": "USD", "name": "US Dollar (USD)", "symbol": "$"})
return {"currency_options": items}