From f7b81b4cb0ff014c18eb8d81067fd68c37dfb631 Mon Sep 17 00:00:00 2001 From: alaskowski <alaskowski@ethz.ch> Date: Thu, 22 Jun 2023 18:33:05 +0200 Subject: [PATCH] SSDM-13737: Fixing del_children method. --- .../src/python/pybis/attribute.py | 23 +++++++---------- .../src/python/tests/conftest.py | 2 +- .../src/python/tests/test_sample.py | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/api-openbis-python3-pybis/src/python/pybis/attribute.py b/api-openbis-python3-pybis/src/python/pybis/attribute.py index 5863976d70f..8a83cb2bb8e 100644 --- a/api-openbis-python3-pybis/src/python/pybis/attribute.py +++ b/api-openbis-python3-pybis/src/python/pybis/attribute.py @@ -12,8 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from pandas import DataFrame, Series +import base64 +import os +import pathlib + +from pandas import DataFrame from tabulate import tabulate + +from .attachment import Attachment from .definitions import ( openbis_definitions, fetch_option, @@ -21,21 +27,10 @@ from .definitions import ( get_type_for_entity, ) from .utils import ( - parse_jackson, - check_datatype, - split_identifier, format_timestamp, - is_identifier, - is_permid, nvl, extract_person, ) -from .attachment import Attachment - -import copy -import base64 -import os -import pathlib class AttrHolder: @@ -829,13 +824,13 @@ class AttrHolder: and "identifier" in item and ident["identifier"] == item["identifier"] ): - self.__dict__["_children"].pop(i, None) + self.__dict__["_children"].pop(i) elif ( "permId" in ident and "permId" in item and ident["permId"] == item["permId"] ): - self.__dict__["_children"].pop(i, None) + self.__dict__["_children"].pop(i) @property def tags(self): diff --git a/api-openbis-python3-pybis/src/python/tests/conftest.py b/api-openbis-python3-pybis/src/python/tests/conftest.py index aeb89ccb3e9..718e1d04834 100644 --- a/api-openbis-python3-pybis/src/python/tests/conftest.py +++ b/api-openbis-python3-pybis/src/python/tests/conftest.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os import time import pytest + from pybis import Openbis openbis_url = "https://localhost:8443" diff --git a/api-openbis-python3-pybis/src/python/tests/test_sample.py b/api-openbis-python3-pybis/src/python/tests/test_sample.py index 50420c887c3..a244cfd56fe 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_sample.py +++ b/api-openbis-python3-pybis/src/python/tests/test_sample.py @@ -320,3 +320,28 @@ def test_create_sample_type_assign_property(space): st.assign_property("$NAME") st.save() +def test_del_child_from_sample(space): + # Prepare + sample_type = "UNKNOWN" + timestamp = time.strftime("%a_%y%m%d_%H%M%S").upper() + sample_code1 = "test_sample_child_" + timestamp + "_" + str(random.randint(0, 1000)) + + sample_child = space.new_sample(code=sample_code1, type=sample_type) + sample_child.save() + + sample_code2 = "test_sample_parent_" + timestamp + "_" + str(random.randint(0, 1000)) + sample_parent = space.new_sample(code=sample_code2, type=sample_type) + sample_parent.children = [sample_child] + sample_parent.save() + + assert sample_parent.children == [sample_child.identifier] + + # Act & Assert + item = str(sample_parent.children[0]) + sample_parent.del_children(item) + sample_parent.save() + + assert sample_parent.children == [] + + + -- GitLab