From 2b7cf624455a906b13eb8526881fdc2d0c22d1cd Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <alexander@mail-schlemmer.de>
Date: Fri, 25 Feb 2022 12:04:44 +0100
Subject: [PATCH] TST: improved and expanded tests for high level api

---
 unittests/test_high_level_api.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/unittests/test_high_level_api.py b/unittests/test_high_level_api.py
index b6d2f28e..ecab19f1 100644
--- a/unittests/test_high_level_api.py
+++ b/unittests/test_high_level_api.py
@@ -26,6 +26,7 @@
 
 import caosdb as db
 from caosdb.high_level_api import (convert_to_entity, convert_to_python_object)
+from caosdb.high_level_api import (CaosDBPythonUnresolvedParent,)
 import pytest
 from lxml import etree
 import os
@@ -42,8 +43,6 @@ def testrecord():
     return testrecord
 
 
-
-
 def test_convert_object(testrecord):
     r2 = convert_to_python_object(testrecord)
     assert r2.species == "Rabbit"
@@ -71,5 +70,28 @@ def test_convert_record():
     assert obj.a == 42
     assert obj.b == "test"
 
+    # There is no such property
+    with pytest.raises(AttributeError):
+        assert obj.c == 18
+
+    assert obj.has_parent("bla") is True
+    assert obj.has_parent(CaosDBPythonUnresolvedParent(name="bla")) is True
+
+    # Check the has_parent function:
+    assert obj.has_parent("test") is False
+    assert obj.has_parent(CaosDBPythonUnresolvedParent(name="test")) is False
+
+    # duplicate parent
     with pytest.raises(RuntimeError):
         obj.add_parent("bla")
+
+    # add parent with just an id:
+    obj.add_parent(CaosDBPythonUnresolvedParent(id=225))
+    assert obj.has_parent(225) is True
+    assert obj.has_parent(CaosDBPythonUnresolvedParent(id=225)) is True
+    assert obj.has_parent(226) is False
+    assert obj.has_parent(CaosDBPythonUnresolvedParent(id=228)) is False
+
+    # same with just a name:
+    obj.add_parent(CaosDBPythonUnresolvedParent(name="another"))
+    assert obj.has_parent("another") is True
-- 
GitLab