From 173d1e2c528a0da58bc7d4bf58d8a6ea3cc8f5ec Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Thu, 24 Jun 2021 10:22:25 +0000 Subject: [PATCH] TST: Add tests for SELECT updates --- CHANGELOG.md | 6 ++++++ tests/test_select.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3a77a..876191c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [caosdb-server#132](https://gitlab.indiscale.com/caosdb/src/caosdb-server/-/issues/132) * Tests for missing obligatory Properties [caosdb-server#146](https://gitlab.indiscale.com/caosdb/src/caosdb-server/-/issues/146) +* Tests for updates of SELECT results, two still marked as `xfail` + until + [caosdb-pylib#48](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/48) + and + [caosdb-server#155](https://gitlab.indiscale.com/caosdb/src/caosdb-server/-/issues/155) + have been resolved. ### Changed (for changes in existing functionality) 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