Skip to content
Snippets Groups Projects
Select Git revision
  • 3bf6b29bb7d1cf3f5beecea8cdeb1cc7dc7ee9b3
  • main default protected
  • dev protected
  • f-yaml-parser-enums
  • 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
  • f-h5-files
  • f-json-schema
  • 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

CHANGELOG.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    To find the state of this project's repository at the time of any of these versions, check out the tags.
    test_deletion.py 4.96 KiB
    #!/usr/bin/python2
    # encoding: utf-8
    #
    # ** header v3.0
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2018 Research Group Biomedical Physics,
    # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
    #
    # 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
    #
    
    # Testcase fuer deletion
    # A. Schlemmer, 08/2014
    
    from nose.tools import with_setup, assert_false, assert_true, assert_raises, assert_equal, assert_is_not_none  # @UnresolvedImport
    
    import caosdb as h
    
    
    def setup_module():
        old = h.execute_query("FIND ENTITY WITH ID > 100")
        if old:
            old.delete()
    
    
    def setup161():
        h.RecordType(name="RT1").insert()
        h.RecordType(name="RT2").add_property("RT1").insert()
        h.RecordType(name="RT3").insert()
    
    
    def teardown161():
        setup_module()
    
    
    @with_setup(setup161, teardown161)
    def test_delete_referencing_properties():
        rt3 = h.RecordType(name="RT3").retrieve()
        rt2 = h.RecordType(name="RT2").retrieve()
        rt3.add_property(
            id=rt2.id,
            name=rt2.name,
            datatype="RT2",
            inheritance=h.ALL)
        rt3.update()
        # and delete them
        h.execute_query("FIND ENTITY WITH ID > 100").delete()
    
    
    def setup():
        try:
            h.execute_query("FIND Test*").delete()
        except Exception as e:
            print(e)
    
    
    @with_setup(setup, setup)
    def test_deletion():
        c = h.Container()
        c.append(
            h.Property(
                name="TestSimpleTextProperty",
                description="TestSimple text property (from test_deletion.py)",
                datatype='text'))
        c.append(
            h.Property(
                name="TestSimpleDoubleProperty",
                description="TestSimple double property (from test_deletion.py)",
                datatype='double'))
        c.append(
            h.Property(
                name="TestSimpleIntegerProperty",
                description="TestSimple integer property (from test_deletion.py)",
                datatype='integer'))
        c.append(
            h.Property(
                name="TestSimpleDatetimeProperty",
                description="TestSimple datetime property (from test_deletion.py)",
                datatype='datetime'))
        c.append(
            h.Property(
                name="TestSimpleFileProperty",
                description="TestSimple file property (from test_deletion.py)",
                datatype='file'))
        c.insert()
    
        d = h.Container()
        d.append(
            h.RecordType(
                name="TestSimpleRecordType",
                description="TestSimple recordType (from test_deletion.py)") .add_property(
                name='TestSimpleTextProperty') .add_property(
                    name='TestSimpleDoubleProperty') .add_property(
                        name='TestSimpleIntegerProperty') .add_property(
                            name='TestSimpleDatetimeProperty') .add_property(
                                name='TestSimpleFileProperty'))
    
        d.append(
            h.Property(
                name="TestReferenceProperty",
                description='TestReference property (from test_deletion.py)',
                datatype="TestSimpleRecordType"))
        d.append(h.RecordType(name="TestComplexRecordType", description="TestComplex recordType with TestReferences (from test_deletion.py)")
                 .add_property(name='TestReferenceProperty')  # first method
                 # second method, doesn't need the TestReferenceProperty
                 .add_property(name='TestSimpleRecordType')
                 )
    
        d.insert()
    
        sr = (h.Record(name="TestRecord1").add_parent(name="TestSimpleRecordType")
              .add_property(name="TestSimpleTextProperty", value="Some Text")
              .add_property(name="TestSimpleDoubleProperty", value=3.14)
              .add_property(name="TestSimpleIntegerProperty", value=1337)
              )
    
        sr.insert()
    
        cr1 = (
            h.Record(
                name="TestRecord2").add_parent(
                name="TestComplexRecordType") .add_property(
                    name="TestReferenceProperty",
                value=sr))
    
        cr1.insert()
    
        cr2 = (
            h.Record(
                name="TestRecord3").add_parent(
                name="TestComplexRecordType") .add_property(
                    name="TestSimpleRecordType",
                value=sr))
    
        cr2.insert()
        assert_true(cr2.is_valid())
        assert_is_not_none(cr2.id)
    
        c.extend([cr1, sr, d])
        assert_raises(h.TransactionError, c.delete)
        assert_true(c.has_errors())
        assert_equal(int(c.get_errors()[0].code), 12)
    
        c.extend([cr2])
        print(c)
        c.delete()
    
        assert_false(c.has_errors())