Skip to content
Snippets Groups Projects
Commit ab06cb26 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'dev' into f-exception-handling

parents 237f2073 e811b854
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], datatype=db.LIST("TestWindow"))
house.add_property("TestDoor", door)
house.insert()
g1 = db.Record().add_parent("TestPerson").insert()
g2 = db.Record().add_parent("TestPerson").insert()
......@@ -183,33 +192,71 @@ def test_sub2():
def test_subref():
window = db.execute_query("FIND RECORD TestWindow", unique=True)
s = db.execute_query("SELECT name, TestWindow.TestHeight.value, "
"TestWindow.TestHeight.unit FROM RECORD TestHouse")
door = db.execute_query("FIND RECORD TestDoor", unique=True)
s = db.execute_query("SELECT name, TestDoor.TestHeight.value, "
"TestDoor.TestHeight.unit FROM RECORD TestHouse")
assert len(s) == 1
row = s.get_property_values("name", "TestWindow")[0]
row = s.get_property_values("name", "TestDoor")[0]
assert row[0] == "Buckingham Palace"
assert row[1] == window.id
assert row[1] == door.id
row = s.get_property_values("name", ("TestWindow", "TestHeight"))[0]
row = s.get_property_values("name", ("TestDoor", "TestHeight"))[0]
assert row[0] == "Buckingham Palace"
assert row[1] == 20.5
assert row[1] == 21.5
row = s.get_property_values(
"name", ("TestWindow", "TestHeight", "unit"))[0]
"name", ("TestDoor", "TestHeight", "unit"))[0]
assert row[0] == "Buckingham Palace"
assert row[1] == "ft"
def test_subref_list():
window = db.execute_query("FIND RECORD TestWindow", unique=True)
s = db.execute_query("SELECT name, TestWindow.TestHeight.value, "
"TestWindow.TestHeight.unit FROM RECORD TestHouse")
assert len(s) == 1
row = s.get_property_values("name", "TestWindow")[0]
assert row[0] == "Buckingham Palace"
assert row[1][0].id == window.id
# current limitation of get_property_values - no lists
# row = s.get_property_values("name", ("TestWindow", "TestHeight"))[0]
# assert row[0] == "Buckingham Palace"
# assert row[1] == 20.5
assert row[1][0].get_property("TestHeight").value == 20.5
# current limitation of get_property_values - no lists
# row = s.get_property_values(
# "name", ("TestWindow", "TestHeight", "unit"))[0]
# assert row[0] == "Buckingham Palace"
# assert row[1] == "ft"
assert row[1][0].get_property("TestHeight").unit == "ft"
def test_subref_deep():
p = db.execute_query(
"SELECT name, Testdate, location, location.TestWindow.Testheight FROM "
"SELECT name, Testdate, location, location.TestDoor.Testheight FROM "
"RECORD TestParty", unique=True)
row = p.get_property_values("name", "Testdate",
("location", "Testwindow", "Testheight"))
assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 20.5)
("location", "Testdoor", "Testheight"))
assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 21.5)
def test_subref_deep_list():
p = db.execute_query(
"SELECT name, Testdate, location, location.TestWindow.Testheight FROM "
"RECORD TestParty", unique=True)
# current limitation of get_property_values - no lists
# row = p.get_property_values("name", "Testdate",
# ("location", "Testwindow", "Testheight"))
# assert row == ("Diamond Jubilee of Elizabeth II", "2012-02-06", 20.5)
assert p.get_property_values(("location", "TestWindow"))[
0][0].get_property("TestHeight").value == 20.5
def test_select_list():
......@@ -218,6 +265,7 @@ def test_select_list():
s = db.execute_query("SELECT guests FROM RECORD TestParty", unique=True)
column = s.get_property_values("guests")[0]
print(s)
assert len(column) == len(guests)
for eid in [e.id for e in guests]:
......@@ -233,17 +281,35 @@ def test_select_unit():
column = s.get_property_values("unit")
assert column == ("ft",)
s = db.execute_query("SELECT TestWindow.TestHeight.unit FROM "
s = db.execute_query("SELECT TestDoor.TestHeight.unit FROM "
"RECORD TestHouse", unique=True)
column = s.get_property_values(("TestWindow", "TestHeight", "unit"))
column = s.get_property_values(("TestDoor", "TestHeight", "unit"))
assert column == ("ft",)
s = db.execute_query("SELECT TestHeight.unit.TestWindow FROM "
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "unit", "TestWindow"))
s = db.execute_query("SELECT TestHeight.unit.TestDoor FROM "
"RECORD TestDoor", unique=True)
column = s.get_property_values(("TestHeight", "unit", "TestDoor"))
assert column == (None,)
def test_select_unit_list():
s = db.execute_query("SELECT unit FROM RECORD TestHouse", unique=True)
column = s.get_property_values("unit")
assert column == (None,)
s = db.execute_query("SELECT unit FROM PROPERTY TestHeight", unique=True)
column = s.get_property_values("unit")
assert column == ("ft",)
s = db.execute_query("SELECT TestWindow.TestHeight.unit FROM "
"RECORD TestHouse", unique=True)
# current limitation of get_property_values - no lists
# column = s.get_property_values(("TestWindow", "TestHeight", "unit"))
# assert column == ("ft",)
assert s.get_property_values(("TestWindow"))[
0][0].get_property("TestHeight").unit == "ft"
def test_select_description():
s = db.execute_query("SELECT description FROM RECORD TestPerson")
column = s.get_property_values("description")
......@@ -260,21 +326,50 @@ def test_select_description():
assert column == ("A rather large house",)
s = db.execute_query("SELECT TestHeight.description FROM "
"RECORD TestWindow", unique=True)
"RECORD TestDoor", unique=True)
column = s.get_property_values(("TestHeight", "description"))
assert column == ('TestHeightDesc',)
s = db.execute_query("SELECT TestWindow.TestHeight.description FROM "
s = db.execute_query("SELECT TestDoor.TestHeight.description FROM "
"RECORD TestHouse", unique=True)
column = s.get_property_values(("TestWindow", "TestHeight", "description"))
column = s.get_property_values(("TestDoor", "TestHeight", "description"))
assert column == ('TestHeightDesc',)
s = db.execute_query("SELECT TestHeight.description.TestWindow FROM "
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "description", "TestWindow"))
s = db.execute_query("SELECT TestHeight.description.TestDoor FROM "
"RECORD TestDoor", unique=True)
column = s.get_property_values(("TestHeight", "description", "TestDoor"))
assert column == (None,)
def test_select_description_list():
s = db.execute_query("SELECT description FROM RECORD TestPerson")
column = s.get_property_values("description")
assert column == [(None,), (None,), (None,), (None,)]
s = db.execute_query("SELECT description"
"FROM RECORD TestHouse", unique=True)
column = s.get_property_values(("description"))
assert column == ("A rather large house",)
s = db.execute_query("SELECT location.description"
"FROM RECORD TestParty", unique=True)
column = s.get_property_values(("location", "description"))
assert column == ("A rather large house",)
s = db.execute_query("SELECT TestHeight.description FROM "
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "description"))
assert column == ('TestHeightDesc',)
s = db.execute_query("SELECT TestWindow.TestHeight.description FROM "
"RECORD TestHouse", unique=True)
# current limitation of get_property_values - no lists
# column = s.get_property_values(("TestWindow", "TestHeight", "description"))
# assert column == ('TestHeightDesc',)
assert s.get_property_values(("TestWindow"))[0][0].get_property(
"TestHeight").description == "TestHeightDesc"
def test_select_id():
house_id = db.execute_query("FIND RECORD TestHouse", unique=True).id
s = db.execute_query("SELECT id FROM RECORD TestHouse", unique=True)
......@@ -292,17 +387,43 @@ def test_select_id():
column = s.get_property_values("id")
assert column == (height_id,)
s = db.execute_query("SELECT TestWindow.TestHeight.id FROM "
s = db.execute_query("SELECT TestDoor.TestHeight.id FROM "
"RECORD TestHouse", unique=True)
column = s.get_property_values(("TestWindow", "TestHeight", "id"))
column = s.get_property_values(("TestDoor", "TestHeight", "id"))
assert column == (height_id,)
s = db.execute_query("SELECT TestHeight.id.TestWindow FROM "
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "id", "TestWindow"))
s = db.execute_query("SELECT TestHeight.id.TestDoor FROM "
"RECORD TestDoor", unique=True)
column = s.get_property_values(("TestHeight", "id", "TestDoor"))
assert column == (None,)
def test_select_id_list():
house_id = db.execute_query("FIND RECORD TestHouse", unique=True).id
s = db.execute_query("SELECT id FROM RECORD TestHouse", unique=True)
column = s.get_property_values("id")
assert column == (house_id,)
s = db.execute_query(
"SELECT location.id FROM RECORD TestHouse",
unique=True)
column = s.get_property_values("id")
assert column == (house_id,)
height_id = db.execute_query("FIND PROPERTY TestHeight", unique=True).id
s = db.execute_query("SELECT id FROM PROPERTY TestHeight", unique=True)
column = s.get_property_values("id")
assert column == (height_id,)
s = db.execute_query("SELECT TestWindow.TestHeight.id FROM "
"RECORD TestHouse", unique=True)
# current limitation of get_property_values - no lists
# column = s.get_property_values(("TestWindow", "TestHeight", "id"))
# assert column == (height_id,)
assert s.get_property_values(("TestWindow"))[0][0].get_property(
"TestHeight").id == height_id
def test_select_name():
s = db.execute_query("SELECT name FROM RECORD TestHouse", unique=True)
column = s.get_property_values("name")
......@@ -317,12 +438,84 @@ def test_select_name():
column = s.get_property_values("name")
assert column == ("TestHeight",)
s = db.execute_query("SELECT TestWindow.TestHeight.name FROM "
s = db.execute_query("SELECT TestDoor.TestHeight.name FROM "
"RECORD TestHouse", unique=True)
column = s.get_property_values(("TestWindow", "TestHeight", "name"))
column = s.get_property_values(("TestDoor", "TestHeight", "name"))
assert column == ("TestHeight",)
s = db.execute_query("SELECT TestHeight.name.TestWindow FROM "
"RECORD TestWindow", unique=True)
column = s.get_property_values(("TestHeight", "name", "TestWindow"))
s = db.execute_query("SELECT TestHeight.name.TestDoor FROM "
"RECORD TestDoor", unique=True)
column = s.get_property_values(("TestHeight", "name", "TestDoor"))
assert column == (None,)
def test_select_name_list():
s = db.execute_query("SELECT name FROM RECORD TestHouse", unique=True)
column = s.get_property_values("name")
assert column == ("Buckingham Palace",)
s = db.execute_query("SELECT location.name FROM RECORD TestHouse",
unique=True)
column = s.get_property_values("name")
assert column == ("Buckingham Palace",)
s = db.execute_query("SELECT name FROM PROPERTY TestHeight", unique=True)
column = s.get_property_values("name")
assert column == ("TestHeight",)
s = db.execute_query("SELECT TestWindow.TestHeight.name FROM "
"RECORD TestHouse", unique=True)
# current limitation of get_property_values - no lists
# column = s.get_property_values(("TestWindow", "TestHeight", "name"))
# assert column == ("TestHeight",)
assert s.get_property_values(("TestWindow"))[0][0].get_property(
"TestHeight").name == "TestHeight"
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 TestDoor.TestHeight FROM RECORD TestHouse WITH TestHousePart",
unique=True)
column = s.get_property_values(("TestDoor", "TestHeight"))
assert column == (21.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], 21.5,])
assert len(s.properties) == 2
# both the door and the window have been returned
print(s.properties[0].value)
assert (s.properties[0].name,
s.properties[1].name) == ("TestHousePart", "TestHousePart")
assert (s.properties[0].value[0].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)
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[0].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