Skip to content
Snippets Groups Projects
Unverified Commit f7ce0019 authored by Daniel's avatar Daniel
Browse files

ENH: Test for duplicate parents. Also refactored.

parent 2b67fcdd
No related branches found
No related tags found
No related merge requests found
......@@ -23,20 +23,12 @@
"""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 numpy as np
import pytest
# from tests import test_misc
def setup_module():
try:
......@@ -47,7 +39,7 @@ def setup_module():
def setup():
"""No setup required."""
pass
setup_module()
def teardown():
......@@ -57,48 +49,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(np.unique(pids), len(pids), "Duplicate parents.")
# -*- 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment