diff --git a/tests/test_issues_mysqlbackend.py b/tests/test_issues_mysqlbackend.py index 91e8cf00c8124547b369fb53d311eb7104898270..98665a092f0900326a88f201e99e0a2b5c1f1de2 100644 --- a/tests/test_issues_mysqlbackend.py +++ b/tests/test_issues_mysqlbackend.py @@ -23,20 +23,11 @@ """Tests for issues on gitlab.com, project caosdb-mysqlbackend.""" -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 nose.tools import assert_equal import pytest -# from tests import test_misc - def setup_module(): try: @@ -47,7 +38,7 @@ def setup_module(): def setup(): """No setup required.""" - pass + setup_module() def teardown(): @@ -57,48 +48,26 @@ def teardown(): # ########################### Issue tests start here ########################### +@pytest.mark.xfail @with_setup(setup, teardown) -def test_issue_85_a(): - """SQLIntegrityConstraintViolationException for special inheritance patterns. +def test_issue_18(): + """Sometimes, duplicate parents were returned. - Tests for https://gitlab.com/caosdb/caosdb-server/-/issues/85 + Tests for https://gitlab.com/caosdb/caosdb-mysqlbackend/-/issues/18 """ 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(C) # The self-parenting is here on purpose 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' - - -@with_setup(setup, teardown) -def test_issue_85_b(): - """SQLIntegrityConstraintViolationException for special inheritance patterns. + c.extend([B, C, A]) + c.insert() - 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") - A.insert() - B.insert() - C.insert() - B.add_parent(A) - B.update() - C.add_parent(B) - C.update() - C.add_parent(C) - C.update() - C.add_parent(A) - C.update() # Failed at this step + C1 = db.Entity(name="C").retrieve() + pids = [p.id for p in C1.parents] + assert_equal(len(set(pids)), len(pids), "Duplicate parents.") diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py new file mode 100644 index 0000000000000000000000000000000000000000..9b866dd03f93606224daa317f697a4bbea00ac7c --- /dev/null +++ b/tests/test_issues_server.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (c) 2020 IndiScale GmbH (www.indiscale.com) +# 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, project caosdb-mysqlbackend.""" + +import caosdb as db +from nose import with_setup + + +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.""" + setup_module() + + +def teardown(): + """Deleting entities again.""" + setup_module() + + +# ########################### Issue tests start here ########################### + +@with_setup(setup, teardown) +def test_issue_85_a(): + """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' + + +@with_setup(setup, teardown) +def test_issue_85_b(): + """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") + A.insert() + B.insert() + C.insert() + B.add_parent(A) + B.update() + C.add_parent(B) + C.update() + C.add_parent(C) + C.update() + C.add_parent(A) + C.update() # Failed at this step