Skip to content
Snippets Groups Projects
Commit 173d1e2c authored by Florian Spreckelsen's avatar Florian Spreckelsen Committed by Timm Fitschen
Browse files

TST: Add tests for SELECT updates

parent bc7a11b4
No related branches found
No related tags found
1 merge request!10TST: Add tests for SELECT updates
......@@ -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)
......
......@@ -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
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