FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmodel/tests/test_validation.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_validation.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (23 loc) · 936 Bytes
Breadcrumbs
sqlmodel
/
tests
/
test_validation.py
Copy path
File metadata and controls
33 lines (23 loc) · 936 Bytes
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
from
typing
import
Optional
import
pytest
from
pydantic
.
error_wrappers
import
ValidationError
from
sqlmodel
import
SQLModel
def
test_validation_pydantic_v2
(
clear_sqlmodel
):
"""Test validation of implicit and explicit None values.
# For consistency with pydantic, validators are not to be called on
# arguments that are not explicitly provided.
https://github.com/tiangolo/sqlmodel/issues/230
https://github.com/samuelcolvin/pydantic/issues/1223
"""
from
pydantic
import
field_validator
class
Hero
(
SQLModel
):
name
:
Optional
[
str
]
=
None
secret_name
:
Optional
[
str
]
=
None
age
:
Optional
[
int
]
=
None
@
field_validator
(
"name"
,
"secret_name"
,
"age"
)
def
reject_none
(
cls
,
v
):
assert
v
is
not
None
return
v
Hero
.
model_validate
({
"age"
:
25
})
with
pytest
.
raises
(
ValidationError
):
Hero
.
model_validate
({
"name"
:
None
,
"age"
:
25
})
Back
|
FazBrowse Home
|
New Git URL