From 8809e683a13845689e2ac30d67862acccad58b20 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Thu, 9 Jul 2020 16:37:30 +0200 Subject: [PATCH] WIP: Update more errors --- tests/test_affiliation.py | 83 +++++++++++++++++++------------------ tests/test_issues_server.py | 4 +- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/tests/test_affiliation.py b/tests/test_affiliation.py index 813c6ff..f51305c 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 2bc35a4..cd4e40a 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() -- GitLab