From d0aec5dbaac49cf467565177c5b76668f068be22 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Tue, 26 Jan 2021 14:58:46 +0100 Subject: [PATCH] add tests --- src/caosdb/apiutils.py | 2 ++ unittests/test_property.py | 5 +++++ unittests/test_record.xml | 6 ++++++ unittests/test_utils.py | 3 +-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py index bd279fcf..2d4a4a0f 100644 --- a/src/caosdb/apiutils.py +++ b/src/caosdb/apiutils.py @@ -244,6 +244,8 @@ class CaosDBPythonEntity(object): return (val, False) elif pr[0:4] == "LIST": return self._type_converted_list(val, pr) + elif isinstance(val, Entity): + return (convert_to_python_object(val), False) else: return (int(val), True) diff --git a/unittests/test_property.py b/unittests/test_property.py index 8b2deeb4..752ee01f 100644 --- a/unittests/test_property.py +++ b/unittests/test_property.py @@ -84,3 +84,8 @@ def test_get_property_with_entity(): p = Property(id=1234) r.add_property(id=1234, value="bla") assert r.get_property(p).value == "bla" + + +def test_selected_reference_list(): + assert len(testrecord.get_property("Conductor").value) == 1 + assert isinstance(testrecord.get_property("Conductor").value[0], Entity) diff --git a/unittests/test_record.xml b/unittests/test_record.xml index e961bdc6..018c747c 100644 --- a/unittests/test_record.xml +++ b/unittests/test_record.xml @@ -328,4 +328,10 @@ <Value>45531</Value> <Value>45532</Value> </Property> + <Property datatype="LIST<Person>" description="DESCRIBE ME!" id="1634561234" importance="FIX" name="Conductor"> + <Value> + <Record id="23456543"> + </Record> + </Value> + </Property> </Record> diff --git a/unittests/test_utils.py b/unittests/test_utils.py index f308445e..42d18ba0 100644 --- a/unittests/test_utils.py +++ b/unittests/test_utils.py @@ -24,7 +24,6 @@ """Tests for caosdb.common.utils.""" from __future__ import unicode_literals from lxml.etree import Element -from nose.tools import assert_equals as eq from caosdb.common.utils import xml2str @@ -32,4 +31,4 @@ def test_xml2str(): name = 'Björn' element = Element(name) serialized = xml2str(element) - eq(serialized, "<Björn/>\n") + assert serialized == "<Björn/>\n" -- GitLab