-
-
Notifications
You must be signed in to change notification settings - Fork 837
Expand file tree
/
Copy pathtest_query.py
More file actions
26 lines (20 loc) · 762 Bytes
/
test_query.py
File metadata and controls
26 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pytest
from sqlmodel import Field, Session, SQLModel, create_engine
def test_query(clear_sqlmodel):
class Hero(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
secret_name: str
age: int | None = None
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
engine = create_engine("sqlite://")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
session.add(hero_1)
session.commit()
session.refresh(hero_1)
with Session(engine) as session:
with pytest.warns(DeprecationWarning):
query_hero = session.query(Hero).first()
assert query_hero
assert query_hero.name == hero_1.name