From b7a4a1a210fe8786f838b3e468a613eb0e018a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DUBUS=20L=C3=A9o=20243615?= Date: Thu, 11 Apr 2024 09:39:13 +0200 Subject: [PATCH] =?UTF-8?q?test:=20=E2=9C=85=20add=20sqlmodel=20test=20and?= =?UTF-8?q?=20clean=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/sqlalchemy/crud/test_upsert.py | 2 +- tests/sqlmodel/crud/test_upsert.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/sqlmodel/crud/test_upsert.py diff --git a/tests/sqlalchemy/crud/test_upsert.py b/tests/sqlalchemy/crud/test_upsert.py index f5f5cf6..7fdaba2 100644 --- a/tests/sqlalchemy/crud/test_upsert.py +++ b/tests/sqlalchemy/crud/test_upsert.py @@ -1,5 +1,5 @@ import pytest -from sqlalchemy import select + from fastcrud.crud.fast_crud import FastCRUD diff --git a/tests/sqlmodel/crud/test_upsert.py b/tests/sqlmodel/crud/test_upsert.py new file mode 100644 index 0000000..7fdaba2 --- /dev/null +++ b/tests/sqlmodel/crud/test_upsert.py @@ -0,0 +1,16 @@ +import pytest + +from fastcrud.crud.fast_crud import FastCRUD + + +@pytest.mark.asyncio +async def test_upsert_successful(async_session, test_model, read_schema): + crud = FastCRUD(test_model) + new_data = read_schema(id=1, name="New Record", tier_id=1, category_id=1) + fetched_record = await crud.upsert(async_session, new_data, return_as_model=True) + assert read_schema.model_validate(fetched_record) == new_data + + fetched_record.name == "New name" + + updated_fetched_record = await crud.upsert(async_session, fetched_record) + assert read_schema.model_validate(updated_fetched_record) == fetched_record