From f35607fedc1bb644622febd0fe522a900c1dc321 Mon Sep 17 00:00:00 2001 From: zwitschi Date: Fri, 24 Oct 2025 19:19:24 +0200 Subject: [PATCH] feat: Add CI workflow for running tests and update database URL handling --- .gitea/workflows/{test.yml.bak => test.yml} | 13 ++++++++++++- config/database.py | 20 +++++++------------- requirements-test.txt | 5 +++++ requirements.txt | 4 ---- routes/currencies.py | 2 ++ routes/ui.py | 2 ++ 6 files changed, 28 insertions(+), 18 deletions(-) rename .gitea/workflows/{test.yml.bak => test.yml} (52%) create mode 100644 requirements-test.txt diff --git a/.gitea/workflows/test.yml.bak b/.gitea/workflows/test.yml similarity index 52% rename from .gitea/workflows/test.yml.bak rename to .gitea/workflows/test.yml index 97c4f4e..e8f3d6a 100644 --- a/.gitea/workflows/test.yml.bak +++ b/.gitea/workflows/test.yml @@ -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 diff --git a/config/database.py b/config/database.py index ad8a8f5..a850c05 100644 --- a/config/database.py +++ b/config/database.py @@ -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) diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..2c69518 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,5 @@ +pytest +pytest-cov +pytest-httpx +playwright +pytest-playwright \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4f5aabe..d85057c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,3 @@ httpx jinja2 pandas numpy -pytest -pytest-cov -pytest-httpx -playwright \ No newline at end of file diff --git a/routes/currencies.py b/routes/currencies.py index 06e6d48..d1a86fc 100644 --- a/routes/currencies.py +++ b/routes/currencies.py @@ -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 diff --git a/routes/ui.py b/routes/ui.py index 3ec8b37..ff54d02 100644 --- a/routes/ui.py +++ b/routes/ui.py @@ -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}