From 2dd5e6f48261da74f178fb796411111d40b3110a Mon Sep 17 00:00:00 2001 From: hay-kot Date: Sat, 1 May 2021 12:18:49 -0800 Subject: [PATCH] test pg workflow --- .github/workflows/test-all.yml | 18 ++++++++++++++++++ mealie/core/config.py | 4 ++-- tests/conftest.py | 2 +- tests/pre_test.py | 9 +++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 46be84b45..73a58a6f0 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -15,6 +15,16 @@ jobs: env: PRODUCTION: false runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_USER: mealie + POSTGRES_PASSWORD: mealie + POSTGRES_DB: mealie + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 5432:5432 steps: #---------------------------------------------- # check-out repo and set-up python @@ -54,3 +64,11 @@ jobs: - name: Run Test Suite run: | make test-all + #---------------------------------------------- + # run test suite + #---------------------------------------------- + - name: Run Test Suite Postgres + env: + DB_ENGINE: postgres + run: | + make test-all diff --git a/mealie/core/config.py b/mealie/core/config.py index 8263019e2..c08d75cb1 100644 --- a/mealie/core/config.py +++ b/mealie/core/config.py @@ -82,9 +82,9 @@ class AppDirectories: app_dirs = AppDirectories(CWD, DATA_DIR) -def determine_sqlite_path(path=False) -> str: +def determine_sqlite_path(path=False, suffix=DB_VERSION) -> str: global app_dirs - db_path = app_dirs.DATA_DIR.joinpath(f"mealie_{DB_VERSION}.db") # ! Temporary Until Alembic + db_path = app_dirs.DATA_DIR.joinpath(f"mealie_{suffix}.db") # ! Temporary Until Alembic if path: return db_path diff --git a/tests/conftest.py b/tests/conftest.py index 3c6e18075..f641f27e6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,7 @@ def api_client(): yield TestClient(app) - DB_URL.unlink() + DB_URL.unlink(missing_ok=True) @fixture(scope="session") diff --git a/tests/pre_test.py b/tests/pre_test.py index c1483e003..5056fab66 100644 --- a/tests/pre_test.py +++ b/tests/pre_test.py @@ -1,7 +1,8 @@ -from mealie.core.config import app_dirs, settings +from mealie.core.config import determine_sqlite_path, settings -# Monkeypatch Database Testing -DB_URL = app_dirs.DATA_DIR.joinpath("test.db") +DB_URL = determine_sqlite_path(path=True, suffix="test") DB_URL.unlink(missing_ok=True) -settings.DB_URL = "sqlite:///" + str(DB_URL.absolute()) +if settings.DB_ENGINE != "postgres": + # Monkeypatch Database Testing + settings.DB_URL = determine_sqlite_path(path=False, suffix="test") \ No newline at end of file