From 0ca300b4e0deb9ce4a05303670433df43f0a7c4e Mon Sep 17 00:00:00 2001 From: PuQing Date: Mon, 26 Feb 2024 02:01:15 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20build:=20Update=20database=20con?= =?UTF-8?q?figuration=20for=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/app/conftest.py | 13 +++++++++---- backend/app/app/models.py | 2 +- docker-compose.ci.yml | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/app/app/conftest.py b/backend/app/app/conftest.py index af5d244..bb792ef 100644 --- a/backend/app/app/conftest.py +++ b/backend/app/app/conftest.py @@ -8,15 +8,20 @@ from app.web.application import get_app -@pytest.fixture(name="session") -def session_fixture(): +@pytest.fixture(scope="session") +def engine_fixture(): engine = create_engine( - f"postgresql+psycopg://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@bemore-db/{settings.POSTGRES_DB}", + f"postgresql+psycopg://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@bemore-db/test", ) SQLModel.metadata.create_all(engine) - with Session(engine) as session: init_db(session) + yield engine + + +@pytest.fixture(name="session") +def session_fixture(engine_fixture): + with Session(engine_fixture) as session: yield session diff --git a/backend/app/app/models.py b/backend/app/app/models.py index 1f59f8d..07f02dd 100644 --- a/backend/app/app/models.py +++ b/backend/app/app/models.py @@ -84,7 +84,7 @@ def convert_without_saving( update: Optional[dict] = None, ) -> SQLModel: if isinstance(source, SQLModel): - obj = cls.from_orm(source, update=update) # type: ignore + obj = cls.model_validate(source, update=update) # type: ignore elif isinstance(source, dict): obj = cls.parse_obj(source, update=update) # type: ignore return obj diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index ec876b7..3aef9c4 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -9,6 +9,7 @@ services: - .env environment: - PGDATA=/var/lib/postgresql/data/pgdata + - POSTGRES_DB=test networks: - default