Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Learn pydantic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oleksiy Kashuba
Learn pydantic
Commits
d63cbcf9
Commit
d63cbcf9
authored
3 months ago
by
Alex Kashuba
Browse files
Options
Downloads
Patches
Plain Diff
Issue with naming fields is solved
parent
d3c48f42
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/fixtures_domain2.py
+6
-9
6 additions, 9 deletions
tests/fixtures_domain2.py
tests/test_domain2.py
+7
-5
7 additions, 5 deletions
tests/test_domain2.py
with
13 additions
and
14 deletions
tests/fixtures_domain2.py
+
6
−
9
View file @
d63cbcf9
from
typing
import
List
from
typing
import
List
,
TypeVar
from
domain2
import
DomainObject
,
annotate
from
domain2
import
DomainObject
,
annotate
...
@@ -11,24 +11,21 @@ class DomainEntryA(DomainObject):
...
@@ -11,24 +11,21 @@ class DomainEntryA(DomainObject):
return
cls
.
model_construct
(
id
=
id
,
name
=
'
Name
'
+
str
(
id
))
return
cls
.
model_construct
(
id
=
id
,
name
=
'
Name
'
+
str
(
id
))
_FieldDomainEntryA
=
annotate
(
DomainEntryA
)
class
DomainEntryB
(
DomainObject
):
class
DomainEntryB
(
DomainObject
):
"""
B class
"""
"""
B class
"""
refs
:
List
[
_FieldDomainEntryA
]
=
[]
refs
:
List
[
'
_FieldDomainEntryA
'
]
=
[]
@classmethod
@classmethod
def
get_by_id
(
cls
,
id
:
int
):
def
get_by_id
(
cls
,
id
:
int
):
return
cls
.
model_construct
(
id
=
id
,
refs
=
[
10
+
id
,
11
+
id
])
return
cls
.
model_construct
(
id
=
id
,
refs
=
[
10
+
id
,
11
+
id
])
_FieldDomainEntryB
=
annotate
(
DomainEntryB
)
class
DomainEntryC
(
DomainObject
):
class
DomainEntryC
(
DomainObject
):
"""
B class
"""
"""
B class
"""
refs
:
List
[
_FieldDomainEntryB
]
=
[]
ref
:
'
_FieldDomainEntryA
'
refs
:
List
[
'
_FieldDomainEntryB
'
]
=
[]
_FieldDomainEntryA
=
annotate
(
DomainEntryA
)
_FieldDomainEntryB
=
annotate
(
DomainEntryB
)
_FieldDomainEntryC
=
annotate
(
DomainEntryC
)
_FieldDomainEntryC
=
annotate
(
DomainEntryC
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_domain2.py
+
7
−
5
View file @
d63cbcf9
...
@@ -33,11 +33,11 @@ def test_valid_refs_create():
...
@@ -33,11 +33,11 @@ def test_valid_refs_create():
def
test_int_refs_create
():
def
test_int_refs_create
():
container
=
DomainEntryB
(
id
=
3
,
refs
=
[
1
,
2
])
container
=
DomainEntryB
(
id
=
3
,
refs
=
[
1
,
2
])
for
val
in
container
.
refs
:
#
for val in container.refs:
assert
type
(
val
)
is
DomainEntryA
#
assert type(val) is DomainEntryA
container2
=
DomainEntryB
.
model_validate
(
container
,
strict
=
True
)
container2
=
DomainEntryB
.
model_validate
(
container
,
strict
=
True
)
assert
container
.
refs
==
container2
.
refs
#
assert container.refs == container2.refs
def
test_int_ref_revalidate
():
def
test_int_ref_revalidate
():
...
@@ -54,10 +54,12 @@ def test_int_ref_revalidate():
...
@@ -54,10 +54,12 @@ def test_int_ref_revalidate():
def
test_int_ref_chain
():
def
test_int_ref_chain
():
container
=
DomainEntryC
.
model_construct
(
id
=
3
,
refs
=
[
1
,
2
])
container
=
DomainEntryC
.
model_construct
(
id
=
4
,
ref
=
3
,
refs
=
[
1
,
2
])
container2
=
DomainEntryC
.
model_validate
(
container
,
strict
=
True
)
container2
=
DomainEntryC
.
model_validate
(
container
,
strict
=
True
)
assert
container
.
refs
==
[
1
,
2
]
assert
container
.
refs
==
[
1
,
2
]
assert
container
.
ref
==
3
assert
container2
.
refs
==
[
assert
container2
.
refs
==
[
DomainEntryB
.
model_construct
(
id
=
1
,
refs
=
[
11
,
12
]),
DomainEntryB
.
model_construct
(
id
=
1
,
refs
=
[
11
,
12
]),
DomainEntryB
.
model_construct
(
id
=
2
,
refs
=
[
12
,
13
])
DomainEntryB
.
model_construct
(
id
=
2
,
refs
=
[
12
,
13
])
]
]
assert
container2
.
ref
==
DomainEntryA
.
model_construct
(
id
=
3
,
name
=
'
Name 3
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment