diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index ead0eb61bf713e9a878d1cc0358e8677946c9f19..06617d1e74d5897e3d5b863938864e185dacb554 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -970,6 +970,7 @@ class Entity(object): return self + def _parse_value(datatype, value): if value is None: return value @@ -1031,7 +1032,6 @@ def _parse_value(datatype, value): return str(value) - def _log_request(request, xml_body=None): if Container._debug() > 0: print("\n" + request) diff --git a/unittests/test_datatype.py b/unittests/test_datatype.py index ccda7734501001b1f27082ad1039badaecdb68da..ef650ce2e64d45df169dfdc1ab8199f16ae4ef34 100644 --- a/unittests/test_datatype.py +++ b/unittests/test_datatype.py @@ -37,14 +37,14 @@ def test_list_utilites(): def test_parsing_of_intger_list_values(): dtype = db.LIST(db.INTEGER) - assert _parse_value(dtype, [1,2,3]) == [1,2,3] + assert _parse_value(dtype, [1, 2, 3]) == [1, 2, 3] assert _parse_value(dtype, [1]) == [1] - assert _parse_value(dtype, [None,1,2,3]) == [None,1,2,3] - assert _parse_value(dtype, [1, None,1,2,3]) == [1, None,1,2,3] - assert _parse_value(dtype, ["4", 4]) == [4,4] + assert _parse_value(dtype, [None, 1, 2, 3]) == [None, 1, 2, 3] + assert _parse_value(dtype, [1, None, 1, 2, 3]) == [1, None, 1, 2, 3] + assert _parse_value(dtype, ["4", 4]) == [4, 4] assert _parse_value(dtype, []) == [] - assert _parse_value(dtype, None) == None - assert _parse_value(None, [1,2,3.14,"asdf"]) == [1,2,3.14,"asdf"] + assert _parse_value(dtype, None) is None + assert _parse_value(None, [1, 2, 3.14, "asdf"]) == [1, 2, 3.14, "asdf"] assert _parse_value(dtype, 1) == [1] with raises(ValueError): @@ -75,6 +75,5 @@ def test_parsing_of_references(): assert _parse_value(dtype, "2345") == 2345 assert _parse_value(dtype, 2345) == 2345 - entity = db.Record(name="bla") assert id(_parse_value(dtype, entity)) == id(entity) diff --git a/unittests/test_xml_parsing.py b/unittests/test_xml_parsing.py new file mode 100644 index 0000000000000000000000000000000000000000..46c6978c3d976510b0a76b715e9df89b30beae03 --- /dev/null +++ b/unittests/test_xml_parsing.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +# +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# ** end header + +import caosdb as db +from caosdb.common.utils import xml2str +from .test_property import testrecord + + +def test_null_empty_text_value_1(): + assert testrecord.get_property("LISTofTEXT").value == ["One", "Two", "Three", None, ""] + + +def test_null_empty_text_value_2(): + assert testrecord.get_property("NULLTEXT1").value is None + + +def test_null_empty_text_value_3(): + assert testrecord.get_property("NULLTEXT2").value is None + + +def test_null_empty_text_value_4(): + assert testrecord.get_property("EMPTYTEXT1").value == "" + + +def test_null_empty_text_value_5(): + assert testrecord.get_property("EMPTYTEXT2").value == ""