diff --git a/unittests/test_error_handling.py b/unittests/test_error_handling.py index e467517f3799c6c0782e8e1b7f0b19fb72b97699..deb3c18d0154f9fb3f4fbe5059857184377d6f14 100644 --- a/unittests/test_error_handling.py +++ b/unittests/test_error_handling.py @@ -30,7 +30,7 @@ import caosdb as db from caosdb.common.models import raise_errors # TODO: Import the relevant error classes once they have been finalized. from caosdb.exceptions import (AmbiguityException, - AuthorizationException, + AuthorizationException, ContainerError, EntityDoesNotExistError, EntityError, EntityHasNoDatatypeError, TransactionError, UniqueNamesError) @@ -134,10 +134,16 @@ def test_unqualified_parents_error(): rec.add_parent(parent) with raises(TransactionError) as e: raise_errors(rec) - # TODO: Both direct and indirect children should be in the errors - # list, the only direct child is the UnqualifiedParentsError with - # entity rec and one child of its own; the EntityDoesNotExistError - # with entity parent. + te = e.value + # One direct child, two errors in total + assert len(te.errors) == 1 + assert len(te.all_errors) == 2 + # UnqualifiedParentsError in Record ... + assert isinstance(te.errors[0], UnqualifiedParentsError) + assert te.errors[0].entity.name == rec.name + # ... caused by non-existing parent + assert isinstance(te.errors[0].errors[0], EntityDoesNotExistError) + assert te.errors[0].errors[0].entity.name == parent.name def test_unqualified_properties_error(): @@ -157,7 +163,14 @@ def test_unqualified_properties_error(): rec.add_property(prop1).add_property(prop2) with raises(TransactionError) as e: raise_errors(rec) - # TODO: This should result in one direct child with two children. + te = e.value + assert len(te.errors) == 1 + upe = te.errors[0] + assert upe.entity.name == rec.name + assert len(upe.errors) == 2 + assert {UnqualifiedPropertiesError, EntityError, + EntityDoesNotExistError}.issubset(te.all_errors) + assert upe.get_code == code # #################### Multiple errors #################### @@ -279,3 +292,6 @@ def test_convenience_functions(): for error_t in [EntityDoesNotExistError, UnqualifiedParentsError, UnqualifiedPropertiesError]: assert te.has_error(error_t) + # Not, if limitted to direct children + assert not te.has_error(EntityDoesNotExistError, + direct_children_only=True)