From 8bfb410ee13fc4fcb38f7724c00e3bf1aea5a348 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 8 Dec 2024 05:57:04 +0100 Subject: [PATCH] CI: set db host for tests --- .forgejo/workflows/build.yaml | 2 +- .forgejo/workflows/test.yaml | 2 +- Containerfile | 2 +- src/treetrail/database.py | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 11544bb..2852887 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -33,7 +33,7 @@ jobs: run: uv pip install --python=$UV_PROJECT_ENVIRONMENT --no-deps . - name: Run tests (API call) - run: pytest -s tests/basic.py + run: TREETRAIL_DB_HOST=treetrail-database pytest -s tests/basic.py build: runs-on: container diff --git a/.forgejo/workflows/test.yaml b/.forgejo/workflows/test.yaml index 096dc40..fb41758 100644 --- a/.forgejo/workflows/test.yaml +++ b/.forgejo/workflows/test.yaml @@ -31,4 +31,4 @@ jobs: run: uv pip install --python=$UV_PROJECT_ENVIRONMENT --no-deps . - name: Run tests (API call) - run: pytest -s tests/basic.py + run: TREETRAIL_DB_HOST=treetrail-database pytest -s tests/basic.py diff --git a/Containerfile b/Containerfile index 3c5b98a..ee769f8 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -# Build: podman build -t code.philo.ydns.eu/philorg/treetrail-backend-base -f Containerfile.base +# Build: podman build -t code.philo.ydns.eu/philorg/treetrail-backend -f Containerfile FROM code.philo.ydns.eu/philorg/treetrail-backend-deps diff --git a/src/treetrail/database.py b/src/treetrail/database.py index 4433b58..94e15bf 100644 --- a/src/treetrail/database.py +++ b/src/treetrail/database.py @@ -14,7 +14,7 @@ from treetrail.config import conf logger = logging.getLogger(__name__) -CREATE_DB_TIMEOUT = 30 +CREATE_DB_TIMEOUT = 10 engine = create_async_engine( conf.db.get_sqla_url(), @@ -33,7 +33,7 @@ async def create_db(drop=False): await conn.run_sync(SQLModel.metadata.drop_all) await conn.run_sync(SQLModel.metadata.create_all) - logger.debug(f'Connect to database with config: {conf.db}') + logger.debug(f"Connect to database with config: {conf.db}") while attempts > 0: try: await try_once() @@ -68,6 +68,7 @@ async def populate_init_db(): """Populate the database for a fresh install""" from sqlalchemy import text from treetrail.security import create_user, add_role, add_user_role + logger.info("Populating initial database") user = await create_user(username="admin", password="admin") @@ -76,7 +77,7 @@ async def populate_init_db(): async with db_session() as session: for initial in initials: await session.execute(text(initial)) - logger.debug(f'Added map style {initial}') + logger.debug(f"Added map style {initial}") await session.commit()