-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ add sqlmodel test and clean import
- Loading branch information
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import pytest | ||
from sqlalchemy import select | ||
|
||
from fastcrud.crud.fast_crud import FastCRUD | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |