Skip to content
Snippets Groups Projects
Commit 09daacad authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-semantic-select-query' into 'dev'

F semantic select query

See merge request caosdb/caosdb-pyinttest!49
parents e3f6f3a2 dc267ca9
No related branches found
No related tags found
No related merge requests found
......@@ -41,15 +41,22 @@ def setup_module():
name="TestPropertyOne", value="v1").add_property(
name="TestPropertyTwo", value="v2").insert()
rt_house = db.RecordType("TestHouse", description="TestHouseDesc").insert()
db.RecordType("TestWindow").insert()
db.RecordType("TestHousePart", description="TestHousePartDesc").insert()
db.RecordType("TestWindow").add_parent("TestHousePart").insert()
db.RecordType("TestDoor").add_parent("TestHousePart").insert()
rt_person = db.RecordType("TestPerson",
description="TestPersonDesc").insert()
db.RecordType("TestParty", description="TestPartyDesc").insert()
db.Property("TestHouseProperty", datatype=db.TEXT).insert()
db.Property("TestHeight", description="TestHeightDesc", datatype=db.DOUBLE,
unit="ft").insert()
unit="ft").add_parent("TestHouseProperty").insert()
db.Property("TestDate", description="TestDateDesc",
datatype=db.DATETIME).insert()
door = db.Record("Door1",
description="Door1Desc").add_parent("TestDoor")
door.add_property("TestHeight", "21.5", unit="ft")
door.insert()
window = db.Record("Window1",
description="Window1Desc").add_parent("TestWindow")
window.add_property("TestHeight", 20.5, unit="ft")
......@@ -61,7 +68,9 @@ def setup_module():
house.description = "A rather large house"
house.add_parent("TestHouse")
house.add_property(rt_person, name="TestOwner", value=owner)
house.add_property("TestWindow", window).insert()
house.add_property("TestWindow", window)
house.add_property("TestDoor", door)
house.insert()
g1 = db.Record().add_parent("TestPerson").insert()
g2 = db.Record().add_parent("TestPerson").insert()
......@@ -326,3 +335,55 @@ def test_select_name():
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "name", "TestWindow"))
assert column == (None,)
def test_select_with_subtyping_semantics():
s = db.execute_query(
"SELECT name FROM RECORD TestHouse WITH TestHousePart",
unique=True)
column = s.get_property_values("name")
assert column == ("Buckingham Palace",)
s = db.execute_query(
"SELECT TestWindow.TestHeight FROM RECORD TestHouse WITH TestHousePart",
unique=True)
column = s.get_property_values(("TestWindow", "TestHeight"))
assert column == (20.5,)
s = db.execute_query(
"SELECT TestHousePart.TestHeight FROM RECORD TestHouse WITH TestHousePart",
unique=True)
column = s.get_property_values(("TestHousePart", "TestHeight"))
# this is a current limitation of get_property_values which will only
# return the value of the first matching property
assert column == (20.5,)
assert len(s.properties) == 2
# both the door and the window have been returned
assert (s.properties[0].name,
s.properties[1].name) == ("TestHousePart", "TestHousePart")
assert (s.properties[0].value.properties[0].value,
s.properties[1].value.properties[0].value) == (20.5, 21.5)
def test_select_with_subtyping_semantics_second_level():
s = db.execute_query(
"SELECT TestHousePart.TestHouseProperty FROM RECORD TestHouse WITH TestHousePart",
unique=True)
column = s.get_property_values(("TestHousePart", "TestHouseProperty"))
# this is a current limitation of get_property_values which will only
# return the value of the first matching property
assert column == (20.5,)
assert len(s.properties) == 2
# both the door and the window have been returned
assert (s.properties[0].name,
s.properties[1].name) == ("TestHousePart", "TestHousePart")
assert (s.properties[0].value.properties[0].value,
s.properties[1].value.properties[0].value) == (20.5, 21.5)
def test_select_with_subtyping_semantics_and_name_duplicates():
db.Property(name="TestHousePart", description="This is a duplicate",
datatype=db.TEXT).insert(unique=False)
test_select_with_subtyping_semantics()
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