From f5bd5529bd59aa25b4ef52afb60f1d9cbdfa202e Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Fri, 13 Aug 2021 13:33:50 +0200 Subject: [PATCH] ENH: Add test for entities --- test/runtests.jl | 67 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 99a8e12..7662464 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 -- GitLab