Skip to content
Snippets Groups Projects
Select Git revision
  • a7bd31607a2e79eb9e8325e9b91b5783c8d7ff5c
  • main default protected
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
36 results

test_property.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_cache.py 2.82 KiB
    #!/usr/bin/env python
    # encoding: utf-8
    #
    # ** header v3.0
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2020 Indiscale GmbH <info@indiscale.com>
    # Copyright (C) 2020 Florian Spreckelsen <f.spreckelsen@indiscale.com>
    #
    # 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/>.
    #
    # ** end header
    
    import os
    import unittest
    from tempfile import NamedTemporaryFile
    
    import caosdb as db
    from caosadvancedtools.cache import UpdateCache
    
    
    class CacheTest(unittest.TestCase):
        def empty_db(self):
            try:
                db.execute_query("FIND ENTITY Test*").delete()
            except Exception:
                pass
    
        def setUp(self):
            self.cache = NamedTemporaryFile(delete=False).name
            os.remove(self.cache)
            self.empty_db()
    
        def tearDown(self):
            self.empty_db()
            os.remove(self.cache)
    
        def test_same_old_different_new(self):
            """Formerly, inserting two containers with different changes to the
            same entity into the update cache would result in an
            IntegrityException.
    
            """
            rt = db.RecordType(name="TestType").insert()
            db.Property(name="TestProp1", datatype=db.TEXT).insert()
            db.Property(name="TestProp2", datatype=db.TEXT).insert()
            rec = db.Record(name="TestRecord").add_parent(rt).insert()
    
            # add TestProp1 to TestRecord
            rec.add_property(name="TestProp1", value="blub")
            cont = db.Container().append(rec)
    
            update = UpdateCache(db_file=self.cache)
            run_id = "a"
            print(db.execute_query("FIND Record TestRecord", unique=True))
            print(db.execute_query("FIND entity with id="+str(rec.id), unique=True))
            try:
                print(db.execute_query("FIND Record "+str(rec.id), unique=True))
            except BaseException:
                print("Query does not work as expected")
            update.insert(cont, run_id)
            assert len(update.get_updates(run_id)) == 1
    
            # duplicate and add TestProp2 to TestRecord
            rec = db.execute_query("FIND Record TestRecord", unique=True)
            rec.add_property(name="TestProp2", value="bla")
            cont = db.Container().append(rec)
            # same old digest, different new digest
            update.insert(cont, run_id)
            assert len(update.get_updates(run_id)) == 2