From 5a499414dbe39036879fb38e60fcac966e3d95d8 Mon Sep 17 00:00:00 2001 From: Bakar Tavadze Date: Mon, 22 Apr 2024 16:48:24 +0400 Subject: [PATCH] Use storage settings during tests. --- backend/tests/unit_tests/conftest.py | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/backend/tests/unit_tests/conftest.py b/backend/tests/unit_tests/conftest.py index 4d21da0d..8070c0bf 100644 --- a/backend/tests/unit_tests/conftest.py +++ b/backend/tests/unit_tests/conftest.py @@ -9,6 +9,7 @@ from app.auth.settings import settings as auth_settings from app.lifespan import get_pg_pool, lifespan from app.server import app +from app.storage.settings import settings as storage_settings auth_settings.auth_type = AuthType.NOOP @@ -16,16 +17,16 @@ os.environ["OPENAI_API_KEY"] = "test" TEST_DB = "test" -assert os.environ["POSTGRES_DB"] != TEST_DB, "Test and main database conflict." -os.environ["POSTGRES_DB"] = TEST_DB +assert storage_settings.postgres.db != TEST_DB, "Test and main database conflict." +storage_settings.postgres.db = TEST_DB async def _get_conn() -> asyncpg.Connection: return await asyncpg.connect( - user=os.environ["POSTGRES_USER"], - password=os.environ["POSTGRES_PASSWORD"], - host=os.environ["POSTGRES_HOST"], - port=os.environ["POSTGRES_PORT"], + user=storage_settings.postgres.user, + password=storage_settings.postgres.password, + host=storage_settings.postgres.host, + port=storage_settings.postgres.port, database="postgres", ) @@ -49,7 +50,21 @@ async def _drop_test_db() -> None: def _migrate_test_db() -> None: - subprocess.run(["make", "migrate"], check=True) + subprocess.run( + [ + "migrate", + "-database", + ( + f"postgres://{storage_settings.postgres.user}:{storage_settings.postgres.password}" + f"@{storage_settings.postgres.host}:{storage_settings.postgres.port}" + f"/{storage_settings.postgres.db}?sslmode=disable" + ), + "-path", + "./migrations/postgres", + "up", + ], + check=True, + ) @pytest.fixture(scope="session")