Skip to content
Snippets Groups Projects
Select Git revision
  • 6d10b7a6f77c7e781605d14976b6f34ee65e82ec
  • main default protected
  • f-prefill-read-only
  • f-recursive-data-model
  • f-yaml-parser-enums
  • dev protected
  • f-fix-paths
  • f-fix-validate-to-dict
  • f-labfolder-converter
  • f-state-machine-script
  • f-xlsx-converter-warnings-errors
  • f-rename
  • f-extra-deps
  • f-more-jsonschema-export
  • f-henrik
  • f-fix-89
  • f-trigger-advanced-user-tools
  • f-real-rename-test
  • f-linkahead-rename
  • f-register-integrationtests
  • f-fix-id
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0-numpy2
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.1
  • v0.6.0
  • v0.5.0
  • v0.4.1
  • v0.4.0
  • v0.3.1
  • v0.3.0
37 results

test_structure_mapping.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_structure_mapping.py 2.47 KiB
    #!/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)