-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): enhance ORM tests and introduce QueryWrapper test
- Added `ExampleRecord` model with `TimestampsMixin` to test models. - Implemented new tests for `ExampleRecord` in `orm_test.py`. - Introduced `test_wrapper.py` for testing `QueryWrapper` types and functionalities. Generated-by: aiautocommit
- Loading branch information
1 parent
ac53278
commit be98abb
Showing
4 changed files
with
61 additions
and
10 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
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,37 @@ | ||
from typing import Any, Generator, assert_type | ||
|
||
import sqlmodel as sm | ||
from sqlmodel.sql.expression import SelectOfScalar | ||
|
||
from activemodel.query_wrapper import QueryWrapper | ||
from test.models import ExampleRecord | ||
|
||
|
||
def test_basic_types(create_and_wipe_database): | ||
qw = ExampleRecord.select() | ||
|
||
sm_query = sm.select(ExampleRecord) | ||
assert_type(sm_query, SelectOfScalar[ExampleRecord]) | ||
|
||
# assert type annotation of qw is QueryWrapper[ExampleRecord] | ||
assert_type(qw, QueryWrapper[ExampleRecord]) | ||
assert isinstance(qw, QueryWrapper) | ||
|
||
all_records = qw.all() | ||
assert_type(all_records, Generator[ExampleRecord, Any, None]) | ||
|
||
all_records_list = list(all_records) | ||
assert_type(all_records_list, list[ExampleRecord]) | ||
|
||
|
||
def test_select_with_args(): | ||
result = ExampleRecord.select(sm.func.max(ExampleRecord.id)).one() | ||
|
||
|
||
def test_result_types(): | ||
"ensure the result types are lists of the specific classes the wrapper was generated from" | ||
|
||
ExampleRecord().save() | ||
|
||
s = sm.select("id").select_from(ExampleRecord) | ||
result = ExampleRecord.select().all() |