Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
fd6550a1
Commit
fd6550a1
authored
Jul 13, 2021
by
Alexander Kreft
Browse files
Options
Downloads
Patches
Plain Diff
tests
parent
6969c848
No related branches found
No related tags found
1 merge request
!19
ENH: add resolve_value to Property
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_apiutils.py
+36
-10
36 additions, 10 deletions
unittests/test_apiutils.py
with
36 additions
and
10 deletions
unittests/test_apiutils.py
+
36
−
10
View file @
fd6550a1
...
@@ -29,7 +29,8 @@
...
@@ -29,7 +29,8 @@
import
caosdb
as
db
import
caosdb
as
db
import
pickle
import
pickle
import
tempfile
import
tempfile
from
caosdb.apiutils
import
apply_to_ids
,
create_id_query
,
retrieve_entity_with_id
from
caosdb.apiutils
import
apply_to_ids
,
create_id_query
,
resolve_reference
import
caosdb.apiutils
from
.test_property
import
testrecord
from
.test_property
import
testrecord
...
@@ -63,17 +64,42 @@ def test_apply_to_ids():
...
@@ -63,17 +64,42 @@ def test_apply_to_ids():
assert
rec
.
properties
[
0
].
id
==
-
23345
assert
rec
.
properties
[
0
].
id
==
-
23345
assert
rec
.
id
==
-
23
assert
rec
.
id
==
-
23
def
test_id_query
():
def
test_id_query
():
ids
=
[
1
,
2
,
3
,
4
,
5
]
ids
=
[
1
,
2
,
3
,
4
,
5
]
assert
create_id_query
(
ids
)
==
'
FIND ENTITY WITH ID=1 OR ID=2 OR ID=3 OR ID=4 OR ID=5
'
assert
create_id_query
(
ids
)
==
'
FIND ENTITY WITH ID=1 OR ID=2 OR ID=3 OR ID=4 OR ID=5
'
original_retrieve_entity_with_id
=
retrieve_entity_with_id
retrieve_entity_with_id
=
lambda
eid
:
db
.
Record
(
id
=
eid
)
original_retrieve_entity_with_id
=
caosdb
.
apiutils
.
retrieve_entity_with_id
def
dummy_entity
(
eid
):
return
db
.
Record
(
id
=
eid
)
caosdb
.
apiutils
.
retrieve_entity_with_id
=
dummy_entity
def
test_resolve_reference
():
def
test_resolve_reference
():
prop
=
db
.
Property
(
id
=
1
,
datatype
=
db
.
REFERENCE
,
value
=
100
)
prop
=
db
.
Property
(
id
=
1
,
datatype
=
db
.
REFERENCE
,
value
=
100
)
prop_list
=
[
db
.
Property
(
id
=
2
,
datatype
=
db
.
REFERENCE
,
value
=
200
),
prop
.
is_valid
=
lambda
:
True
db
.
Property
(
id
=
3
,
datatype
=
db
.
REFERENCE
,
value
=
300
),
items
=
[
200
,
300
,
400
]
db
.
Property
(
id
=
4
,
datatype
=
db
.
Integer
,
value
=
400
)
prop_list
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
value
=
items
)
]
prop_list2
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
value
=
db
.
Record
(
id
=
500
))
resolve_reference
(
prop
)
resolve_reference
(
prop_list
)
resolve_reference
(
prop_list2
)
assert
prop
.
value
.
id
==
db
.
Record
(
id
=
100
).
id
prop_list_ids
=
[]
for
i
in
prop_list
.
value
:
prop_list_ids
.
append
(
i
.
id
)
assert
prop_list_ids
==
items
for
i
in
prop_list2
.
value
:
assert
i
.
id
==
500
assert
resolve_reference
(
db
.
Property
(
id
=
5000
,
datatype
=
db
.
INTEGER
,
value
=
2
))
==
None
# restore retrive_entity_with_id
caosdb
.
apiutils
.
retrieve_entity_with_id
=
original_retrieve_entity_with_id
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