diff --git a/tests/test_affiliation.py b/tests/test_affiliation.py index 813c6ffb03b8031b0a42139efd6e8edfac61806a..f51305cfde4644387727e29c5eab1cfa5cf4407a 100644 --- a/tests/test_affiliation.py +++ b/tests/test_affiliation.py @@ -28,6 +28,7 @@ import caosdb as db import os from nose.tools import nottest, assert_true, assert_raises, assert_equal, with_setup, assert_is_not_none # @UnresolvedImport +from pytest import raises def setup_module(): @@ -86,31 +87,33 @@ def test_rec_rt_is_instantiation(): @with_setup(setup, teardown) def test_rec_prop_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.Record(name="TestRecordChild").add_parent(name=prop_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + # TransactionError with UnqualifiedParentsError with EntityError + # caused by wrong affiliation + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_rec_file_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.Record(name="TestRecordChild").add_parent(name=file_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_rt_rec_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.RecordType( name="TestRecordTypeChild").add_parent( name=rec_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) @@ -122,48 +125,48 @@ def test_rt_rt_is_subtyping(): @with_setup(setup, teardown) def test_rt_prop_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.RecordType( name="TestRecordTypeChild").add_parent( name=prop_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_rt_file_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.RecordType( name="TestRecordTypeChild").add_parent( name=file_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_prop_rec_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.Property( name="TestPropertyChild", datatype=db.TEXT).add_parent( name=rec_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_prop_rt_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.Property( name="TestPropertyChild", datatype=db.TEXT).add_parent( name=recty_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) @@ -177,14 +180,14 @@ def test_prop_prop_is_subtyping(): @with_setup(setup, teardown) def test_prop_file_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.Property( name="TestPropertyChild", datatype=db.TEXT).add_parent( name=file_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) @@ -209,28 +212,28 @@ def test_file_rt_is_instantiation(): @with_setup(setup, teardown) def test_file_prop_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.File( name="TestFileChild", file=file_path, path="testfilechild.dat").add_parent( name=prop_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @with_setup(setup, teardown) def test_file_file_is_invalid(): - with assert_raises(db.EntityError) as cm: + with raises(db.TransactionError) as cm: db.File( name="TestFileChild", file=file_path, path="testfilechild.dat").add_parent( name=file_name).insert() - assert_equal( - cm.exception.get_errors()[0].msg, - "Affiliation is not defined for this child-parent constellation.") + assert cm.value.has_error(db.UnqualifiedParentsError) + ee = cm.value.get_errors()[0].get_errors()[0] + assert ee.msg == "Affiliation is not defined for this child-parent constellation." @nottest diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py index 2bc35a4eaed3ae883a2a416cfa41730574b7cb12..cd4e40af9c89e5066c789ac60e98830d4619dbba 100644 --- a/tests/test_issues_server.py +++ b/tests/test_issues_server.py @@ -25,7 +25,7 @@ """Tests for issues on gitlab.com, project caosdb-server.""" import caosdb as db -from caosdb.exceptions import EntityError +from caosdb.exceptions import TransactionError import pytest @@ -69,7 +69,7 @@ def test_issue_62(): assert prop.datatype == rtb.name # fails; datatype not updated # Can't use Test_RTA as datatype anymore prop2 = db.Property(name="Test_Prop2", datatype="Test_RTA") - with pytest.raises(EntityError): + with pytest.raises(TransactionError): prop2.insert()