diff --git a/tests/test_issues.py b/tests/test_issues.py new file mode 100644 index 0000000000000000000000000000000000000000..c2d3a438b4d45abab17ba2f5f3d76362a8ce6137 --- /dev/null +++ b/tests/test_issues.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (c) 2020 IndiScale GmbH +# Copyright (c) 2020 Daniel Hornung <d.hornung@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 + +"""Tests for issues on gitlab.com""" + +from __future__ import absolute_import, print_function, unicode_literals + +import caosdb as db +from caosdb.exceptions import (AmbiguityException, CaosDBException, + EntityDoesNotExistError, EntityError, + TransactionError, UniqueNamesError) +from nose import with_setup +from nose.tools import (assert_equal, assert_false, assert_is_none, + assert_is_not_none, assert_raises, assert_true, + nottest) + +from tests import test_misc + + +def setup_module(): + try: + db.execute_query("FIND ENTITY WITH ID > 100").delete() + except Exception as delete_exc: + print(delete_exc) + + +def setup(): + """No setup required.""" + pass + + +def teardown(): + """Deleting entities again.""" + setup_module() + + +# ########################### Issue tests start here ########################### + +@with_setup(setup, teardown) +def test_issue_85(): + """SQLIntegrityConstraintViolationException for special inheritance patterns. + + Tests for https://gitlab.com/caosdb/caosdb-server/-/issues/85 + """ + A = db.RecordType(name="A") + B = db.RecordType(name="B") + C = db.RecordType(name="C") + + B.add_parent(A) + + # This order is important for the test to fail. + C.add_parent(B) + C.add_parent(C) + C.add_parent(A) + + c = db.Container() + # c.extend([C, B, A]) # worked before #86 was fixed + # c.extend([C, A, B]) # worked before #86 was fixed + c.extend([B, C, A]) # insert() failed before #86 was fixed + c.insert() # Raised java.sql.SQLIntegrityConstraintViolationException: + # Duplicate entry '12345-12346-12345' for key 'PRIMARY'