FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/tests/test_instance_no_args.py at main · ByteDecoder/sqlmodel · GitHub
ByteDecoder
sqlmodel
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmodel
/
tests
/
test_instance_no_args.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (28 loc) · 1.01 KB
Breadcrumbs
sqlmodel
/
tests
/
test_instance_no_args.py
Copy path
File metadata and controls
35 lines (28 loc) · 1.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
27
28
29
30
31
32
33
34
35
from
typing
import
Optional
import
pytest
from
pydantic
import
ValidationError
from
sqlmodel
import
Field
,
Session
,
SQLModel
,
create_engine
,
select
def
test_allow_instantiation_without_arguments
(
clear_sqlmodel
):
class
Item
(
SQLModel
,
table
=
True
):
id
:
Optional
[
int
]
=
Field
(
default
=
None
,
primary_key
=
True
)
name
:
str
description
:
Optional
[
str
]
=
None
engine
=
create_engine
(
"sqlite:///:memory:"
)
SQLModel
.
metadata
.
create_all
(
engine
)
with
Session
(
engine
)
as
db
:
item
=
Item
()
item
.
name
=
"Rick"
db
.
add
(
item
)
db
.
commit
()
statement
=
select
(
Item
)
result
=
db
.
exec
(
statement
).
all
()
assert
len
(
result
)
==
1
assert
isinstance
(
item
.
id
,
int
)
SQLModel
.
metadata
.
clear
()
def
test_not_allow_instantiation_without_arguments_if_not_table
():
class
Item
(
SQLModel
):
id
:
Optional
[
int
]
=
Field
(
default
=
None
,
primary_key
=
True
)
name
:
str
description
:
Optional
[
str
]
=
None
with
pytest
.
raises
(
ValidationError
):
Item
()
Back
|
FazBrowse Home
|
New Git URL