diff --git a/tests/test_error_stuff.py b/tests/test_error_stuff.py index 7323d626f29b5b3a7563d0b404c67c7932010bb3..5f06cae51b045f059722a817aae5a3b502c97dd4 100644 --- a/tests/test_error_stuff.py +++ b/tests/test_error_stuff.py @@ -31,7 +31,8 @@ Created on 19.02.2015. """ import caosdb as h -from caosdb.exceptions import (EntityDoesNotExistError, EntityError, +from caosdb.exceptions import (AmbiguousEntityError, + EntityDoesNotExistError, EntityError, EntityHasNoDatatypeError, TransactionError, UniqueNamesError, UnqualifiedParentsError, @@ -86,6 +87,23 @@ def test_retrieval_exception_raised(): assert ee.entity.has_errors() +@pytest.mark.xfail(reason=("Error treatment on server-side" + "has to be implemented first.")) +def test_ambiguous_retrieval(): + """Test if a TransactionError containing an AmbiguousEntityError is + raised correctly if there are two possible candidates. + + """ + h.RecordType(name="TestType").insert() + h.Record(name="TestRec").add_parent(name="TestType").insert() + # Insert twice, so unique=False + h.Record(name="TestRec").add_parent(name="TestType").insert(unique=False) + with pytest.raises(TransactionError) as te: + h.Record(name="TestRec").retrieve() + assert te.value.has_error(AmbiguousEntityError) + assert te.value.errors[0].entity.name == "TestRec" + + def test_insertion_no_exception_raised(): """Test whether insertion fails but no error is raised.""" p = h.Property(name="TestNoTypeProperty").insert(