Skip to content
Snippets Groups Projects
Commit f5bd5529 authored by florian's avatar florian
Browse files

ENH: Add test for entities

parent 2b379aff
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
......@@ -63,6 +63,13 @@ using CaosDB
Cint(-1),
),
) CaosDB.Exceptions.evaluate_return_code(Cint(-1))
# Check whether client errors can be built correctly and
# return the correct code (Change it if this ever changes in
# libcaosdb)
client_err = CaosDB.Exceptions.ClientException("Client error")
@test client_err.msg == "Client_Err"
@test client_err.code == 9999
end
@testset "TestTransaction" begin
......@@ -84,5 +91,63 @@ using CaosDB
end
@testset "TestEntity" begin end
@testset "TestEntity" begin
ent_with_name = CaosDB.Entity.create_entity("TestEnt")
@test CaosDB.Entity.get_name(ent_with_name) == "TestEnt"
rt_with_name = CaosDB.Entity.create_recordtype("TestRT")
@test CaosDB.Entity.get_name(rt_with_name) == "TestRT"
@test CaosDB.Entity.get_role(rt_with_name) == "RecordType"
prop_with_name_and_unit =
CaosDB.Entity.create_property_entity(name = "TestProp", unit = "m")
@test CaosDB.Entity.get_name(prop_with_name_and_unit) == "TestProp"
@test CaosDB.Entity.get_role(prop_with_name_and_unit) == "Property"
@test CaosDB.Entity.get_unit(prop_with_name_and_unit) == "m"
rec_with_parent_and_props = CaosDB.Entity.create_record("TestRec")
# cannot set an ID
@test_throws CaosDB.Exceptions.ClientException CaosDB.Entity.set_id("some_id")
par1 = CaosDB.Entity.create_parent(name = "Parent1")
par2 = CaosDB.Entity.create_parent(name = "Parent2", id = "id_of_parent_2")
CaosDB.Entity.append_parents(rec_with_parent_and_props, [par1, par2])
@test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 2
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_parent(rec_with_parent_and_props, 1),
) == "Parent1"
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_parent(rec_with_parent_and_props, 2),
) == "Parent2"
@test CaosDB.Entity.get_id(
CaosDB.Entity.get_parent(rec_with_parent_and_props, 2),
) == "id_of_parent_2"
CaosDB.Entity.remove_parent(rec_with_parent_and_props, 1)
@test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 1
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_parent(rec_with_parent_and_props, 1),
) == "Parent2"
prop1 = CaosDB.Entity.create_property(name = "Property1", value = "2")
prop2 = CaosDB.Entity.create_property(id = "id_of_property_2")
CaosDB.Entity.set_datatype(prop2, "TEXT")
prop3 = CaosDB.Entity.create_property(name = "Property3")
CaosDB.Entity.append_properties(rec_with_parent_and_props, [prop1, prop2, prop3])
@test length(CaosDB.Entity.get_properties(rec_with_parent_and_props)) == 3
# properties can be accessed as a list
@test CaosDB.Entity.get_value(
CaosDB.Entity.get_properties(rec_with_parent_and_props)[1],
) == "2"
@test CaosDB.Entity.get_datatype(
CaosDB.Entity.get_properties(rec_with_parent_and_props)[2],
) == "TEXT"
@test CaosDB.Entity.get_id(
CaosDB.Entity.get_properties(rec_with_parent_and_props)[2],
) == "id_of_property_2"
CaosDB.Entity.remove_property(rec_with_parent_and_props, 2)
@test length(CaosDB.Entity.get_properties(rec_with_parent_and_props)) == 2
@test CaosDB.Entity.get_name(
CaosDB.Entity.get_properties(rec_with_parent_and_props)[2],
) == "Property3"
end
end
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