diff --git a/api-openbis-python3-pybis/src/python/pybis/attribute.py b/api-openbis-python3-pybis/src/python/pybis/attribute.py index 5863976d70f629421d9593546349320574cfe84b..8a83cb2bb8e03274813f74bdef7331f9f24b8bdb 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 aeb89ccb3e9eb11f8b38d5e4f4a74f4c8661d650..718e1d0483461163ee170a4ae83da3435bd08029 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 50420c887c396ea2b5a57dbdf4ee7e0e6f4d347c..a244cfd56feb1594778be76a1bfdb8ea86edd4e0 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 == [] + + +