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') }} key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ 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 - name: Install dependencies
run: pip install -r requirements.txt run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run tests - name: Run tests
run: pytest run: pytest

View File

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

View File

@@ -14,4 +14,6 @@ def list_currencies(db: Session = Depends(get_db)):
results = [] results = []
for c in db.query(Currency).filter_by(is_active=True).order_by(Currency.code).all(): 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}) 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 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(): for c in db.query(Currency).filter_by(is_active=True).order_by(Currency.code).all():
items.append( items.append(
{"id": c.code, "name": f"{c.name} ({c.code})", "symbol": c.symbol}) {"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} return {"currency_options": items}