Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
d753df87
Commit
d753df87
authored
6 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST(yaml-model-parser): unit test for data model comparison
parent
dc5554d0
No related branches found
No related tags found
2 merge requests
!128
MNT: Added a warning when column metadata is not configured, and a better...
,
!115
add datatype, unit and description to properties that are part of Records
Pipeline
#57809
failed
6 months ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_yaml_model_parser.py
+34
-19
34 additions, 19 deletions
unittests/test_yaml_model_parser.py
with
34 additions
and
19 deletions
unittests/test_yaml_model_parser.py
+
34
−
19
View file @
d753df87
...
@@ -30,8 +30,6 @@ from caosadvancedtools.models.parser import (TwiceDefinedException,
...
@@ -30,8 +30,6 @@ from caosadvancedtools.models.parser import (TwiceDefinedException,
from
linkahead.apiutils
import
compare_entities
from
linkahead.apiutils
import
compare_entities
from
pytest
import
mark
,
raises
from
pytest
import
mark
,
raises
from
unittests.mock
import
Mock
def
to_file
(
string
):
def
to_file
(
string
):
f
=
NamedTemporaryFile
(
mode
=
"
w
"
,
delete
=
False
)
f
=
NamedTemporaryFile
(
mode
=
"
w
"
,
delete
=
False
)
...
@@ -676,12 +674,14 @@ test_reference:
...
@@ -676,12 +674,14 @@ test_reference:
# comparison with a version taken from a LinkAhead instance will have these attributes.
# comparison with a version taken from a LinkAhead instance will have these attributes.
# Furthermore, RT2 will be set as the datatype **in object version** in the yaml definition, while
# Furthermore, RT2 will be set as the datatype **in object version** in the yaml definition, while
# it is an ID in case of the version from the LinkAhead instance.
# it is an ID in case of the version from the LinkAhead instance.
# p_foo = db.Property(name="foo", datatype="INTEGER", description="bla bla", unit="m")
# rt2 = db.RecordType(name="RT2")
# rt1 = db.RecordType(name="RT1")
# rt1.add_property(p_foo)
# rt1.add_property(rt2)
p_foo
=
db
.
Property
(
name
=
"
foo
"
,
datatype
=
"
INTEGER
"
,
description
=
"
bla bla
"
,
unit
=
"
m
"
)
# existing_entities = [
rt2
=
db
.
RecordType
(
name
=
"
RT2
"
)
# p_foo, rt2, rt1]
rt1
=
db
.
RecordType
(
name
=
"
RT1
"
)
rt1
.
add_property
(
p_foo
)
rt1
.
add_property
(
rt2
)
server_response
=
"""
server_response
=
"""
<Entities>
<Entities>
...
@@ -710,26 +710,39 @@ test_reference:
...
@@ -710,26 +710,39 @@ test_reference:
c2
=
compare_entities
(
model
[
"
RT1
"
],
entities
[
1
])
c2
=
compare_entities
(
model
[
"
RT1
"
],
entities
[
1
])
c3
=
compare_entities
(
model
[
"
RT2
"
],
entities
[
2
])
c3
=
compare_entities
(
model
[
"
RT2
"
],
entities
[
2
])
c4
=
compare_entities
(
model
[
"
test_reference
"
],
entities
[
3
])
c4
=
compare_entities
(
model
[
"
test_reference
"
],
entities
[
3
])
for
cs
in
(
c1
,
c2
,
c3
,
c4
):
for
cs
in
(
c1
,
c2
,
c3
,
c4
):
assert
"
id
"
not
in
cs
[
0
]
assert
"
id
"
in
cs
[
0
]
assert
cs
[
0
][
"
id
"
]
is
None
assert
"
id
"
in
cs
[
1
]
assert
"
id
"
in
cs
[
1
]
assert
cs
[
1
][
"
id
"
]
is
not
None
mq
=
Mock
()
# The server response would be the same as the xml above:
def
get_existing_entities
(
ent_cont
):
def
mq_init
(
self
,
query
):
return
entities
self
.
query
=
query
def
mq_execute
(
self
,
unique
=
True
):
class
MockQuery
:
pass
def
__init__
(
self
,
q
):
self
.
q
=
q
mq
.
__init__
=
mq_init
def
execute
(
self
,
unique
=
True
):
mq
.
execute
.
side_effect
=
mq_execute
id
=
int
(
self
.
q
.
split
(
"
=
"
)[
1
])
for
existing_ent
in
entities
:
if
existing_ent
.
id
==
id
:
return
existing_ent
return
None
caosadvancedtools
.
models
.
parser
.
db
.
Query
=
mq
model
.
get_existing_entities
=
get_existing_entities
caosadvancedtools
.
models
.
parser
.
db
.
Query
=
MockQuery
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
=
Mock
()
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
insert
=
Mock
()
model
.
sync_data_model
(
True
,
True
)
model
.
sync_data_model
(
True
,
True
)
assert
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
.
called
stdout
,
stderr
=
capfd
.
readouterr
()
assert
not
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
insert
.
called
output
,
err
=
capfd
.
readouterr
()
print
(
output
)
assert
False
# TODO: test that there were no changes required
# TODO: test that there were no changes required
...
@@ -766,9 +779,11 @@ RT:
...
@@ -766,9 +779,11 @@ RT:
model
.
get_existing_entities
=
get_existing_entities
model
.
get_existing_entities
=
get_existing_entities
caosadvancedtools
.
models
.
parser
.
db
.
Query
=
MockQuery
caosadvancedtools
.
models
.
parser
.
db
.
Query
=
MockQuery
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
=
Mock
()
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
=
Mock
()
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
insert
=
Mock
()
model
.
sync_data_model
(
True
,
True
)
model
.
sync_data_model
(
True
,
True
)
assert
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
.
called
assert
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
update
.
called
assert
not
caosadvancedtools
.
models
.
parser
.
db
.
Container
.
insert
.
called
output
,
err
=
capfd
.
readouterr
()
output
,
err
=
capfd
.
readouterr
()
print
(
output
)
print
(
output
)
assert
"
version from the yaml file: TEXT
"
in
output
assert
"
version from the yaml file: TEXT
"
in
output
...
...
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