Skip to content
Snippets Groups Projects

TST: Add tests for SELECT updates

Merged Florian Spreckelsen requested to merge f-select-update into dev
2 files
+ 52
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 46
0
@@ -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
Loading