From 9e055a9374089dada8c25d3162d7e69596c97517 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Tue, 22 Sep 2020 13:07:35 +0200 Subject: [PATCH] TST: Add test for ambiguous retrieval ... and mark it as xfail until dealt with on server side --- tests/test_error_stuff.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_error_stuff.py b/tests/test_error_stuff.py index 7323d62..5f06cae 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( -- GitLab