-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from dubusster/upsert
feat: ✨ add upsert method in FastCRUD class
- Loading branch information
Showing
5 changed files
with
83 additions
and
3 deletions.
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
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
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 |
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
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 |