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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Merge requests
!8
F h5 cfood
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
F h5 cfood
f-h5-cfood
into
dev
Overview
1
Commits
137
Pipelines
22
Changes
1
Merged
Henrik tom Wörden
requested to merge
f-h5-cfood
into
dev
3 years ago
Overview
1
Commits
137
Pipelines
22
Changes
1
https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/merge_requests/78
0
0
Merge request reports
Viewing commit
6d10b7a6
Prev
Next
Show latest version
1 file
+
61
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
6d10b7a6
TST: test structure mapping
· 6d10b7a6
Alexander Kreft
authored
3 years ago
unittests/test_structure_mapping.py
0 → 100644
+
61
−
0
View file @ 6d10b7a6
Edit in single-file editor
Open in Web IDE
#!/usr/bin/env python3
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 IndiScale GmbH <www.indiscale.com>
# Copyright (C) 2021 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2021 Alexander Kreft <akreft@trineo.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import
unittest
import
caosdb
as
db
from
caosadvancedtools.structure_mapping
import
EntityMapping
,
collect_existing_structure
class
structureMappingTest
(
unittest
.
TestCase
):
def
test_Entitymapping
(
self
):
ex
=
db
.
Record
(
id
=
100
)
tar
=
db
.
Record
()
em
=
EntityMapping
()
em
.
add
(
tar
,
ex
)
for
i
in
em
.
to_existing
.
keys
():
self
.
assertEqual
(
i
,
tar
.
_cuid
)
for
j
in
em
.
to_existing
.
values
():
self
.
assertEqual
(
j
,
ex
)
for
i
in
em
.
to_target
.
keys
():
self
.
assertEqual
(
i
,
ex
.
id
)
for
j
in
em
.
to_target
.
values
():
self
.
assertEqual
(
j
,
tar
)
def
test_collect_existing_structure
(
self
):
map
=
EntityMapping
()
reca1
=
db
.
Record
(
name
=
"
Animals
"
,
id
=
100
)
reca2
=
db
.
Record
(
name
=
"
Dogs
"
,
id
=
200
)
reca3
=
db
.
Record
(
name
=
"
Husky
"
,
id
=
300
)
reca1
.
add_property
(
id
=
101
,
name
=
"
Cute Animals
"
,
datatype
=
db
.
REFERENCE
,
value
=
reca2
)
reca2
.
add_property
(
id
=
201
,
name
=
"
Cute Dogs
"
,
datatype
=
db
.
REFERENCE
,
value
=
reca3
)
recb1
=
db
.
Record
(
name
=
"
Animals
"
)
recb2
=
db
.
Record
(
name
=
"
Dogs
"
)
recb3
=
db
.
Record
(
name
=
"
Husky
"
)
recb1
.
add_property
(
name
=
"
Cute Animals
"
,
datatype
=
db
.
REFERENCE
,
value
=
recb2
)
recb2
.
add_property
(
name
=
"
Cute Dogs
"
,
datatype
=
db
.
REFERENCE
,
value
=
recb3
)
collect_existing_structure
(
recb1
,
reca1
,
map
)
for
i
in
map
.
to_existing
.
keys
():
self
.
assertEqual
(
i
,
map
.
to_target
[
map
.
to_existing
[
i
].
id
].
_cuid
)
for
j
in
map
.
to_target
.
keys
():
self
.
assertEqual
(
j
,
map
.
to_existing
[
map
.
to_target
[
j
].
_cuid
].
id
)
Loading