Skip to content
Snippets Groups Projects
Commit 7833754c authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-fix-assure-in-list' into 'dev'

F fix assure in list

See merge request !41
parents 8b675a87 65e379db
Branches
Tags
2 merge requests!43REL: Release 0.4.1,!41F fix assure in list
Pipeline #22401 passed
...@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
- [#40](https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/40)
`assure_object_is_in_list` now handles adding objects to an initially empty list correctly.
### Security ### ### Security ###
## [0.4.0] - 2022-04-05 ## ## [0.4.0] - 2022-04-05 ##
......
--- ---
responsible: Responsible, Only responsible: Responsible, Only
description: A description of this example analysis. description: A description of another example analysis.
sources: sources:
- file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat" - file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat"
......
--- ---
responsible: responsible:
- Only Responsible MPI DS - Only Responsible MPI DS
description: A description of this example analysis. description: A description of another example analysis.
sources: sources:
- file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat" - file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
responsible: responsible:
- Some Responsible - Some Responsible
- Responsible, No, MPI DS - Responsible, No, MPI DS
description: A description of this example analysis. description: A description of another example analysis.
sources: sources:
- file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat" - file: "/ExperimentalData/2010_TestProject/2019-02-03/*.dat"
......
...@@ -35,14 +35,17 @@ echo "Testing the crawler database" ...@@ -35,14 +35,17 @@ echo "Testing the crawler database"
python3 -m pytest test_crawler_with_cfoods.py python3 -m pytest test_crawler_with_cfoods.py
echo "make a change" echo "make a change"
cd extroot cd extroot
egrep -liRZ 'A description of another example' . | xargs -0 -l sed -i -e 's/A description of another example/A description of this example/g' egrep -liRZ 'A description of another example' . \
| xargs -0 -l sed -i -e 's/A description of another example/A description of this example/g'
# remove a file to check that this does not lead to a crawler crash # remove a file to check that this does not lead to a crawler crash
mv DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back mv DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx \
DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back
cd .. cd ..
echo "run crawler" echo "run crawler"
./crawl.py / | tee $OUT ./crawl.py / | tee $OUT
# rename the moved file # rename the moved file
mv extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx mv extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx_back \
extroot/DataAnalysis/2010_TestProject/2019-02-03_something/README.xlsx
# check whether there was something UNAUTHORIZED # check whether there was something UNAUTHORIZED
grep "There where unauthorized changes" $OUT grep "There where unauthorized changes" $OUT
# get the id of the run which is the last field of the output string # get the id of the run which is the last field of the output string
...@@ -59,7 +62,8 @@ fi ...@@ -59,7 +62,8 @@ fi
set -e set -e
echo "Undoing previous changes to extroot content..." echo "Undoing previous changes to extroot content..."
cd extroot cd extroot
egrep -liRZ 'A description of this example' . | xargs -0 -l sed -i -e 's/A description of this example/A description of another example/g' egrep -liRZ 'A description of this example' . \
| xargs -0 -l sed -i -e 's/A description of this example/A description of another example/g'
cd .. cd ..
echo "Done." echo "Done."
python3 test_table.py python3 test_table.py
......
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
# #
# ** header v3.0
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2022 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2021 University Medical Center Göttingen, Institute for Medical Informatics # Copyright (C) 2021 University Medical Center Göttingen, Institute for Medical Informatics
# Copyright (C) 2021 Florian Spreckelsen <florian.spreckelsen@med.uni-goettingen.de> # Copyright (C) 2021 Florian Spreckelsen <florian.spreckelsen@med.uni-goettingen.de>
# Copyright (C) 2022 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify it under
# it under the terms of the GNU Affero General Public License as # the terms of the GNU Affero General Public License as published by the Free
# published by the Free Software Foundation, either version 3 of the # Software Foundation, either version 3 of the License, or (at your option) any
# License, or (at your option) any later version. # later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful, but WITHOUT
# but WITHOUT ANY WARRANTY; without even the implied warranty of # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# GNU Affero General Public License for more details. # details.
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License along
# along with this program. If not, see <https://www.gnu.org/licenses/>. # with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
"""Integration tests for the `assure_...` functions from """Integration tests for the `assure_...` functions from
`caosadvancedtools.cfood`. They mainly test the in-place updates when `caosadvancedtools.cfood`. They mainly test the in-place updates when
no `to_be_updated` is specified. no `to_be_updated` is specified.
...@@ -90,3 +89,29 @@ def test_assure_list_in_place(): ...@@ -90,3 +89,29 @@ def test_assure_list_in_place():
assert len(rec2.get_property(ref_rt.name).value) == 3 assert len(rec2.get_property(ref_rt.name).value) == 3
assert ref_rec2.id in rec2.get_property(ref_rt.name).value assert ref_rec2.id in rec2.get_property(ref_rt.name).value
assert ref_rec3.id in rec2.get_property(ref_rt.name).value assert ref_rec3.id in rec2.get_property(ref_rt.name).value
def test_add_to_empty_list():
"""See https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/40."""
# @author Florian Spreckelsen
# @date 2022-04-19
referenced_rt = db.RecordType(name="TestReferencedType").insert()
list_prop = db.Property(name="TestListProp",
datatype=db.LIST(referenced_rt)).insert()
referencing_rt = db.RecordType(
name="TestReferencingType").add_property(list_prop).insert()
db.Record(name="TestReferencedRecord").add_parent(referenced_rt).insert()
db.Record(name="TestReferencingRecord").add_parent(
referencing_rt).add_property(list_prop, value=[]).insert()
referenced_rec = db.execute_query("FIND TestReferencedRecord", unique=True)
referencing_rec = db.execute_query(
"FIND TestReferencingRecord", unique=True)
assure_object_is_in_list(referenced_rec, referencing_rec, list_prop.name)
referencing_rec = db.execute_query(
"FIND TestReferencingRecord", unique=True)
assert referencing_rec.get_property(list_prop.name).value == [
referenced_rec.id]
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
# #
# ** header v3.0
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2019,2020 IndiScale GmbH <info@indiscale.com> # Copyright (C) 2019-2022 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2019,2020 Henrik tom Wörden # Copyright (C) 2019,2020 Henrik tom Wörden
# Copyright (C) 2020 Florian Spreckelsen <f.spreckelsen@indiscale.com> # Copyright (C) 2020-2022 Florian Spreckelsen <f.spreckelsen@indiscale.com>
# Copyright (C) 2021 University Medical Center Göttingen, Institute for Medical Informatics # Copyright (C) 2021 University Medical Center Göttingen, Institute for Medical Informatics
# Copyright (C) 2021 Florian Spreckelsen <florian.spreckelsen@med.uni-goettingen.de> # Copyright (C) 2021 Florian Spreckelsen <florian.spreckelsen@med.uni-goettingen.de>
# #
...@@ -24,8 +23,6 @@ ...@@ -24,8 +23,6 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
""" Defines how something that shall be inserted into CaosDB is treated. """ Defines how something that shall be inserted into CaosDB is treated.
CaosDB can automatically be filled with Records based on some structure, a file CaosDB can automatically be filled with Records based on some structure, a file
...@@ -415,11 +412,13 @@ def assure_object_is_in_list(obj, containing_object, property_name, ...@@ -415,11 +412,13 @@ def assure_object_is_in_list(obj, containing_object, property_name,
datatype=datatype) datatype=datatype)
# TODO: case where multiple times the same property exists is not treated # TODO: case where multiple times the same property exists is not treated
if not isinstance(containing_object.get_property(property_name).value, list): list_prop = containing_object.get_property(property_name)
containing_object.get_property(property_name).value = [ if list_prop.value is None:
containing_object.get_property(property_name).value] list_prop.value = []
containing_object.get_property(property_name).datatype = datatype elif not isinstance(list_prop.value, list):
current_list = containing_object.get_property(property_name).value list_prop.value = [list_prop.value]
list_prop.datatype = datatype
current_list = list_prop.value
if not isinstance(obj, list): if not isinstance(obj, list):
objects = [obj] objects = [obj]
...@@ -674,7 +673,8 @@ def assure_has_property(entity, name, value, to_be_updated=None, ...@@ -674,7 +673,8 @@ def assure_has_property(entity, name, value, to_be_updated=None,
tmp_value = el.value.id tmp_value = el.value.id
if isinstance(tmp_value, list): if isinstance(tmp_value, list):
tmp_value = [i.id if isinstance(i, db.Entity) else i for i in tmp_value] tmp_value = [i.id if isinstance(
i, db.Entity) else i for i in tmp_value]
if tmp_value == value: if tmp_value == value:
contained = True contained = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment