Skip to content
Snippets Groups Projects

F h5 cfood

Merged Henrik tom Wörden requested to merge f-h5-cfood into dev
1 file
+ 61
0
Compare changes
  • Side-by-side
  • Inline
#!/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