From af6cdb84d6cda7f6969f3348092c1b84dddb785b Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Wed, 8 Jul 2020 10:24:44 +0200
Subject: [PATCH] TST: Finish unit test

---
 unittests/test_error_handling.py | 41 +++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/unittests/test_error_handling.py b/unittests/test_error_handling.py
index 1811629d..3223ff25 100644
--- a/unittests/test_error_handling.py
+++ b/unittests/test_error_handling.py
@@ -148,7 +148,7 @@ def test_unqualified_parents_error():
     assert isinstance(te.errors[0].errors[0], EntityDoesNotExistError)
     assert te.errors[0].errors[0].entity.name == parent.name
 
-@pytest.mark.xfail
+
 def test_unqualified_properties_error():
     """Code 114; properties do not exist or have wrong data types or
     values.
@@ -171,14 +171,14 @@ def test_unqualified_properties_error():
     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
+    for error_t in [UnqualifiedPropertiesError, EntityError,
+                    EntityDoesNotExistError]:
+        assert any([isinstance(x, error_t) for x in te.all_errors])
+    assert upe.get_code() == code
 
 
 # #################### Multiple errors ####################
 
-@pytest.mark.xfail
 def test_parent_and_properties_errors():
     """Record with UnqualifiedParentsError and UnqualifiedPropertiesError,
     and corresponding parent and properties with their errors as
@@ -204,8 +204,33 @@ def test_parent_and_properties_errors():
         raise_errors(rec)
     # TODO: Now there should be two direct children; both have to be
     # displayed correctly.
+    te = e.value
+    # exactly two children:
+    assert len(te.errors) == 2
+    # both have to have the right codes and entities
+    found_parent = False
+    found_prop = False
+    for err in te.errors:
+        if err.get_code() == parent_code:
+            found_parent = True
+            assert err.errors[0].entity.name == parent.name
+            assert not prop1.name in [x.name for x in
+                                      err.all_entities]
+            assert not prop2.name in [x.name for x in
+                                      err.all_entities]
+        elif err.get_code() == prop_code:
+            found_prop = True
+            assert not parent.name in [x.name for x in
+                                       err.all_entities]
+            for sub_err in err.errors:
+                if sub_err.get_code() == entity_code:
+                    assert sub_err.entity.name == prop1.name
+                elif sub_err.get_code() == no_entity_code:
+                    assert sub_err.entity.name == prop2.name
+    assert found_parent
+    assert found_prop
+
 
-@pytest.mark.xfail
 def test_container_with_faulty_elements():
     """Code 12; container with valid and invalid entities. All faulty
     entities have to be reflected correctly in the errors list of the
@@ -235,7 +260,7 @@ def test_container_with_faulty_elements():
     # broken records with single and multiole errors
     rec_name = _add_error_message_to_entity(db.Record(name="TestRecord2"),
                                             code=name_code)
-    rec_auth = _add_error_message_to_entity(db.Record(name="TestRecord2"),
+    rec_auth = _add_error_message_to_entity(db.Record(name="TestRecord3"),
                                             code=auth_code)
     rec_par_prop = _add_error_message_to_entity(
         db.Record(name="TestRecord"), prop_code)
@@ -245,8 +270,6 @@ def test_container_with_faulty_elements():
     cont.extend([rec_name, rec_auth, rec_par_prop])
     with raises(TransactionError) as e:
         raise_errors(cont)
-    # TODO: Check whether all errors and all broken entities are
-    # listed correctly. The healthy entities must not appear.
     te = e.value
     # only container on first level:
     assert len(te.errors) == 1
-- 
GitLab