From b168add5b164b84422491ab965f47d926b6c71e2 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Wed, 23 Jun 2021 18:25:47 +0200 Subject: [PATCH] TST: Add tests for update of SELECT result --- tests/test_select.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_select.py b/tests/test_select.py index 0b89da1..2eae8cf 100644 --- a/tests/test_select.py +++ b/tests/test_select.py @@ -5,6 +5,8 @@ # # Copyright (C) 2018 Research Group Biomedical Physics, # Max-Planck-Institute for Dynamics and Self-Organization Göttingen +# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -25,6 +27,8 @@ @author: tf """ +from pytest import mark, raises + import caosdb as db @@ -530,3 +534,45 @@ 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() + + +def test_select_update(): + """Ensure that the result of a SELECT query can't be used for an + update (which might result in data loss). + + """ + select_result = db.execute_query("SELECT name FROM RECORD TestHouse")[0] + + with raises(db.CaosDBException): + select_result.update() + + +@mark.xfail(reason="see pylib issue #48 and server issue #155") +def test_select_update_with_parent(): + """Ensure that even with a valid parent, the result of a SELECT query + can't be updated. + + """ + + test_house_rt = db.RecordType(name="TestHouse").retrieve() + select_result = db.execute_query("SELECT name FROM RECORD TestHouse")[0] + select_result.add_parent(test_house_rt) + + with raises(db.CaosDBException): + select_result.update() + + +@mark.xfail(reason="see pylib issue #48 and server issue #155") +def test_select_update_with_force(): + """The update of the result of a SELECT query may be forced.""" + test_house_rt = db.RecordType(name="TestHouse").retrieve() + select_result = db.execute_query("SELECT name FROM RECORD TestHouse")[0] + select_result.add_parent(test_house_rt) + + # TODO: The syntax may change here depending on the implementation + # of caosdb-pylib#48 + select_result.update(force_incomplete=True) + + # only name has been selected and updated, so no properties remain: + rec = db.Record(name=select_result.name).retrieve() + assert len(rec.properties) == 0 -- GitLab