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

More tests and some confirmation tests for bugs

parent c1b70f54
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,6 @@ import pytest
import caosdb as db
def setup():
teardown()
rt = db.RecordType("TestRT")
......@@ -31,78 +30,119 @@ def setup():
p = db.Property("TestProp", datatype=db.TEXT)
p.insert()
def teardown():
try:
db.execute_query("FIND Test*").delete()
except Exception as e:
print(e)
def test_empty_string():
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", value="leer")
r.insert()
assert db.execute_query("FIND TestRT with TestProp='leer'", unique=True).id == r.id
r.delete()
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", value="")
r.insert()
assert db.execute_query("FIND Record TestRT", unique=True).value == ""
# assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r.id
r.delete()
r1 = db.Record()
r1.add_parent("TestRT")
r1.add_property("TestProp", value="")
r1.insert()
# value was stored correctly
assert db.execute_query("FIND Record TestRT", unique=True).get_property("TestProp").value == ""
# query language works for empty string
assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r1.id
assert db.execute_query('FIND TestRT with TestProp=""', unique=True).get_property("TestProp").value == ""
r2 = db.Record()
r2.add_parent("TestRT")
r2.add_property("TestProp", value="not empty")
r2.insert()
assert db.execute_query("FIND TestRT with TestProp='not empty'", unique=True).id == r2.id
# query language work while other records with non empty values are present
assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r1.id
assert len(db.execute_query("FIND Record TestRT")) == 2
def test_null_value():
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", value="null")
r.insert()
assert db.execute_query("FIND TestRT with TestProp='null'", unique=True).id == r.id
r.delete()
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", value=None)
r.insert()
assert db.execute_query("FIND Record TestRT", unique=True).value == None
# assert db.execute_query("FIND TestRT WHERE TestProp IS NULL", unique=True).id == r.id
r.delete()
r1 = db.Record()
r1.add_parent("TestRT")
r1.add_property("TestProp", value=None)
r1.insert()
# value was stored correctly
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == None
# query language works with null value
assert db.execute_query("FIND TestRT WHERE TestProp IS NULL", unique=True).id == r1.id
# add a bit of noise
r2 = db.Record()
r2.add_parent("TestRT")
r2.add_property("TestProp", value="null")
r2.insert()
assert db.execute_query("FIND TestRT with TestProp='null'", unique=True).id == r2.id
# query language works while other record with non-null values are present
assert db.execute_query("FIND TestRT WHERE TestProp IS NULL", unique=True).id == r1.id
assert len(db.execute_query("FIND Record TestRT")) == 2
def test_list_with_empty_string():
r1 = db.Record()
r1.add_parent("TestRT")
r1.add_property("TestProp", datatype=db.LIST(db.TEXT), value=[""])
r1.insert()
# value was stored correctly
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == [""]
# query language works
assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r1.id
r2 = db.Record()
r2.add_parent("TestRT")
r2.add_property("TestProp", datatype=db.LIST(db.TEXT), value=["leer"])
r2.insert()
assert db.execute_query("FIND Record TestRT with TestProp='leer'",
unique=True).get_property("TestProp").value == ["leer"]
assert db.execute_query("FIND TestRT with TestProp='leer'", unique=True).id == r2.id
assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r1.id
def test_null_list():
r1 = db.Record()
r1.add_parent("TestRT")
r1.add_property("TestProp", datatype=db.LIST(db.TEXT), value=None)
r1.insert()
# null list was stored correctly
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == None
assert db.execute_query("FIND TestRT WHERE TestProp IS NULL", unique=True).id == r1.id
@pytest.mark.skip(reason="""this is the confirmation for
https://gitlab.com/caosdb/caosdb-server/issues/new. Empty
lists cannot be distinguished from None.""")
def test_empty_list():
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", datatype=db.LIST(db.TEXT), value=["leer"])
r.insert()
assert len(db.execute_query("FIND Record TestRT", unique=True).value) == 1
assert db.execute_query("FIND Record TestRT", unique=True).value[0] == "leer"
# assert db.execute_query("FIND TestRT with TestProp='leer'", unique=True).id == r.id
r.delete()
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", datatype=db.LIST(db.TEXT), value=[""])
r.add_property("TestProp", datatype=db.LIST(db.TEXT), value=[])
r.insert()
assert len(db.execute_query("FIND Record TestRT", unique=True).value) == 1
assert db.execute_query("FIND Record TestRT", unique=True).value[0] == ""
# assert db.execute_query("FIND TestRT with TestProp=''", unique=True).id == r.id
r.delete()
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == []
@pytest.mark.skip(reason="""this is the confirmation for
https://gitlab.com/caosdb/caosdb-server/issues/new. `None`
cannot be distinguished from [None] lists.""")
def test_list_with_null_value():
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", datatype=db.LIST(db.TEXT), value=["null"])
r.insert()
assert len(db.execute_query("FIND Record TestRT", unique=True).value) == 1
assert db.execute_query("FIND Record TestRT", unique=True).value[0] == "null"
assert db.execute_query("FIND TestRT with TestProp='null'", unique=True).id == r.id
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == ["null"]
r.delete()
r = db.Record()
r.add_parent("TestRT")
r.add_property("TestProp", datatype=db.LIST(db.TEXT), value=[None])
r.insert()
assert len(db.execute_query("FIND Record TestRT", unique=True).value) == 1
assert db.execute_query("FIND Record TestRT", unique=True).value[0] == None
assert db.execute_query("FIND Record TestRT",
unique=True).get_property("TestProp").value == [None]
# assert db.execute_query("FIND TestRT WHERE TestProp IS NULL", unique=True).id == r.id
r.delete()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment