Skip to content
Snippets Groups Projects
Commit 80708974 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: added correct handling of base attributes

parent 442acd02
Branches
Tags
2 merge requests!57RELEASE 0.7.3,!52F refactor high level api
......@@ -52,8 +52,6 @@ class CaosDBPropertyMetaData:
# name is already the name of the attribute
unit: Optional[str] = None
datatype: Optional[str] = None
file: Optional[str] = None
path: Optional[str] = None
description: Optional[str] = None
id: Optional[int] = None
importance: Optional[str] = None
......@@ -638,8 +636,9 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
Returns the input object robj.
"""
for base_attribute in BASE_ATTRIBUTES:
robj.__setattr__(base_attribute,
entity.__getattribute__(base_attribute))
val = entity.__getattribute__(base_attribute)
if val is not None:
robj.__setattr__(base_attribute, val)
for prop in entity.properties:
robj._set_property_from_entity(prop, entity.get_importance(prop), references)
......@@ -663,13 +662,13 @@ def _single_convert_to_entity(entity: db.Entity,
The CaosDBPythonEntity that is supposed to be converted to the entity.
"""
# for base_attribute in BASE_ATTRIBUTES:
# modified_base_attribute = base_attribute
# if base_attribute in ("file", "path"):
# modified_base_attribute = "_" + modified_base_attribute
for base_attribute in BASE_ATTRIBUTES:
if base_attribute in ("file", "path") and not isinstance(robj, CaosDBPythonFile):
continue
val = robj.__getattribute__(base_attribute)
# entity.__setattr__(modified_base_attribute,
# robj.__getattribute__(base_attribute))
if val is not None:
entity.__setattr__(base_attribute, val)
for parent in robj.get_parents():
if isinstance(parent, CaosDBPythonUnresolvedParent):
......
......@@ -260,6 +260,31 @@ def test_conversion_to_entity():
== r.get_property("ref").value.get_property("a").value)
# TODO: add more tests here
def test_base_properties():
r = db.Record(id=5, name="test", description="ok")
r.add_property(name="v", value=15, datatype=db.INTEGER, unit="kpx",
importance="RECOMMENDED", description="description")
obj = convert_to_python_object(r)
assert obj.name == "test"
assert obj.id == 5
assert obj.description == "ok"
metadata = obj.get_property_metadata("v")
assert metadata.id is None
assert metadata.datatype == db.INTEGER
assert metadata.unit == "kpx"
assert metadata.importance == "RECOMMENDED"
assert metadata.description == "description"
rconv = convert_to_entity(obj)
assert rconv.name == "test"
assert rconv.id == 5
assert rconv.description == "ok"
prop = rconv.get_property("v")
assert prop.value == 15
assert prop.datatype == db.INTEGER
assert prop.unit == "kpx"
assert prop.description == "description"
assert rconv.get_importance("v") == "RECOMMENDED"
def test_empty():
r = db.Record()
......@@ -293,6 +318,14 @@ def test_serialization():
for teststr in teststrs:
assert teststr in text
r = db.Record(description="ok")
r.add_property(name="v", value=15, datatype=db.INTEGER, unit="kpx",
importance="RECOMMENDED")
obj = convert_to_python_object(r)
text = str(obj)
assert "name" not in text
assert "id" not in text
def test_files():
# empty file:
......@@ -316,6 +349,5 @@ def test_files():
assert obj.path == "test.dat"
assert obj.file == "/local/path/test.dat"
print(obj)
assert "path: test.dat" in str(obj)
assert "file: /local/path/test.dat" in str(obj)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment