Skip to content
Snippets Groups Projects
Verified Commit da04056f authored by Timm Fitschen's avatar Timm Fitschen
Browse files

TST: _parse_value when datatype is an entity

parent 734c5e50
Branches
Tags
No related merge requests found
...@@ -992,25 +992,26 @@ def _parse_value(datatype, value): ...@@ -992,25 +992,26 @@ def _parse_value(datatype, value):
return value return value
# deal with collections # deal with collections
matcher = re.compile(r"^(?P<col>[^<]+)<(?P<dt>[^>]+)>$") if isinstance(datatype, str):
m = matcher.match(datatype) matcher = re.compile(r"^(?P<col>[^<]+)<(?P<dt>[^>]+)>$")
if m: m = matcher.match(datatype)
col = m.group("col") if m:
dt = m.group("dt") col = m.group("col")
dt = m.group("dt")
if col == "LIST":
ret = list() if col == "LIST":
else: ret = list()
return value else:
return value
if hasattr(value, "__iter__") and not isinstance(value, str): if hasattr(value, "__iter__") and not isinstance(value, str):
for v in value: for v in value:
ret.append(_parse_value(dt, v)) ret.append(_parse_value(dt, v))
else: else:
# put a single value into a list since the datatype says so. # put a single value into a list since the datatype says so.
ret.append(_parse_value(dt, value)) ret.append(_parse_value(dt, value))
return ret return ret
# This is for a special case, where the xml parser could not differentiate # This is for a special case, where the xml parser could not differentiate
# between single values and lists with one element. As # between single values and lists with one element. As
......
...@@ -77,3 +77,14 @@ def test_parsing_of_references(): ...@@ -77,3 +77,14 @@ def test_parsing_of_references():
entity = db.Record(name="bla") entity = db.Record(name="bla")
assert id(_parse_value(dtype, entity)) == id(entity) assert id(_parse_value(dtype, entity)) == id(entity)
dtype = db.RecordType(name="Person")
assert _parse_value(dtype, "Anna Lytik") == "Anna Lytik"
assert _parse_value(None, "Anna Lytik") == "Anna Lytik"
assert _parse_value(dtype, "2345@sdfg") == "2345@sdfg"
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment